//载入KML
osgEarth::Drivers::KMLOptions kml_options;
kml_options.declutter() = true;
// set up a default icon for point placemarks:
osgEarth::Symbology::IconSymbol* defaultIcon = new osgEarth::Symbology::IconSymbol();
defaultIcon->url()->setLiteral("../UAV/Resources/UAVdata/placemark32.png");
defaultIcon->declutter() = false;//不自动裁剪
kml_options.defaultIconSymbol() = defaultIcon;
osgEarth::Symbology::TextSymbol* defaultText = new osgEarth::Symbology::TextSymbol();
defaultText->halo() = osgEarth::Symbology::Stroke(0.3, 0.3, 0.3, 1.0);
kml_options.defaultTextSymbol() = defaultText;
osg::ref_ptr<osg::Node> kml = osgEarth::Drivers::KML::load(osgEarth::URI("../UAV/Resources/UAVdata/07/07.kml"), _mapnode, kml_options);
if (!kml)
return;
//控制面板显示与否
osgEarth::Util::ControlCanvas* canvas = osgEarth::Util::ControlCanvas::getOrCreate(_viewer);
if (true)
{
osgEarth::Util::Control* c = osgEarth::Util::AnnotationGraphControlFactory().create(kml, _viewer);
if (c)
{
c->setVertAlign(osgEarth::Util::Control::ALIGN_TOP);
canvas->addControl(c);
}
}
root->addChild(kml);
即可将kml节点加入到earth中