Changeset 5969 for geovis/trunk


Ignore:
Timestamp:
Jan 25, 2016 6:28:49 PM (8 years ago)
Author:
ldelgass
Message:

Add style settings for placard

Location:
geovis/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/Picker.cpp

    r5961 r5969  
    201201        INFO("Hit feature ID: %lu (of %d) layer: %s", feature->getFID(), index->size(), layerName.c_str());
    202202
    203         osgEarth::Symbology::Style style;
    204         osgEarth::Symbology::TextSymbol *ts = style.getOrCreateSymbol<osgEarth::Symbology::TextSymbol>();
    205         //ts->halo()->color() = osgEarth::Symbology::Color(1, 1, 1);
    206         //ts->halo()->width() = 2;
    207         ts->fill()->color() = osgEarth::Symbology::Color(0, 0, 0);
    208         ts->size() = 14;
    209         //ts->alignment() = alignment;
    210         ts->declutter() = false;
    211         //ts->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8;
    212203        clearSelection();
    213204
     
    218209        }
    219210        PlacardNode *label =
    220             new PlacardNode(_renderer->getMapNode(), _pickPoint, placard, attrs, style);
     211            new PlacardNode(_renderer->getMapNode(), _pickPoint, placard, attrs);
    221212        label->getOrCreateStateSet()->setRenderBinDetails(INT_MAX, "RenderBin");
    222213        _renderer->getAnnotations()->addChild(label);
  • geovis/trunk/Placard.cpp

    r5961 r5969  
    2222using namespace GeoVis;
    2323
     24Placard::Placard() :
     25    _backdropColor(0.75, 0.75, 0.75, 0.75)
     26{
     27    osgEarth::Symbology::TextSymbol *ts = _textStyle.getOrCreateSymbol<osgEarth::Symbology::TextSymbol>();
     28    //ts->halo()->color() = osgEarth::Symbology::Color(1, 1, 1);
     29    //ts->halo()->width() = 2;
     30    ts->fill()->color() = osgEarth::Symbology::Color(0, 0, 0);
     31    ts->size() = 14;
     32    //ts->alignment() = alignment;
     33    ts->declutter() = false;
     34    //ts->encoding() = osgEarth::Symbology::TextSymbol::ENCODING_UTF8;
     35    double charSize = ts->size().isSet() ? ts->size()->eval() : 14.0;
     36    _padding = (float)(charSize / 2.0);
     37}
     38
    2439PlacardLabelNode::PlacardLabelNode(osgEarth::MapNode *mapNode,
    2540                                   const osgEarth::GeoPoint& position,
    2641                                   const Placard& placardConf,
    27                                    const osgEarth::Features::AttributeTable &attrs,
    28                                    const osgEarth::Symbology::Style& style) :
    29     osgEarth::Annotation::LabelNode(mapNode, position, style),
     42                                   const osgEarth::Features::AttributeTable &attrs) :
     43    osgEarth::Annotation::LabelNode(mapNode, position, placardConf.getStyle()),
    3044    _placardConf(placardConf),
    3145    _attrs(attrs)
     
    7488                         const osgEarth::GeoPoint& position,
    7589                         const Placard& placardConf,
    76                          const osgEarth::Features::AttributeTable &attrs,
    77                          const osgEarth::Symbology::Style& style) :
     90                         const osgEarth::Features::AttributeTable &attrs) :
    7891    osgEarth::Annotation::OrthoNode(mapNode, position),
    79     _backdropColor(0.75, 0.75, 0.75, 0.75),
    8092    _placardConf(placardConf),
    8193    _attrs(attrs)
    8294{
    8395    setConfig(placardConf);
    84     init(style);
     96    init(placardConf.getStyle());
    8597}
    8698
     
    172184    if (bd) {
    173185        osg::BoundingBox bbox = d->getBoundingBox();
    174         const osgEarth::Symbology::TextSymbol* symbol = _style.get<osgEarth::Symbology::TextSymbol>();
    175         double charSize = symbol && symbol->size().isSet() ? symbol->size()->eval() : 16.0;
    176         float padding = (float)(charSize / 2.0);
    177186        _backdropGeode->removeDrawables( 0, _backdropGeode->getNumDrawables() );
    178         osg::Drawable *bd = osgEarth::Annotation::AnnotationUtils::create2DQuad(bbox, padding, _backdropColor);
     187        osg::Drawable *bd = osgEarth::Annotation::AnnotationUtils::create2DQuad(bbox, _placardConf.getPadding(), _placardConf.getBackdropColor());
    179188        _backdropGeode->addDrawable(bd);
    180189    }
     
    207216    _geode->setCullingActive(false);
    208217
    209     double charSize = symbol && symbol->size().isSet() ? symbol->size()->eval() : 16.0;
    210218    osg::BoundingBox bbox = t->getBoundingBox();
    211     float padding = (float)(charSize / 2.0);
    212     osg::Drawable *bd = osgEarth::Annotation::AnnotationUtils::create2DQuad(bbox, padding, _backdropColor);
     219   
     220    osg::Drawable *bd = osgEarth::Annotation::AnnotationUtils::create2DQuad(bbox, _placardConf.getPadding(), _placardConf.getBackdropColor());
    213221    _backdropGeode->addDrawable(bd);
    214222    _backdropGeode->setCullingActive(false);
     
    258266    conf.add   ( "text",   _text );
    259267    conf.addObj( "style",  _style );
     268    conf.add   ( "padding", _placardConf.getPadding() );
     269    conf.add   ( "bg-fill", _placardConf.getBackdropColor() );
    260270    conf.addObj( "position", getPosition() );
    261271
  • geovis/trunk/Placard.h

    r5961 r5969  
    2222class Placard {
    2323public:
    24     Placard()
    25     {}
     24    Placard();
    2625    virtual ~Placard()
    2726    {}
     
    5352        return _attrNames.size();
    5453    }
     54    void setStyle(const osgEarth::Symbology::Style& style)
     55    {
     56        _textStyle = style;
     57    }
     58    const osgEarth::Symbology::Style& getStyle() const
     59    {
     60        return _textStyle;
     61    }
     62    void setPadding(float padding)
     63    {
     64        _padding = padding;
     65    }
     66    float getPadding() const
     67    {
     68        return _padding;
     69    }
     70    void setBackdropColor(const osg::Vec4& color)
     71    {
     72        _backdropColor = color;
     73    }
     74    const osg::Vec4& getBackdropColor() const
     75    {
     76        return _backdropColor;
     77    }
    5578private:
    5679    std::vector<std::string> _attrNames;
    5780    std::vector<std::string> _attrLabels;
     81    float _padding;
     82    osg::Vec4 _backdropColor;
     83    osgEarth::Symbology::Style _textStyle;
    5884};
    5985
     
    75101                     const osgEarth::GeoPoint& position,
    76102                     const Placard& placardConf,
    77                 const osgEarth::Features::AttributeTable &attrs,
    78                      const osgEarth::Symbology::Style& style = osgEarth::Symbology::Style());
     103                     const osgEarth::Features::AttributeTable &attrs);
    79104
    80105    virtual ~PlacardLabelNode()
     
    105130                const osgEarth::GeoPoint& position,
    106131                const Placard& placardConf,
    107                 const osgEarth::Features::AttributeTable &attrs,
    108                 const osgEarth::Symbology::Style& style = osgEarth::Symbology::Style());
     132                const osgEarth::Features::AttributeTable &attrs);
    109133
    110134    virtual ~PlacardNode()
  • geovis/trunk/RendererCmd.cpp

    r5944 r5969  
    30433043    int namec;
    30443044    Tcl_Obj **namev = NULL;
    3045     const char *layerName = Tcl_GetString(objv[3]);
     3045    const char *layerName = Tcl_GetString(objv[9]);
    30463046
    30473047    if (Tcl_ListObjGetElements(interp, objv[2], &namec, &namev) != TCL_OK) {
     
    30593059        placardConf.addEntry(name, label);
    30603060    }
     3061    osgEarth::Config styleConf("style", Tcl_GetString(objv[3]));
     3062    styleConf.add("type", "text/css");
     3063    placardConf.setStyle(osgEarth::Symbology::Style(styleConf));
     3064    float r, g, b, a;
     3065    if (GetFloatFromObj(interp, objv[4], &r) != TCL_OK ||
     3066        GetFloatFromObj(interp, objv[5], &g) != TCL_OK ||
     3067        GetFloatFromObj(interp, objv[6], &b) != TCL_OK ||
     3068        GetFloatFromObj(interp, objv[7], &a) != TCL_OK) {
     3069        return TCL_ERROR;
     3070    }
     3071    placardConf.setBackdropColor(osg::Vec4(r, g, b, a));
     3072    float padding;
     3073    if (GetFloatFromObj(interp, objv[8], &padding) != TCL_OK) {
     3074        return TCL_ERROR;
     3075    }
     3076    placardConf.setPadding(padding);
    30613077    g_renderer->setPlacardConfig(placardConf, layerName);
    30623078    return TCL_OK;
     
    30643080
    30653081static CmdSpec placardOps[] = {
    3066     {"config", 1, PlacardConfigOp, 4, 4, "attrlist layerName"},
     3082    {"config", 1, PlacardConfigOp, 10, 10, "attrlist textStyle bgColorR bgColorG bgColorB bgColorA padding layerName"},
    30673083};
    30683084static int nPlacardOps = NumCmdSpecs(placardOps);
Note: See TracChangeset for help on using the changeset viewer.