1 /* -*-c++-*- */
2 /* osgEarth - Geospatial SDK for OpenSceneGraph
3 * Copyright 2019 Pelican Mapping
4 * http://osgearth.org
5 *
6 * osgEarth is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 */
19 #include <osgEarthSymbology/BBoxSymbol>
20 #include <osgEarthSymbology/Style>
21
22 using namespace osgEarth;
23 using namespace osgEarth::Symbology;
24
25 OSGEARTH_REGISTER_SIMPLE_SYMBOL(bbox, BBoxSymbol);
26
BBoxSymbol(const Config & conf)27 BBoxSymbol::BBoxSymbol( const Config& conf ) :
28 Symbol ( conf ),
29 _fill ( Fill( 1, 1, 1, 1 ) ),
30 _border ( Stroke( 0.3, 0.3, 0.3, 1) ),
31 _margin ( 3 ),
32 _bboxGeom ( GEOM_BOX )
33 {
34 mergeConfig(conf);
35 }
36
BBoxSymbol(const BBoxSymbol & rhs,const osg::CopyOp & copyop)37 BBoxSymbol::BBoxSymbol(const BBoxSymbol& rhs,const osg::CopyOp& copyop):
38 Symbol(rhs, copyop),
39 _fill ( rhs._fill ),
40 _border ( rhs._border ),
41 _margin ( rhs._margin ),
42 _bboxGeom ( rhs._bboxGeom )
43 {
44
45 }
46
47 Config
getConfig() const48 BBoxSymbol::getConfig() const
49 {
50 Config conf = Symbol::getConfig();
51 conf.key() = "bbox";
52 conf.set( "fill", _fill );
53 conf.set( "border", _border );
54 conf.set( "margin", _margin );
55
56 conf.set( "geom", "box", _bboxGeom, GEOM_BOX );
57 conf.set( "geom", "box_oriented", _bboxGeom, GEOM_BOX_ORIENTED );
58
59 return conf;
60 }
61
62 void
mergeConfig(const Config & conf)63 BBoxSymbol::mergeConfig( const Config& conf )
64 {
65 conf.get( "fill", _fill );
66 conf.get( "border", _border );
67 conf.get( "margin", _margin );
68
69 conf.get( "geom", "box", _bboxGeom, GEOM_BOX );
70 conf.get( "geom", "box_oriented", _bboxGeom, GEOM_BOX_ORIENTED );
71 }
72
73 void
parseSLD(const Config & c,Style & style)74 BBoxSymbol::parseSLD(const Config& c, Style& style)
75 {
76 if ( match(c.key(), "text-bbox-fill") ) {
77 style.getOrCreate<BBoxSymbol>()->fill()->color() = Color(c.value());
78 }
79 else if ( match(c.key(), "text-bbox-border") ) {
80 style.getOrCreate<BBoxSymbol>()->border()->color() = Color(c.value());
81 }
82 else if ( match(c.key(), "text-bbox-border-width") ) {
83 style.getOrCreate<BBoxSymbol>()->border()->width() = as<float>( c.value(), 1.0f );
84 }
85 else if ( match(c.key(), "text-bbox-margin") ) {
86 style.getOrCreate<BBoxSymbol>()->margin() = as<float>(c.value(), 3.0f);
87 }
88 else if ( match(c.key(), "text-bbox-geom") ) {
89 if ( match(c.value(), "box") )
90 style.getOrCreate<BBoxSymbol>()->geom() = GEOM_BOX;
91 else if ( match(c.value(), "box_oriented") )
92 style.getOrCreate<BBoxSymbol>()->geom() = GEOM_BOX_ORIENTED;
93 }
94 }
95