最近想添加一个城市标签名,折腾半天,后来发现,在osgEarth的安装文档里,有一个tests文件夹,里面有一个叫做feature_labels.earth的文件,里面如下显示:
<!--
osgEarth Sample
This shows how to label point features with an attribute.
-->
<map name="Feature Geometry Demo" type="geocentric" version="2">
<image name="World Imagery" driver="gdal">
<url>../data/world.tif</url>
</image>
<feature_source name="city-data" driver="ogr">
<url>../data/cities.gpkg</url>
</feature_source>
<feature_model name="cities" feature_source="city-data">
<feature_indexing enabled="false"/>
<styles>
<selector class="cities">
<query><expr><![CDATA[rank_max >= 8]]></expr></query>
</selector>
<style type="text/css">
cities {
icon: "../data/downarrow.png";
icon-placement: centroid;
icon-declutter: true;
icon-align: center-bottom;
text-content: [name];
text-encoding: utf-8;
text-priority: [rank_max];
text-align: center-bottom;
text-halo: #1f1f1f;
text-size: 6+2*[rank_max];
}
</style>
</styles>
</feature_model>
<screen_space_layout>
<out_animation_time> 0.0 </out_animation_time>
<in_animation_time> 0.25 </in_animation_time>
<min_animation_scale> 0.45 </min_animation_scale>
<min_animation_alpha> 0.0 </min_animation_alpha>
<sort_by_priority> true </sort_by_priority>
</screen_space_layout>
</map>
可以看见,其实osgearth里自带了城市名称的标签,不过是英文的,位置就在../data/cities.gpkg
。对,就是这个cities.gpkg文件。就在osgearth的安装包的data文件夹下。
根据feature_labels.earth的内容可以猜测,之前试图通过shp文件来导入城市坐标点,却一直失败的原因,可能是因为shp文件中的键值对的键,和osgearth中的不匹配。
启发,应该没事多看看tests和data文件夹下的东西,osgearth带了很多例子,很有启发性。