Skip to content

Commit

Permalink
annotation demo cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Feb 5, 2015
1 parent 2f45c86 commit fed24f5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
32 changes: 19 additions & 13 deletions src/applications/osgearth_annotation/osgearth_annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <osgEarth/MapNode>
#include <osgEarth/Decluttering>
#include <osgEarth/ECEF>
#include <osgEarth/Registry>

#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AnnotationEvents>
Expand All @@ -39,6 +40,7 @@
#include <osgEarthAnnotation/FeatureNode>
#include <osgEarthAnnotation/HighlightDecoration>
#include <osgEarthAnnotation/ScaleDecoration>
#include <osgEarthUtil/ActivityMonitorTool>

#include <osgEarthSymbology/GeometryFactory>

Expand Down Expand Up @@ -75,27 +77,25 @@ struct MyAnnoEventHandler : public AnnotationEventHandler
void onHoverEnter( AnnotationNode* anno, const EventArgs& args )
{
anno->setDecoration( "hover" );
OE_NOTICE << "Hover enter" << std::endl;
Registry::instance()->startActivity( "Hovering " + anno->getText() );
Registry::instance()->endActivity( _lastClick );
}

void onHoverLeave( AnnotationNode* anno, const EventArgs& args )
{
anno->clearDecoration();
OE_NOTICE << "Hover leave" << std::endl;
Registry::instance()->endActivity( "Hovering " + anno->getText() );
Registry::instance()->endActivity( _lastClick );
}

virtual void onClick( AnnotationNode* node, const EventArgs& details )
{
PlaceNode* place = dynamic_cast<PlaceNode*>(node);
if (place == NULL)
{
OE_NOTICE << "Thanks for clicking this annotation" << std::endl;
}
else
{
OE_NOTICE << "Thanks for clicking the PlaceNode: " << place->getText() << std::endl;
}
virtual void onClick( AnnotationNode* anno, const EventArgs& details )
{
Registry::instance()->endActivity( _lastClick );
_lastClick = "Clicked " + anno->getText();
Registry::instance()->startActivity( _lastClick );
}

std::string _lastClick;
};

//------------------------------------------------------------------
Expand Down Expand Up @@ -157,6 +157,12 @@ main(int argc, char** argv)
labelControl->setFontSize( 24.0f );
box->addControl( labelControl );

// Activity monitor:
VBox* activityBox = ControlCanvas::getOrCreate(&viewer)->addControl( new VBox() );
activityBox->setHorizAlign(activityBox->ALIGN_RIGHT);
activityBox->setVertAlign(activityBox->ALIGN_BOTTOM);
activityBox->setBackColor(0,0,0,0.75);
viewer.addEventHandler(new ActivityMonitorTool(activityBox));

// Make a group for 2D items, and activate the decluttering engine. Decluttering
// will migitate overlap between elements that occupy the same screen real estate.
Expand Down
5 changes: 5 additions & 0 deletions src/osgEarthAnnotation/AnnotationNode
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ namespace osgEarth { namespace Annotation
*/
bool hasDecoration( const std::string& name ) const;

/**
* Text associated with this annotation; might be the name, might be actual text
*/
virtual const std::string& getText() const { return this->getName(); }

public: // MapNodeObserver

virtual void setMapNode( MapNode* mapNode );
Expand Down
1 change: 1 addition & 0 deletions src/osgEarthAnnotation/LabelNode
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace osgEarth { namespace Annotation
*/
void setText( const std::string& text );
const std::string& text() const { return _text; }
virtual const std::string& getText() const { return text(); }

/**
* Gets a copy of the text style.
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthAnnotation/PlaceNode
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ namespace osgEarth { namespace Annotation
* Text label content
*/
void setText( const std::string& text );
const std::string& getText() const { return _text; }
virtual const std::string& getText() const { return _text; }

/**
* Style (for text and placement)
Expand Down

0 comments on commit fed24f5

Please sign in to comment.