bool ServiceReader::read( const Config& conf, RESTResponse& response ) { response.getServices().clear(); response.getFolders().clear(); if (conf.hasChild("currentVersion")) { response.setCurrentVersion( conf.value("currentVersion") ); } if (conf.hasChild("services")) { ConfigSet services = conf.child("services").children(); for (ConfigSet::iterator itr = services.begin(); itr != services.end(); ++itr) { response.getServices().push_back( Service( itr->value("name"), itr->value("type") ) ); } } if (conf.hasChild("folders")) { ConfigSet folders = conf.child("folders").children(); for (ConfigSet::iterator itr = folders.begin(); itr != folders.end(); ++itr) { response.getFolders().push_back( itr->value() ); } } return true; }
void ShaderOptions::fromConfig(const Config& conf) { _code = conf.value(); _samplers.clear(); ConfigSet s = conf.children("sampler"); for (ConfigSet::const_iterator i = s.begin(); i != s.end(); ++i) { _samplers.push_back(Sampler()); _samplers.back()._name = i->value("name"); const Config* urlarray = i->find("array"); if (urlarray) { ConfigSet uris = urlarray->children("url"); for (ConfigSet::const_iterator j = uris.begin(); j != uris.end(); ++j) { URI uri(j->value(), URIContext(conf.referrer())); _samplers.back()._uris.push_back(uri); } } else { optional<URI> uri; i->get("url", uri); if (uri.isSet()) _samplers.back()._uris.push_back(uri.get()); } } s = conf.children("uniform"); for (ConfigSet::const_iterator i = s.begin(); i != s.end(); ++i) { _uniforms.push_back(Uniform()); _uniforms.back()._name = i->value("name"); i->get("value", _uniforms.back()._value); } }
void CExternalChannel::CFrontEnd::MParseDemands(const NSHARE::CConfig& aConf) { const ConfigSet _dems = aConf.MChildren(DEMAND); LOG_IF(WARNING,_dems.empty()) << "No demands "; if (!_dems.empty()) { ConfigSet::const_iterator _it = _dems.begin(); for (; _it != _dems.end(); ++_it) { VLOG(2) << "dem info " << *_it; demand_dg_t _dem(*_it); _dem.FHandler = 0; LOG_IF(ERROR,!_dem.MIsValid()) << "Cannot create demands from " << _it->MToJSON(true); if (_dem.MIsValid()) { LOG(INFO)<<"Demand "<<_dem; FDemands.push_back(_dem); FSendProtocol.insert(_dem.FProtocol); } } } if (aConf.MIsChild(RECV_PROTOCOL)) { VLOG(2) << "There is exit protocol"; FReceiveProtocol=aConf.MChild(RECV_PROTOCOL).MValue(); LOG_IF(FATAL,!FReceiveProtocol.empty() && !CParserFactory::sMGetInstance().MIsFactoryPresent(FReceiveProtocol)) << "The protocol handler is not exist."<<FReceiveProtocol; } }
void KML_Model::parseStyle(const Config& conf, KMLContext& cx, Style& style) { ModelSymbol* model = 0L; std::string url = KMLUtils::parseLink(conf); if ( !url.empty() ) { if ( !model ) model = style.getOrCreate<ModelSymbol>(); model->url()->setLiteral( url ); model->url()->setURIContext( URIContext(conf.referrer()) ); } Config scale = conf.child("scale"); if (!scale.empty()) { if ( !model ) model = style.getOrCreate<ModelSymbol>(); //TODO: Support XYZ scale instead of single value model->scale() = scale.value("x", 1.0); } Config orientation = conf.child("orientation"); if (!orientation.empty()) { if ( !model ) model = style.getOrCreate<ModelSymbol>(); double h = orientation.value("heading", 0); if ( !osg::equivalent(h, 0.0) ) model->heading() = NumericExpression( h ); double p = orientation.value("tilt", 0); if ( !osg::equivalent(p, 0.0) ) model->pitch() = NumericExpression( p ); double r = orientation.value("roll", 0); if ( !osg::equivalent(r, 0.0) ) model->roll() = NumericExpression( r ); } // Read and store file path aliases from a KML ResourceMap. Config resource_map = conf.child("resourcemap"); if ( !resource_map.empty() ) { const ConfigSet aliases = resource_map.children("alias"); for( ConfigSet::const_iterator i = aliases.begin(); i != aliases.end(); ++i ) { std::string source = i->value("sourcehref"); std::string target = i->value("targethref"); if ( !source.empty() || !target.empty() ) { if ( !model ) model = style.getOrCreate<ModelSymbol>(); model->uriAliasMap()->insert( source, target ); } } } KML_Geometry::parseStyle(conf, cx, style); }
void FeatureDisplayLayout::fromConfig( const Config& conf ) { conf.getIfSet( "tile_size_factor", _tileSizeFactor ); conf.getIfSet( "crop_features", _cropFeatures ); ConfigSet children = conf.children( "level" ); for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i ) addLevel( FeatureLevel( *i ) ); }
void ResourceLibrary::mergeConfig( const Config& conf ) { // read skins const ConfigSet skins = conf.children( "skin" ); for( ConfigSet::const_iterator i = skins.begin(); i != skins.end(); ++i ) { addResource( new SkinResource(*i) ); } //todo: other types later.. }
void LandCoverCoverageLayerOptions::fromConfig(const Config& conf) { ConfigSet mappings = conf.child("land_cover_mappings").children("mapping"); for (ConfigSet::const_iterator i = mappings.begin(); i != mappings.end(); ++i) { osg::ref_ptr<LandCoverValueMapping> mapping = new LandCoverValueMapping(*i); _valueMappings.push_back(mapping.get()); } conf.get("warp", _warp); }
void URI::mergeConfig(const Config& conf) { conf.get("option_string", _optionString); const ConfigSet headers = conf.child("headers").children(); for (ConfigSet::const_iterator i = headers.begin(); i != headers.end(); ++i) { const Config& header = *i; if (!header.key().empty() && !header.value().empty()) { _context.addHeader(header.key(), header.value()); } } }
void FeatureDisplayLayout::fromConfig( const Config& conf ) { conf.getIfSet( "tile_size", _tileSize ); conf.getIfSet( "tile_size_factor", _tileSizeFactor ); conf.getIfSet( "crop_features", _cropFeatures ); conf.getIfSet( "priority_offset", _priorityOffset ); conf.getIfSet( "priority_scale", _priorityScale ); conf.getIfSet( "min_expiry_time", _minExpiryTime ); conf.getIfSet( "min_range", _minRange ); conf.getIfSet( "max_range", _maxRange ); ConfigSet children = conf.children( "level" ); for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i ) addLevel( FeatureLevel( *i ) ); }
void FeatureLevel::fromConfig( const Config& conf ) { if ( conf.hasValue( "min_range" ) ) _minRange = conf.value( "min_range", 0.0f ); if ( conf.hasValue( "max_range" ) ) _maxRange = conf.value( "max_range", FLT_MAX ); conf.getIfSet( "lod", _lod ); const ConfigSet selectorsConf = conf.children( "selector" ); for( ConfigSet::const_iterator i = selectorsConf.begin(); i != selectorsConf.end(); ++i ) { _selectors.push_back( StyleSelector(*i) ); } }
void TextureSplatter::mergeConfig(const Config& conf) { conf.getIfSet( "start_lod", _startLOD ); conf.getIfSet( "intensity", _intensity ); conf.getIfSet( "scale", _scale ); conf.getIfSet( "attenuation_distance", _attenuationDistance ); conf.getIfSet( "mask_layer", _maskLayerName ); ConfigSet textures = conf.child("textures").children("texture"); for(ConfigSet::iterator i = textures.begin(); i != textures.end(); ++i) { _textures.push_back(TextureSource()); _textures.back()._tag = i->value("tag"); _textures.back()._url = i->value("url"); } }
DataManager::DataManager(osgEarth::MapNode* mapNode) : _mapNode(mapNode), _maxUndoStackSize( 128 ) { if (_mapNode) { _map = _mapNode->getMap(); //Look for viewpoints in the MapNode externals const Config& externals = _mapNode->externalConfig(); const ConfigSet children = externals.children("viewpoint"); if (children.size() > 0) { for( ConfigSet::const_iterator i = children.begin(); i != children.end(); ++i ) _viewpoints.push_back(Viewpoint(*i)); } } initialize(); }
void SplatCoverageLegend::fromConfig(const Config& conf) { conf.get("name", _name); conf.get("source", _source); ConfigSet predicatesConf = conf.child("mappings").children(); for(ConfigSet::const_iterator i = predicatesConf.begin(); i != predicatesConf.end(); ++i) { osg::ref_ptr<CoverageValuePredicate> p = new CoverageValuePredicate(); i->get( "name", p->_description ); i->get( "value", p->_exactValue ); i->get( "class", p->_mappedClassName ); if ( p->_mappedClassName.isSet() ) { _predicates.push_back( p.get() ); } } }
void StyleSheet::mergeConfig( const Config& conf ) { _uriContext = URIContext( conf.referrer() ); // read in any resource library references ConfigSet libraries = conf.children( "library" ); for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i ) { ResourceLibrary* resLib = new ResourceLibrary( *i ); _resLibs[resLib->getName()] = resLib; } // read in any scripts ConfigSet scripts = conf.children( "script" ); for( ConfigSet::iterator i = scripts.begin(); i != scripts.end(); ++i ) { // get the script code std::string code = i->value(); // name is optional and unused at the moment std::string name = i->value("name"); std::string lang = i->value("language"); if ( lang.empty() ) { // default to javascript lang = "javascript"; } _script = new Script(code, lang, name); } // read any style class definitions. either "class" or "selector" is allowed ConfigSet selectors = conf.children( "selector" ); if ( selectors.empty() ) selectors = conf.children( "class" ); for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i ) { _selectors.push_back( StyleSelector( *i ) ); } // read in the actual styles ConfigSet styles = conf.children( "style" ); for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i ) { const Config& styleConf = *i; if ( styleConf.value("type") == "text/css" ) { // for CSS data, there may be multiple styles in one CSS block. So // parse them all out and add them to the stylesheet. // read the inline data: std::string cssString = styleConf.value(); // if there's a URL, read the CSS from the URL: if ( styleConf.hasValue("url") ) { URI uri( styleConf.value("url"), styleConf.referrer() ); cssString = uri.readString().getString(); } // break up the CSS into multiple CSS blocks and parse each one individually. std::vector<std::string> blocks; CssUtils::split( cssString, blocks ); for( std::vector<std::string>::iterator i = blocks.begin(); i != blocks.end(); ++i ) { Config blockConf( styleConf ); blockConf.value() = *i; //OE_INFO << LC << "Style block = " << blockConf.toJSON() << std::endl; Style style( blockConf ); _styles[ style.getName() ] = style; } } else { Style style( styleConf ); _styles[ style.getName() ] = style; } } }
MapNode* EarthFileSerializer2::deserialize( const Config& conf, const std::string& referenceURI ) const { MapOptions mapOptions( conf.child( "options" ) ); // legacy: check for name/type in top-level attrs: if ( conf.hasValue( "name" ) || conf.hasValue( "type" ) ) { Config legacy; if ( conf.hasValue("name") ) legacy.add( "name", conf.value("name") ); if ( conf.hasValue("type") ) legacy.add( "type", conf.value("type") ); mapOptions.mergeConfig( legacy ); } Map* map = new Map( mapOptions ); // Yes, MapOptions and MapNodeOptions share the same Config node. Weird but true. MapNodeOptions mapNodeOptions( conf.child( "options" ) ); // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration) // Image layers: ConfigSet images = conf.children( "image" ); for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "256" ); ImageLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value("name"); //layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addImageLayer( new ImageLayer(layerOpt) ); } // Elevation layers: for( int k=0; k<2; ++k ) { std::string tagName = k == 0 ? "elevation" : "heightfield"; // support both :) ConfigSet heightfields = conf.children( tagName ); for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "16" ); ElevationLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); //layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addElevationLayer( new ElevationLayer(layerOpt) ); } } // Model layers: ConfigSet models = conf.children( "model" ); for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ ) { const Config& layerDriverConf = *i; ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); map->addModelLayer( new ModelLayer(layerOpt) ); //map->addModelLayer( new ModelLayer( layerDriverConf.value("name"), ModelSourceOptions(*i) ) ); } // Overlay layers (just an alias for Model Layer with overlay=true) ConfigSet overlays = conf.children( "overlay" ); for( ConfigSet::const_iterator i = overlays.begin(); i != overlays.end(); i++ ) { Config layerDriverConf = *i; if ( !layerDriverConf.hasValue("driver") ) layerDriverConf.set("driver", "feature_geom"); ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); layerOpt.overlay() = true; // forced on when "overlay" specified map->addModelLayer( new ModelLayer(layerOpt) ); } // Mask layer: ConfigSet masks = conf.children( "mask" ); for( ConfigSet::const_iterator i = masks.begin(); i != masks.end(); i++ ) { Config maskLayerConf = *i; MaskLayerOptions options(maskLayerConf); options.name() = maskLayerConf.value( "name" ); options.driver() = MaskSourceOptions(options); map->addTerrainMaskLayer( new MaskLayer(options) ); } //Add any addition paths specified in the options/osg_file_paths element to the file path. Useful for pointing osgEarth at resource folders. Config osg_file_paths = conf.child( "options" ).child("osg_file_paths"); ConfigSet urls = osg_file_paths.children("url"); for (ConfigSet::const_iterator i = urls.begin(); i != urls.end(); i++) { std::string path = osgEarth::getFullPath( referenceURI, (*i).value()); OE_DEBUG << "Adding OSG file path " << path << std::endl; osgDB::Registry::instance()->getDataFilePathList().push_back( path ); } MapNode* mapNode = new MapNode( map, mapNodeOptions ); // External configs: Config ext = conf.child( "external" ); if ( !ext.empty() ) { mapNode->externalConfig() = ext; } return mapNode; }
MapNode* EarthFileSerializer2::deserialize( const Config& conf, const std::string& referrer ) const { // First, pre-load any extension DLLs. preloadExtensionLibs(conf); MapOptions mapOptions( conf.child( "options" ) ); // legacy: check for name/type in top-level attrs: if ( conf.hasValue( "name" ) || conf.hasValue( "type" ) ) { Config legacy; if ( conf.hasValue("name") ) legacy.add( "name", conf.value("name") ); if ( conf.hasValue("type") ) legacy.add( "type", conf.value("type") ); mapOptions.mergeConfig( legacy ); } Map* map = new Map( mapOptions ); // Yes, MapOptions and MapNodeOptions share the same Config node. Weird but true. MapNodeOptions mapNodeOptions( conf.child( "options" ) ); // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration) // Image layers: ConfigSet images = conf.children( "image" ); for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ ) { Config layerDriverConf = *i; ImageLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value("name"); map->addImageLayer( new ImageLayer(layerOpt) ); } // Elevation layers: for( int k=0; k<2; ++k ) { std::string tagName = k == 0 ? "elevation" : "heightfield"; // support both :) ConfigSet heightfields = conf.children( tagName ); for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ ) { Config layerDriverConf = *i; ElevationLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); map->addElevationLayer( new ElevationLayer(layerOpt) ); } } // Model layers: ConfigSet models = conf.children( "model" ); for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ ) { const Config& layerDriverConf = *i; ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); map->addModelLayer( new ModelLayer(layerOpt) ); } // Mask layer: ConfigSet masks = conf.children( "mask" ); for( ConfigSet::const_iterator i = masks.begin(); i != masks.end(); i++ ) { Config maskLayerConf = *i; MaskLayerOptions options(maskLayerConf); options.name() = maskLayerConf.value( "name" ); options.driver() = MaskSourceOptions(options); map->addTerrainMaskLayer( new MaskLayer(options) ); } //Add any addition paths specified in the options/osg_file_paths element to the file path. Useful for pointing osgEarth at resource folders. Config osg_file_paths = conf.child( "options" ).child("osg_file_paths"); ConfigSet urls = osg_file_paths.children("url"); for (ConfigSet::const_iterator i = urls.begin(); i != urls.end(); i++) { std::string path = osgEarth::getFullPath( referrer, (*i).value()); OE_DEBUG << "Adding OSG file path " << path << std::endl; osgDB::Registry::instance()->getDataFilePathList().push_back( path ); } osg::ref_ptr<MapNode> mapNode = new MapNode( map, mapNodeOptions ); // External configs. Support both "external" and "extensions" tags. Config ext = conf.child( "external" ); if ( ext.empty() ) ext = conf.child( "extensions" ); if ( !ext.empty() ) { // save the configuration in case we need to write it back out later mapNode->externalConfig() = ext; // locate and install any registered extensions. ConfigSet extensions = ext.children(); for(ConfigSet::const_iterator i = extensions.begin(); i != extensions.end(); ++i) { Extension* extension = Extension::create( i->key(), *i ); if ( extension ) { mapNode->addExtension( extension ); } else { OE_DEBUG << LC << "Failed to load an extension for \"" << i->key() << "\"\n"; } } } return mapNode.release(); }
/** * Create and return an image for the given TileKey. */ osg::Image* createImage( const TileKey& key, ProgressCallback* progress ) { if (_debugDirect) { //osg::Image* image = new osg::Image; //image->allocateImage(256,256,1, GL_RGB, GL_UNSIGNED_BYTE); //return image; return osgDB::readImageFile( getDirectURI(key) ); //return URI(getDirectURI(key)).getImage(_dbOptions.get(), progress); } // center point of the tile (will be in spherical mercator) double x, y; key.getExtent().getCentroid(x, y); // transform it to lat/long: GeoPoint geo; GeoPoint( getProfile()->getSRS(), x, y ).transform( getProfile()->getSRS()->getGeographicSRS(), geo ); // contact the REST API. Docs are here: // http://msdn.microsoft.com/en-us/library/ff701716.aspx // construct the request URI: std::string request = Stringify() << std::setprecision(12) << _options.imageryMetadataAPI().get() // base REST API << "/" << _options.imagerySet().get() // imagery set to use << "/" << geo.y() << "," << geo.x() // center point in lat/long << "?zl=" << key.getLOD() + 1 // zoom level << "&o=json" // response format << "&key=" << _options.key().get(); // API key // check the URI cache. URI location; TileURICache::Record rec; if ( _tileURICache.get(request, rec) ) { location = URI(rec.value()); //CacheStats stats = _tileURICache.getStats(); //OE_INFO << "Ratio = " << (stats._hitRatio*100) << "%" << std::endl; } else { unsigned c = ++_apiCount; if ( c % 25 == 0 ) OE_INFO << LC << "API calls = " << c << std::endl; // fetch it: ReadResult metadataResult = URI(request).readString(_dbOptions, progress); if ( metadataResult.failed() ) { // check for a REST error: if ( metadataResult.code() == ReadResult::RESULT_SERVER_ERROR ) { OE_WARN << LC << "REST API request error!" << std::endl; Config metadata; std::string content = metadataResult.getString(); metadata.fromJSON( content ); ConfigSet errors = metadata.child("errorDetails").children(); for(ConfigSet::const_iterator i = errors.begin(); i != errors.end(); ++i ) { OE_WARN << LC << "REST API: " << i->value() << std::endl; } return 0L; } else { OE_WARN << LC << "Request error: " << metadataResult.getResultCodeString() << std::endl; } return 0L; } // decode it: Config metadata; if ( !metadata.fromJSON(metadataResult.getString()) ) { OE_WARN << LC << "Error decoding REST API response" << std::endl; return 0L; } // check the vintage field. If it's empty, that means we got a "no data" tile. Config* vintageEnd = metadata.find("vintageEnd"); if ( !vintageEnd || vintageEnd->value().empty() ) { OE_DEBUG << LC << "NO data image encountered." << std::endl; return 0L; } // find the tile URI: Config* locationConf= metadata.find("imageUrl"); if ( !locationConf ) { OE_WARN << LC << "REST API JSON parsing error (imageUrl not found)" << std::endl; return 0L; } location = URI( locationConf->value() ); _tileURICache.insert( request, location.full() ); } // request the actual tile //OE_INFO << "key = " << key.str() << ", URL = " << location->value() << std::endl; //osg::Image* image = location.getImage(_dbOptions.get(), progress); osg::Image* image = osgDB::readImageFile( location.full() ); if ( image && _geom.valid() ) { GeometryRasterizer rasterizer( image->s(), image->t() ); rasterizer.draw( _geom.get(), osg::Vec4(1,1,1,1) ); osg::ref_ptr<osg::Image> overlay = rasterizer.finalize(); ImageUtils::PixelVisitor<AlphaBlend> blend; blend.accept( overlay.get(), image ); } return image; }
void StyleSheet::mergeConfig( const Config& conf ) { _uriContext = URIContext( conf.referrer() ); // read in any resource library references ConfigSet libraries = conf.children( "library" ); for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i ) { std::string name = i->value("name"); if ( name.empty() ) { OE_WARN << LC << "Resource library missing required 'name' attribute" << std::endl; continue; } URI uri( i->value("url"), i->referrer() ); if ( uri.empty() ) { OE_WARN << LC << "Resource library missing required 'url' element" << std::endl; continue; } _resLibs[name] = ResourceLibraryEntry(uri, (osgEarth::Symbology::ResourceLibrary*)0L); //addResourceLibrary( name, reslib.get() ); } // read in any scripts ConfigSet scripts = conf.children( "script" ); for( ConfigSet::iterator i = scripts.begin(); i != scripts.end(); ++i ) { // get the script code std::string code = i->value(); // name is optional and unused at the moment std::string name = i->value("name"); std::string lang = i->value("language"); if ( lang.empty() ) { // default to javascript lang = "javascript"; } _script = new Script(code, lang, name); } // read any style class definitions. either "class" or "selector" is allowed ConfigSet selectors = conf.children( "selector" ); if ( selectors.empty() ) selectors = conf.children( "class" ); for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i ) { _selectors.push_back( StyleSelector( *i ) ); } // read in the actual styles ConfigSet styles = conf.children( "style" ); for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i ) { const Config& styleConf = *i; if ( styleConf.value("type") == "text/css" ) { // read the inline data: std::string cssString = styleConf.value(); // if there's a URL, read the CSS from the URL: if ( styleConf.hasValue("url") ) { URI uri( styleConf.value("url"), styleConf.referrer() ); cssString = uri.readString().getString(); } // a CSS style definition can actually contain multiple styles. Read them // and create one style for each in the catalog. std::stringstream buf( cssString ); Config css = CssUtils::readConfig( buf ); css.setReferrer( styleConf.referrer() ); const ConfigSet children = css.children(); for(ConfigSet::const_iterator j = children.begin(); j != children.end(); ++j ) { Style style( styleConf ); if ( SLDReader::readStyleFromCSSParams( *j, style ) ) _styles[ j->key() ] = style; } } else { Style style( styleConf ); _styles[ style.getName() ] = style; } } }
void StyleSheet::mergeConfig( const Config& conf ) { // read in any resource library references ConfigSet libraries = conf.children( "library" ); for( ConfigSet::iterator i = libraries.begin(); i != libraries.end(); ++i ) { std::string name = i->value("name"); if ( name.empty() ) { OE_WARN << LC << "Resource library missing required 'name' attribute" << std::endl; continue; } URI uri( i->value("url"), i->uriContext() ); if ( uri.empty() ) { OE_WARN << LC << "Resource library missing required 'url' element" << std::endl; continue; } osg::ref_ptr<ResourceLibrary> reslib = ResourceLibrary::create( uri ); if ( !reslib.valid() ) { OE_WARN << LC << "Resource library creation failed" << std::endl; continue; } addResourceLibrary( name, reslib.get() ); } // read any style class definitions. either "class" or "selector" is allowed ConfigSet selectors = conf.children( "selector" ); if ( selectors.empty() ) selectors = conf.children( "class" ); for( ConfigSet::iterator i = selectors.begin(); i != selectors.end(); ++i ) { _selectors.push_back( StyleSelector( *i ) ); } // read in the actual styles ConfigSet styles = conf.children( "style" ); for( ConfigSet::iterator i = styles.begin(); i != styles.end(); ++i ) { const Config& styleConf = *i; if ( styleConf.value("type") == "text/css" ) { // read the inline data: std::string cssString = styleConf.value(); // if there's a URL, read the CSS from the URL: if ( styleConf.hasValue("url") ) { URI uri( styleConf.value("url"), styleConf.uriContext() ); HTTPClient::readString( uri.full(), cssString ); } // a CSS style definition can actually contain multiple styles. Read them // and create one style for each in the catalog. std::stringstream buf( cssString ); Config css = CssUtils::readConfig( buf ); css.setURIContext( styleConf.uriContext( ) ); const ConfigSet children = css.children(); for(ConfigSet::const_iterator j = children.begin(); j != children.end(); ++j ) { Style style( styleConf ); if ( SLDReader::readStyleFromCSSParams( *j, style ) ) _styles[ j->key() ] = style; } } else { Style style( styleConf ); _styles[ style.getName() ] = style; } } }
MapNode* EarthFileSerializer1::deserialize( const Config& conf, const std::string& referenceURI ) const { // piece together a MapOptions, TerrainOptions, and MapNodeOptions: Config mapOptionsConf; if ( conf.hasValue("name") ) mapOptionsConf.update("name", conf.value("name")); if ( conf.hasValue("type") ) mapOptionsConf.update("type", conf.value("type")); Config terrainOptionsConf; Config mapNodeOptionsConf; for( ConfigSet::const_iterator i = conf.children().begin(); i != conf.children().end(); ++i ) { const Config& child = *i; if (child.key() == "profile" || child.key() == "cache" ) { if (child.key() == "cache") { std::string type = child.attr("type"); if (type.empty()) type = "tms"; Config cacheConfig(child); cacheConfig.attrs()["driver"] = type; mapOptionsConf.add( cacheConfig ); } else { mapOptionsConf.add( child ); } } else if ( child.key() == "proxy" || child.key() == "cache_only" ) { mapNodeOptionsConf.add( child ); } else if ( child.key() == "vertical_scale" || child.key() == "sample_ratio" || child.key() == "min_tile_range_factor" || child.key() == "normalize_edges" || child.key() == "combine_layers" || child.key() == "loading_policy" || child.key() == "max_lod" || child.key() == "lighting" ) { terrainOptionsConf.add( child ); } else if ( child.key() == "layering_technique" ) { if ( child.value() == "multipass" ) terrainOptionsConf.update( "compositor", "multipass"); } } MapOptions mapOptions( mapOptionsConf ); MapNodeOptions mapNodeOptions( mapNodeOptionsConf ); mapNodeOptions.setTerrainOptions( TerrainOptions(terrainOptionsConf) ); //Set the reference URI of the cache config. if (mapOptions.cache().isSet()) { mapOptions.cache()->setReferenceURI(referenceURI); } // the reference URI allows osgEarth to resolve relative paths within the configuration mapOptions.referenceURI() = referenceURI; Map* map = new Map( mapOptions ); // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration) // Image layers: ConfigSet images = conf.children( "image" ); for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "256" ); ImageLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value("name"); layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addImageLayer( new ImageLayer(layerOpt) ); } // Elevation layers: for( int k=0; k<2; ++k ) { std::string tagName = k == 0 ? "elevation" : "heightfield"; // support both :) ConfigSet heightfields = conf.children( tagName ); for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "16" ); ElevationLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addElevationLayer( new ElevationLayer(layerOpt) ); } } // Model layers: ConfigSet models = conf.children( "model" ); for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ ) { const Config& layerDriverConf = *i; ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); map->addModelLayer( new ModelLayer(layerOpt) ); //map->addModelLayer( new ModelLayer( i->value("name"), ModelSourceOptions(*i) ) ); } // Mask layer: ConfigSet masks = conf.children( "mask" ); for( ConfigSet::const_iterator i = masks.begin(); i != masks.end(); i++ ) { Config maskLayerConf = *i; MaskLayerOptions options(maskLayerConf); options.name() = maskLayerConf.value( "name" ); options.driver() = MaskSourceOptions(options); map->addTerrainMaskLayer( new MaskLayer(options) ); } return new MapNode( map, mapNodeOptions ); }
MapNode* EarthFileSerializer2::deserialize( const Config& conf, const std::string& referenceURI ) const { MapOptions mapOptions( conf.child( "options" ) ); //Set the reference URI of the cache config. if (mapOptions.cache().isSet()) { mapOptions.cache()->setReferenceURI(referenceURI); } // the reference URI allows osgEarth to resolve relative paths within the configuration mapOptions.referenceURI() = referenceURI; // manually extract the "type" from the main tag: const std::string& csVal = conf.value("type"); mapOptions.coordSysType() = csVal == "cube" ? MapOptions::CSTYPE_GEOCENTRIC_CUBE : csVal == "projected" || csVal == "flat" ? MapOptions::CSTYPE_PROJECTED : MapOptions::CSTYPE_GEOCENTRIC; // legacy: check for name/type in top-level attrs: if ( conf.hasValue( "name" ) || conf.hasValue( "type" ) ) { Config legacy; if ( conf.hasValue("name") ) legacy.add( "name", conf.value("name") ); if ( conf.hasValue("type") ) legacy.add( "type", conf.value("type") ); mapOptions.mergeConfig( legacy ); } Map* map = new Map( mapOptions ); // Yes, MapOptions and MapNodeOptions share the same Config node. Weird but true. MapNodeOptions mapNodeOptions( conf.child( "options" ) ); // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration) // Image layers: ConfigSet images = conf.children( "image" ); for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "256" ); ImageLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value("name"); //layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addImageLayer( new ImageLayer(layerOpt) ); } // Elevation layers: for( int k=0; k<2; ++k ) { std::string tagName = k == 0 ? "elevation" : "heightfield"; // support both :) ConfigSet heightfields = conf.children( tagName ); for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ ) { Config layerDriverConf = *i; layerDriverConf.add( "default_tile_size", "16" ); ElevationLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); //layerOpt.driver() = TileSourceOptions( layerDriverConf ); map->addElevationLayer( new ElevationLayer(layerOpt) ); } } // Model layers: ConfigSet models = conf.children( "model" ); for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ ) { const Config& layerDriverConf = *i; ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); map->addModelLayer( new ModelLayer(layerOpt) ); //map->addModelLayer( new ModelLayer( layerDriverConf.value("name"), ModelSourceOptions(*i) ) ); } // Overlay layers (just an alias for Model Layer with overlay=true) ConfigSet overlays = conf.children( "overlay" ); for( ConfigSet::const_iterator i = overlays.begin(); i != overlays.end(); i++ ) { Config layerDriverConf = *i; if ( !layerDriverConf.hasValue("driver") ) layerDriverConf.attr("driver") = "feature_geom"; //const Config& layerDriverConf = *i; ModelLayerOptions layerOpt( layerDriverConf ); layerOpt.name() = layerDriverConf.value( "name" ); layerOpt.driver() = ModelSourceOptions( layerDriverConf ); layerOpt.overlay() = true; // forced on when "overlay" specified map->addModelLayer( new ModelLayer(layerOpt) ); } // Mask layer: Config maskLayerConf = conf.child( "mask" ); if ( !maskLayerConf.empty() ) { MaskLayerOptions options(maskLayerConf); options.name() = maskLayerConf.value( "name" ); options.driver() = MaskSourceOptions(options); map->setTerrainMaskLayer( new MaskLayer(options) ); } MapNode* mapNode = new MapNode( map, mapNodeOptions ); // External configs: Config ext = conf.child( "external" ); if ( !ext.empty() ) { mapNode->externalConfig() = ext; } return mapNode; }
static bool readMap( const Config& conf, const std::string& referenceURI, EarthFile* earth ) { // OE_NOTICE << conf.toString() << std::endl; bool success = true; Map::CoordinateSystemType cstype = Map::CSTYPE_GEOCENTRIC; std::string a_cstype = conf.value( ATTR_CSTYPE ); if ( a_cstype == "geocentric" || a_cstype == "round" || a_cstype == "globe" || a_cstype == "earth" ) cstype = Map::CSTYPE_GEOCENTRIC; else if ( a_cstype == "geographic" || a_cstype == "flat" || a_cstype == "plate carre" || a_cstype == "projected") cstype = Map::CSTYPE_PROJECTED; else if ( a_cstype == "cube" ) cstype = Map::CSTYPE_GEOCENTRIC_CUBE; osg::ref_ptr<Map> map = new Map( cstype ); map->setReferenceURI( referenceURI ); map->setName( conf.value( ATTR_NAME ) ); MapEngineProperties engineProps; if ( conf.hasChild( "engine_properties" ) ) engineProps = MapEngineProperties( conf.child("engine_properties") ); else engineProps = MapEngineProperties( conf ); // old style, for backwards compatibility //Read the profile definition if ( conf.hasChild( ELEM_PROFILE ) ) map->profileConfig() = ProfileConfig( conf.child( ELEM_PROFILE ) ); //Try to read the global map cache if one is specifiec if ( conf.hasChild( ELEM_CACHE ) ) { map->cacheConfig() = CacheConfig( conf.child( ELEM_CACHE ) ); //Create and set the Cache for the Map CacheFactory factory; Cache* cache = factory.create( map->cacheConfig().value() ); if ( cache ) map->setCache( cache ); } if ( osgEarth::Registry::instance()->getCacheOverride() ) { OE_NOTICE << "Overriding map cache with global cache override" << std::endl; map->setCache( osgEarth::Registry::instance()->getCacheOverride() ); } // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration) ConfigSet images = conf.children( ELEM_IMAGE ); for( ConfigSet::const_iterator i = images.begin(); i != images.end(); i++ ) { Config additional; additional.add( "default_tile_size", "256" ); MapLayer* layer = readMapLayer( *i, additional ); if ( layer ) map->addMapLayer( layer ); } ConfigSet heightfields = conf.children( ELEM_HEIGHTFIELD ); for( ConfigSet::const_iterator i = heightfields.begin(); i != heightfields.end(); i++ ) { Config additional; additional.add( "default_tile_size", "16" ); MapLayer* layer = readMapLayer( *i, additional ); if ( layer ) map->addMapLayer( layer ); } ConfigSet models = conf.children( ELEM_MODEL ); for( ConfigSet::const_iterator i = models.begin(); i != models.end(); i++ ) { ModelLayer* layer = readModelLayer( *i ); if ( layer ) map->addModelLayer( layer ); } Config maskLayerConf = conf.child( ELEM_MASK ); if ( !maskLayerConf.empty() ) { MaskLayer* layer = readMaskLayer( maskLayerConf ); if ( layer ) map->setTerrainMaskLayer( layer ); } earth->setMap( map.get() ); earth->setMapEngineProperties( engineProps ); return success; }