I'm trying to implement POI adding and editing.
I use osgEarth::Annotation::PlaceNode as draw type for POI.
Currently with mouse click I can add POIs. Now I want to edit created POI by double clicking it.
My thought was to setName for PlaceNode as "POI/[id]", then use LineSegmentIntersector to get all objects under mouse, and then filter them all with condition on getName().contains("POI/"). After that I could get corresponding POI id from the name.
But the problem is - all PlaceNodes are ignored while searching intersections. Here is my code to find intersections and show all objects names:
bool MouseClickEventHandler::action_editSimplePOI(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());
if (view->computeIntersections(ea.getX(), ea.getY(), hits))
for (std::multiset<osgUtil::LineSegmentIntersector::Intersection>::iterator it = hits.begin(); it != hits.end(); ++it)
for (osg::Node* node : it->nodePath)
QString name = QString::fromStdString(node->getName());
qDebug() << name;
As a result I can see lots of nodes names like "osgEarth.RexTerrainEngineNode" or empty ones, but no PlaceNodes.
I've double checked that my PlaceNode getName() method returns correct name.
Is it a common behaviour of PlaceNode? How can I bypass it?
Yes, this is normal behavior for PlaceNode. PlaceNode and other annotation types do not render in traditional "scene graph" space; they render as screen-space overlays and are not detectable by an intersection visitor.
I recommend using osgEarth's RTTPicker instead. The "osgearth_pick" example demonstrates it. osgEarth has a global ObjectIndex that supports object identification and picking. Instead of using setName() on your PlaceNode, you would call
I am doing pretty much the same thing as Nikita (using osgEarth 2.9, osg 3.4.1) and getting the same result (only onMiss() called). The tagNode does not seem to work. If I add a place node annotation to the .earth file, it works fine. Obviously I am missing something... any help would be appreciated.
My RTTPicker installation:
picker_ = ref_ptr<RTTPicker>(new RTTPicker());
picker_->setBuffer( 4 );
viewer_->addEventHandler( picker_ );
picker_->setDefaultCallback( new MyPickCallback() );
Perhaps another clue to what I may be doing wrong... I can successfully pick the symbol added via the .earth file until I resize my viewer window. After that, picking the symbol also only calls onMiss().
I found my problem. Maybe this would also help someone else: I had a group node (root_) on the viewer level containing the Map Node as a child. The call to picker_->addChild(mapNode_) should rather be picker_->addChild(root_). Not really sure why this would be the case though.