Style features in model layer depending on camera distance

classic Classic list List threaded Threaded
2 messages Options
Marcel Pursche Marcel Pursche
Reply | Threaded
Open this post in threaded view
|

Style features in model layer depending on camera distance

Hello,

I'm trying to add POI marker to my terrain using a model layer and icon+text symbols. Here is what my .earth file looks like:


<map name="POIs" type="geocentric" version="2">
    <image name="OSM" driver="tms" cacheid="osm">
        <url>http://tile.openstreetmap.org/</url>
        <profile>global-mercator</profile>
        <format>png</format>
        <tile_size>256</tile_size>
        <tms_type>google</tms_type>
        <l2_cache_size>2000</l2_cache_size>
    </image>

    <model name="POI" driver="feature_geom">
        <features name="poi" driver="ogr">
            <url>poi.geojson</url>
        </features>
        <layout>
            <tile_size>25</tile_size>
            <level name="poi" max_range="10000"/>
        </layout>
        <styles>
            <style type="text/css"> poi { icon: [map_icon]; icon-placement: centroid; icon-declutter: true; icon-occlusion-cull: true; icon-align: center-bottom; text-content: [name]; text-encoding: utf-8; text-align: center-bottom; text-halo: #1f1f1f; text-font: /usr/share/fonts/truetype/msttcorefonts/Arial.ttf; text-size: 20; text-occlusion-cull: true; altitude-clamping: terrain; altitude-offset: 100; } </style>                    </styles>
    </model>

    <screen_space_layout>
        <out_animation_time>0.0</out_animation_time>
        <in_animation_time>0.0</in_animation_time>
        <min_animation_scale>0.5</min_animation_scale>
        <min_animation_alpha>0.6 </min_animation_alpha>
        <sort_by_priority>false</sort_by_priority>
        <snap_to_pixel>true</snap_to_pixel>
    </screen_space_layout>

    <options>
      <terrain driver = "mp"
               lighting="true" />
      <cache type="filesystem">
            <path>earth_cache</path>
      </cache>
    </options>
    <external>
        <lod_blending>
            <duration>2.0</duration>
            <blend_imagery>true</blend_imagery>
            <blend_elevation>true</blend_elevation>
        </lod_blending>
    </external>
</map>


I'm currently using the screen space layout for declutering but it is not exactly what I'm looking for. My goal is that POIs close to the camera(max ~2 km) are rendered with a large icon and text, POIs further away with only a small symbol (max ~10 km) and POIs even further away should be culled.
The culling > 10 km somewhat works when I enable tiling and use a small batch size. The screen space declutering does remove the text and shrink the icon but only based on overlapping and not camera distance.

Is it possible to define two style classes and select them depending on the distance to the camera? I have found examples that use Javascript and select the style class depending on a feature property. Is it possible to access the camera distance in Javascript?

Thanks!
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Style features in model layer depending on camera distance

Marcel,

It's not possible to access camera distance from a script. That is because the script gets evaluated when the features are read and compiled into geometry, not at cull/render time when the camera comes into play. Aside from what you have already done -- set up a layout with a style tied to a maximum range -- there isn't anything else built into osgEarth to do what you want. You would need to author something custom.
Glenn Waldron / Pelican Mapping