最近查了一堆词条,总算在一个大佬的博客中找到了解决方法,这里面有一个前提,要使osg、osgearth支持中文,必须要有 freetype,所以在编译它们前,先编译好 freetype。并且在编译osg时,使用freetype库。
加载矢量数据
<model driver="feature_geom">
<features name="china_text" driver="ogr">
<url>maps/shp/tianjin/xian.shp</url>
</features>
<layout>
<tile_size>10000</tile_size>
<level name="xian_text" min_range = "0" max_range="150000"/>
</layout>
<styles>
<style type="text/css">
xian_text {
altitude-clamping:terrain;
altitude-offset:1;
icon:"/images/marker.png";
icon-align:center-center;
icon-declutter:true;
icon-scale:1;
icon-heading:0;
text-fill: #ffffff;
text-content:[Name];
text-size:16;
text-encoding: utf-8;
render-lighting:false;
text-align: center-center;
text-font:"font/msyh.ttc";
}
</style>
</styles>
</model>
添加环境变量
OSGEARTH_DEFAULT_FONT=simsun.ttc
最终效果如下

特别感谢 kl222
本文详细介绍了如何在编译osg和osgearth时确保中文支持,包括安装freetype库,并通过OGR加载中国天津行政区划数据。步骤包括设置环境变量和配置样式,最终展示了使用`simsun.ttc`字体的显示效果,特别感谢kl222提供关键指引。
2821





