|
参考了例子osgearth_feature.cpp,数据是中国省界
【1】使用要素几何模型法将矢量作为几何模型加到earth里面
代码:
Style style;
LineSymbol* ls=style.getOrCreateSymbol<LineSymbol>();
ls->stroke()->color()=Color::Yellow;
ls->stroke()->width()=4.0f;
OGRFeatureOptions featureOptions;
featureOptions.url()="E:/osgEarth/osgearth2.3/data/chinashp.shp";
FeatureGeomModelOptions geomOptions;
geomOptions.featureOptions()=featureOptions;
geomOptions.styles()=new StyleSheet();
geomOptions.styles()->addStyle(style);
geomOptions.enableLighting()=false;
ModelLayerOptions layerOptions("china_boundaries",geomOptions);
layerOptions.overlay()=true;
map->addModelLayer(new ModelLayer(layerOptions));
效果图:
几何模型法
当把overlay参数设为false时,受地形影响,青藏高原那块矢量线条比较虚,慢慢放大就渐渐看不清了
效果图:
几何模型法overlay=false
【2】使用stencil模板法
代码:
osg:isplaySettings::instance()->setMinimumNumStencilBits( 8 );
Style style;
LineSymbol* ls=style.getOrCreateSymbol<LineSymbol>();
ls->stroke()->color()=Color::Yellow;
ls->stroke()->width()=4.0f;
OGRFeatureOptions featureOptions;
featureOptions.url()="E:/osgEarth/osgearth2.3/data/chinashp.shp";
FeatureStencilModelOptions stencilOptions;
stencilOptions.featureOptions() = featureOptions;
stencilOptions.styles() = new StyleSheet();
stencilOptions.styles()->addStyle( style );
stencilOptions.enableLighting() = false;
stencilOptions.depthTestEnabled() = false;
//ls->stroke()->width() = 0.1f;
map->addModelLayer( new ModelLayer("my features", stencilOptions) );
效果:为什么明明是线图层的省界矢量,模板法显示出来却是面状的呢?是使用的方法不对吗?
模板法
【3】Agglite栅格化
代码: Style style;
LineSymbol* ls=style.getOrCreateSymbol<LineSymbol>();
ls->stroke()->color()=Color::Yellow;
ls->stroke()->width()=2.0f;
OGRFeatureOptions featureOptions;
featureOptions.url()="E:/osgEarth/osgearth2.3/data/chinashp.shp";
AGGLiteOptions rasterOptions;
rasterOptions.featureOptions() = featureOptions;
rasterOptions.styles() = new StyleSheet();
rasterOptions.styles()->addStyle( style );
map->addImageLayer( new ImageLayer("my features", rasterOptions) );
效果:赶紧整体效果不是很好,栅格化好粗糙,还有个问题,怎么底图变花了呢?求助大神
栅格化法
|
|