#include <Main/fg_props.hxx>
#include <cmath>
+#include <boost/algorithm/string/predicate.hpp>
+
#define LOG_GEO_RET(msg) \
{\
SG_LOG\
namespace canvas
{
- // TODO make projection configurable
- SansonFlamsteedProjection projection;
const std::string GEO = "-geo";
//----------------------------------------------------------------------------
- Map::Map(SGPropertyNode_ptr node):
- Group(node),
+ Map::Map(SGPropertyNode_ptr node, const Style& parent_style):
+ Group(node, parent_style),
+ // TODO make projection configurable
+ _projection(new SansonFlamsteedProjection),
_projection_dirty(true)
{
continue;
Projection::ScreenPosition pos =
- projection.worldToScreen(lat.value, lon.value);
+ _projection->worldToScreen(lat.value, lon.value);
geo_node->setScreenPos(pos.x, pos.y);
//----------------------------------------------------------------------------
void Map::childAdded(SGPropertyNode* parent, SGPropertyNode* child)
{
- if( !hasSuffix(child->getNameString(), GEO) )
+ if( !boost::ends_with(child->getNameString(), GEO) )
return Element::childAdded(parent, child);
_geo_nodes[child].reset(new GeoNodePair());
//----------------------------------------------------------------------------
void Map::childRemoved(SGPropertyNode* parent, SGPropertyNode* child)
{
- if( !hasSuffix(child->getNameString(), GEO) )
+ if( !boost::ends_with(child->getNameString(), GEO) )
return Element::childRemoved(parent, child);
// TODO remove from other node
{
const std::string& name = child->getNameString();
- if( !hasSuffix(name, GEO) )
+ if( !boost::ends_with(name, GEO) )
return Group::valueChanged(child);
GeoNodes::iterator it_geo_node = _geo_nodes.find(child);
//----------------------------------------------------------------------------
void Map::childChanged(SGPropertyNode * child)
{
+ if( child->getParent() != _node )
+ return Group::childChanged(child);
+
if( child->getNameString() == "ref-lat"
|| child->getNameString() == "ref-lon" )
- projection.setWorldPosition( _node->getDoubleValue("ref-lat"),
- _node->getDoubleValue("ref-lon") );
+ _projection->setWorldPosition( _node->getDoubleValue("ref-lat"),
+ _node->getDoubleValue("ref-lon") );
else if( child->getNameString() == "hdg" )
- projection.setOrientation(child->getFloatValue());
+ _projection->setOrientation(child->getFloatValue());
else if( child->getNameString() == "range" )
- projection.setRange(child->getDoubleValue());
+ _projection->setRange(child->getDoubleValue());
else
- return;
+ return Group::childChanged(child);
_projection_dirty = true;
}
return coord;
}
- //----------------------------------------------------------------------------
- bool Map::hasSuffix(const std::string& str, const std::string& suffix) const
- {
- if( suffix.length() > str.length() )
- return false;
-
- return ( str.compare( str.length() - suffix.length(),
- suffix.length(),
- suffix ) == 0 );
- }
-
} // namespace canvas