GraticuleLabelingEngine::GraticuleLabelingEngine(const SpatialReference* srs)
{
    _srs = srs;

    // Set up the symbology for x-axis labels
    TextSymbol* xText = _xLabelStyle.getOrCreate<TextSymbol>();
    xText->alignment() = TextSymbol::ALIGN_CENTER_BOTTOM;
    xText->halo()->color().set(0, 0, 0, 1);
    xText->declutter() = false;

    // Set up the symbology for y-axis labels
    TextSymbol* yText = _yLabelStyle.getOrCreate<TextSymbol>();
    yText->alignment() = TextSymbol::ALIGN_LEFT_BOTTOM;
    yText->halo()->color().set(0, 0, 0, 1);
    yText->declutter() = false;
}
Beispiel #2
0
void
MapInspectorUI::addTerrainLayer(TerrainLayer* layer,
                                MapNode*      mapNode)
{
    const Color colors[6] = {
        Color::White,
        Color::Yellow,
        Color::Cyan,
        Color::Lime,
        Color::Red,
        Color::Magenta
    };
    Color color = colors[(int)layer->getUID()%6];

    osg::ref_ptr<MultiGeometry> collection = new MultiGeometry();

    const DataExtentList& exlist = layer->getDataExtents();
    if (!exlist.empty())
    {
        for(DataExtentList::const_iterator i = exlist.begin(); i != exlist.end(); ++i)
        {
            const DataExtent& e = *i;
            Polygon* p = new Polygon();
            p->push_back( e.xMin(), e.yMin() );
            p->push_back( e.xMax(), e.yMin() );
            p->push_back( e.xMax(), e.yMax() );
            p->push_back( e.xMin(), e.yMax() );
            collection->add( p );
        }

        // poly:
        {
            Style style;
            style.getOrCreate<LineSymbol>()->stroke()->color() = color;
            style.getOrCreate<LineSymbol>()->stroke()->width() = 2;
            style.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
            style.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;
            style.getOrCreate<RenderSymbol>()->lighting() = false;

            Feature* feature = new Feature(collection.get(), layer->getProfile()->getSRS(), style);
            FeatureNode* node = new FeatureNode( mapNode, feature );
            _annos->addChild( node );
        }

        // label:
        std::string text = 
            !layer->getName().empty()? layer->getName() :
            Stringify() << "Layer " << layer->getUID();

        {
            Style style;
            TextSymbol* ts = style.getOrCreate<TextSymbol>();
            ts->halo()->color().set(0,0,0,1);
            ts->declutter() = true;
            ts->alignment() = TextSymbol::ALIGN_CENTER_CENTER;
        
            osg::Vec2d center = collection->getBounds().center2d();
            GeoPoint position(layer->getProfile()->getSRS(), center.x(), center.y(), 0.0, ALTMODE_ABSOLUTE);

            LabelNode* label = new LabelNode(mapNode, position, text, style);
            _annos->addChild( label );
        }

        unsigned r = this->getNumRows();
        setControl(0, r, new ui::LabelControl(text, color));
    }
}
Beispiel #3
0
void
TextSymbol::parseSLD(const Config& c, Style& style)
{
    TextSymbol defaults;

    if ( match(c.key(), "text-fill") || match(c.key(), "text-color") ) {
        style.getOrCreate<TextSymbol>()->fill()->color() = Color(c.value());
    }
    else if ( match(c.key(), "text-fill-opacity") ) {
        style.getOrCreate<TextSymbol>()->fill()->color().a() = as<float>( c.value(), 1.0f );
    }
    else if ( match(c.key(), "text-size") ) {
        style.getOrCreate<TextSymbol>()->size() = NumericExpression( c.value() );
    }
    else if ( match(c.key(), "text-font") ) {
        style.getOrCreate<TextSymbol>()->font() = c.value();
    }
    else if ( match(c.key(), "text-halo") || match(c.key(), "text-halo-color") ) {
        style.getOrCreate<TextSymbol>()->halo()->color() = htmlColorToVec4f( c.value() );
    }
    else if ( match(c.key(), "text-halo-offset") ) {
        style.getOrCreate<TextSymbol>()->haloOffset() = as<float>(c.value(), defaults.haloOffset().get() );
    }
    else if ( match(c.key(), "text-halo-backdrop-type") ) {
        if      ( match(c.value(), "right-bottom") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_BOTTOM_RIGHT;
        else if ( match(c.value(), "right-center") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_CENTER_RIGHT;
        else if ( match(c.value(), "right-top") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_TOP_RIGHT;
        else if ( match(c.value(), "center-bottom") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_BOTTOM_CENTER;
        else if ( match(c.value(), "center-top") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_TOP_CENTER;
        else if ( match(c.value(), "left-bottom") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_BOTTOM_LEFT;
        else if ( match(c.value(), "left-center") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_CENTER_LEFT;
        else if ( match(c.value(), "left-top") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::DROP_SHADOW_TOP_LEFT;
        else if ( match(c.value(), "outline") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::OUTLINE;
        else if ( match(c.value(), "none") )
            style.getOrCreate<TextSymbol>()->haloBackdropType() = osgText::Text::NONE;
    }
    else if ( match(c.key(), "text-halo-implementation") ) {
        if      ( match(c.value(), "polygon-offset") )
            style.getOrCreate<TextSymbol>()->haloImplementation() = osgText::Text::POLYGON_OFFSET;
        else if ( match(c.value(), "no-depth-buffer") )
            style.getOrCreate<TextSymbol>()->haloImplementation() = osgText::Text::NO_DEPTH_BUFFER;
        else if ( match(c.value(), "depth-range") )
            style.getOrCreate<TextSymbol>()->haloImplementation() = osgText::Text::DEPTH_RANGE;
        else if ( match(c.value(), "stencil-buffer") )
            style.getOrCreate<TextSymbol>()->haloImplementation() = osgText::Text::STENCIL_BUFFER;
        else if ( match(c.value(), "delayed-depth-writes") )
            style.getOrCreate<TextSymbol>()->haloImplementation() = osgText::Text::DELAYED_DEPTH_WRITES;
    }
    else if ( match(c.key(), "text-remove-duplicate-labels") ) {
        if ( c.value() == "true" )
            style.getOrCreate<TextSymbol>()->removeDuplicateLabels() = true;
        else if (c.value() == "false")
            style.getOrCreate<TextSymbol>()->removeDuplicateLabels() = false;
    }
    else if ( match(c.key(), "text-align") ) {
        if      ( match(c.value(), "left-top") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_LEFT_TOP;
        else if ( match(c.value(), "left-center") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_LEFT_CENTER;
        else if ( match(c.value(), "left-bottom") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_LEFT_BOTTOM;
        else if ( match(c.value(), "center-top")  )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_TOP;
        else if ( match(c.value(), "center-center") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_CENTER;
        else if ( match(c.value(), "center-bottom") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_BOTTOM;
        else if ( match(c.value(), "right-top") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_RIGHT_TOP;
        else if ( match(c.value(), "right-center") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_RIGHT_CENTER;
        else if ( match(c.value(), "right-bottom") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_RIGHT_BOTTOM;
        else if ( match(c.value(), "left-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_LEFT_BASE_LINE;
        else if ( match(c.value(), "center-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_BASE_LINE;
        else if ( match(c.value(), "right-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_RIGHT_BASE_LINE;
        else if ( match(c.value(), "left-bottom-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_LEFT_BOTTOM_BASE_LINE;
        else if ( match(c.value(), "center-bottom-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_CENTER_BOTTOM_BASE_LINE;
        else if ( match(c.value(), "right-bottom-base-line") )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_RIGHT_BOTTOM_BASE_LINE;
        else if ( match(c.value(), "base-line" ) )
            style.getOrCreate<TextSymbol>()->alignment() = TextSymbol::ALIGN_BASE_LINE;
    }
    else if ( match(c.key(), "text-layout") ) {
        if ( match(c.value(), "ltr") )
            style.getOrCreate<TextSymbol>()->layout() = TextSymbol::LAYOUT_LEFT_TO_RIGHT;
        else if ( match(c.value(), "rtl" ) )
            style.getOrCreate<TextSymbol>()->layout() = TextSymbol::LAYOUT_RIGHT_TO_LEFT;
        else if ( match(c.value(), "vertical" ) )
            style.getOrCreate<TextSymbol>()->layout() = TextSymbol::LAYOUT_VERTICAL;
    }
    else if ( match(c.key(), "text-content") || match(c.key(), "text") ) {
        style.getOrCreate<TextSymbol>()->content() = StringExpression( c.value() );
    }
    else if ( match(c.key(), "text-priority") ) {
        style.getOrCreate<TextSymbol>()->priority() = NumericExpression( c.value() );
    }
    else if ( match(c.key(), "text-provider") ) {
        style.getOrCreate<TextSymbol>()->provider() = c.value();
    }
    else if ( match(c.key(), "text-encoding") ) {
        if      (match(c.value(), "utf-8"))
            style.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_UTF8;
        else if (match(c.value(), "utf-16"))
            style.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_UTF16;
        else if (match(c.value(), "utf-32"))
            style.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_UTF32;
        else if (match(c.value(), "ascii"))
            style.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_ASCII;
        else
            style.getOrCreate<TextSymbol>()->encoding() = TextSymbol::ENCODING_ASCII;
    }
    else if ( match(c.key(), "text-declutter") ) {
        style.getOrCreate<TextSymbol>()->declutter() = as<bool>(c.value(), defaults.declutter().get() );
    }
    else if ( match(c.key(), "text-occlusion-cull") ) {
        style.getOrCreate<TextSymbol>()->occlusionCull() = as<bool>(c.value(), defaults.occlusionCull().get() );
    }
    else if ( match(c.key(), "text-occlusion-cull-altitude") ) {
        style.getOrCreate<TextSymbol>()->occlusionCullAltitude() = as<double>(c.value(), defaults.occlusionCullAltitude().get() );
    }
    else if ( match(c.key(), "text-script") ) {
        style.getOrCreate<TextSymbol>()->script() = StringExpression(c.value());
    }
    else if ( match(c.key(), "text-offset-x") ) {
        style.getOrCreate<TextSymbol>()->pixelOffset()->x() = as<double>(c.value(), defaults.pixelOffset()->x() );
    }
    else if ( match(c.key(), "text-offset-y") ) {
        style.getOrCreate<TextSymbol>()->pixelOffset()->y() = as<double>(c.value(), defaults.pixelOffset()->y() );
    }
    else if ( match(c.key(), "text-rotation") ) {
        style.getOrCreate<TextSymbol>()->onScreenRotation() = NumericExpression( c.value() );
    }
    else if ( match(c.key(), "text-geographic-course") ) {
        style.getOrCreate<TextSymbol>()->geographicCourse() = NumericExpression( c.value() );
    }
}