define a style programmatically

classic Classic list List threaded Threaded
12 messages Options
tkani tkani
Reply | Threaded
Open this post in threaded view
|

define a style programmatically

hi, I am trying to add a style to the feature_geom , but I am stuck in the way to write it :

 
<styles> 
        <style type="text/css"> states { stroke: #ffff00; stroke-width: 1.0; } </style><styles> 
-----------------------------------------
osgEarth::Config conf("model");
conf.attr("style")= "states {"
               "stroke: #ffff00;"
               "stroke-width: 100.0;"
            "}"  ;
---------------------------------------

what is wrong in the declaration ?

thanks!
Thomas canipel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

Thomas,
You no longer need to manually build Config objects. You can use the new driver APIs. There aren't many docs on this yet but here's a bit to get you started...

#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>
...
FeatureGeomModelOptions* opt = new FeatureGeomModelOptions();
...
Style style("states");
style.lineSymbolizer()->stroke()->color() = osg::Vec4f(1,1,0,0);
style.lineSymbolizer()->stroke()->width() = 1.0f;
opt->styles()->addStyle( style );
...
MapLayer* layer = new MapLayer( "states", opt );


That's just off the cuff so there might be typos, but you get the idea.
Glenn
Glenn Waldron / Pelican Mapping
tkani tkani
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

i got stuck in when I use the object Style:

osgEarth::Drivers::OGRFeatureOptions* feature = new osgEarth::Drivers::OGRFeatureOptions();
feature->url()="data/shpcreate.shp";
feature->geometryConfig()->attr("geometry_type")= "line";
               
osgEarth::Drivers::FeatureGeomModelOptions* opt = new osgEarth::Drivers::FeatureGeomModelOptions();
Style style(features->config()); <-- is this the way to link the OGRfeature to the geomModel ?
style.lineSymbolizer()->stroke()->color() = osg::Vec4f(1,1,0,0);
style.lineSymbolizer()->stroke()->width() = 1.0f;
opt->styles()->addStyle( style );

osgEarth::ModelLayer* model = new osgEarth::ModelLayer("sensorCurve", feature );  <-- do I have to use a modelLayer or a mapLayer ?

thanks
Thomas canipel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

You should never have to deal with Config objects directly.
Try:

osgEarth::Drivers::OGRFeatureOptions* feature = new osgEarth::Drivers::OGRFeatureOptions();
feature->url()="data/shpcreate.shp";
             
osgEarth::Drivers::FeatureGeomModelOptions* opt = new osgEarth::Drivers::FeatureGeomModelOptions();

opt->featureOptions() = feature;
opt->geometryTypeOverride() = Geometry::TYPE_LINESTRING;

Style style();
style.lineSymbolizer()->stroke()->color() = osg::Vec4f(1,1,0,0);
style.lineSymbolizer()->stroke()->width() = 1.0f;
opt->styles()->addStyle( style );

osgEarth::ModelLayer* model = new osgEarth::ModelLayer("sensorCurve", opt );
Glenn Waldron / Pelican Mapping
tkani tkani
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

by defining the element Style like that the application crash on:

void StyleCatalog::addStyle( const Style& style )
{
    _styles[ style.name() ] = style;
}

somethng is missing when initializing the Style object, I try to set a name or to set a config but the result is the same.

thanks
Thomas canipel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

Thomas,

I have checked in a new sample app to the repository called "osgearth_features" that demonstrates how to build a map with a feature layer using the driver API. Take a look and let me know if this is helpful.

Glenn
Glenn Waldron / Pelican Mapping
tkani tkani
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

thanks for the example, its more clear , I have still some questions :

- By using the AGGLiteOptions, my shapefile is draw on the terrain but its a 3D shapefile, the depth is not take into account, is it normal,which options do I have to use.

- The configuration of the cache for the cache_type or for cache_only as to be done on the mapLayer now ?

thanks
Thomas canipel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

agglite is a rasterizer, it draws vectors to bitmaps and makes image tiles out of them. So 2D only. If you want 3D feature geometry then "feature_geom" is currently your only option. I don't know of anyone who has tested it with 3D shapefiles yet, maybe you will be the first :)

Correct, cache_type and cache_only are MapLayer settings.

Glenn
Glenn Waldron / Pelican Mapping
tkani tkani
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

oh by using the xml file it works with the 3D shapefile, by using the FeatureGeomModelOptions there is an error when I try to add the Style on it :

-----------------------------------------------------

osgEarth::Drivers::FeatureGeomModelOptions* worldOpt = new osgEarth::Drivers::FeatureGeomModelOptions();
worldOpt->featureOptions() = featureOpt;
worldOpt->geometryTypeOverride() = Geometry::TYPE_LINESTRING;
worldOpt->styles()->addStyle( style );                                            <---  _styles[ style.name() ] = style;
osgEarth::ModelLayer* model = new osgEarth::ModelLayer("sensorCurve", worldOpt );
map->addModelLayer(model);
-----------------------------------------------------

the variable _styles[] is empty
Thomas canipel
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

Try it now. I checked in a bug fix and tested it.

Glenn
Glenn Waldron / Pelican Mapping
tkani tkani
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

thanks, by the way I dont find the option on the HeighFieldMapLayer or the MapLayer to define the vertical_scale

thanks
Thomas canipel
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: define a style programmatically

Hi Thomas,

You can set the vertical scale on the MapEngineProperties before you
create your mapnode.

Something like:
MapEngineProperties props;
props.verticalScale() = 2.0f;
osg::ref_ptr<MapNode> mapNode = new MapNode(props);

Thanks,

Jason

On Thu, Feb 25, 2010 at 5:45 PM, tcanipel [via osgEarth]
<[hidden email]> wrote:

> thanks, by the way I dont find the option on the HeighFieldMapLayer or the
> MapLayer to define the vertical_scale
>
> thanks
> Thomas canipel
>
> Thanks
>
> ________________________________
> View message @
> http://n2.nabble.com/define-a-style-programmatically-tp4616522p4635931.html
> To start a new topic under osgEarth, email
> [hidden email]
> To unsubscribe from osgEarth, click here.
>