Showing the Mouse Position
When data is loaded in the map, we set in input callback to show mouse position:
if (_mapInfo) {
view->setInputCallback(_showMousePosition, this);
}
This callback class calls the showMousePosition method each time an input event occurs in the view:
void _showMousePosition(IlvView* view, IlvEvent& event, IlAny arg)
{
SimpleMapViewer* mapViewer = (SimpleMapViewer*) arg;
mapViewer->showMousePosition(view, event);
}
This method first initializes some buffers to display information:
void
SimpleMapViewer::showMousePosition(IlvView* view, IlvEvent& event)
{
char buf1[12];
char buf2[12];
char label[50];
}
Then, we get the last object that was under the mouse position, and if any, we get the name of this object to display it as a city name:
IlvManager* manager = _mapInfo->getManager();
const char* name = "";
IlvPoint p(event.x(), event.y());
IlvGraphic* g = manager->lastContains(p, view);
if (g && g->getName())
name = g->getName();
Then we use again our
IlvMapInfo instance to convert manager coordinates of the mouse back to geographical coordinates:
IlvCoordinate ll;
if (_mapInfo->inverse(event, view, ll) == IlvMaps::NoError())
sprintf(label, "%s %s %s",
IlvMaps::RadianToDMS(buf1, ll.x(), IlFalse),
IlvMaps::RadianToDMS(buf2, ll.y(), IlTrue),
name);
else
sprintf(label, "Unable to invert mouse position");
Then, finally, we set the label into the status bar:
_statusBar->setLabel(label);
_statusBar->reDraw();
Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.