Defining the Sample Class, the Main Function, and the Constructor
The Class
The sample is implemented as a class, SimpleMapViewer, that will load the map and create the cities.
It contains the following fields:
private:
IlvGadgetContainer* _container;
IlvSCManagerRectangle* _managerRectangle;
IlvMapInfo* _mapInfo;
IlvTextField* _statusBar;
Where
_container is the top window of this application.
_managerRectangle combines an
IlvManager and an
IlvView. _mapinfo field is an
IlvMapInfo instance that stores the informations to convert coordinates from cartographic coordinate system to the manager coordinate system. As map information is saved along with
.ilv files, this field is initialized when our map file is loaded so that we can use it to place cities on the map and display the geographic coordinates corresponding to the position of the mouse pointer on the map. These geographic coordinates are stored in an
IlvTextField that acts as a status bar.
The Main Function
The main function initialize the
IlvDisplay, creates an instance of our
SimpleMapViewer class, then goes into the main loop of Rogue Wave Views.
int main(int, char**)
{
IlvDisplay* display = new IlvDisplay("Map Viewer");
if (display->isBad()) {
IlvPrint("Cannot create the display");
return 1;
}
SimpleMapViewer* viewer = new SimpleMapViewer(display,
"../data/usa.ilv");
IlvMainLoop();
return 0;
}
The Constructor
The constructor of SimpleMapViewer performs two actions: it creates the interface components of our class, then loads the map data.
SimpleMapViewer::SimpleMapViewer(IlvDisplay* display,
const char* fileName)
:_managerRectangle(0),
_statusBar(0),
_container(0),
_mapInfo(0)
{
createGUI(display);
loadMap(fileName);
}
The
createGUI method creates an instance of
IlvGadgetContainer that is the top view of our application, then call the methods to create the manager rectangle containing the map and to create the tool bar:
void
SimpleMapViewer::createGUI(IlvDisplay* display)
{
_container = new IlvGadgetContainer(display,
“SimpleMapViewer",
"Integrating projections and graphics",
IlvRect(50, 50, 450, 450),
IlFalse);
_container->setDestroyCallback(_exit, this);
createManagerRectangle(_container);
createStatusBar(_container);
}
The createManagerRectangle method creates the manager to store the map, and initialize the view:
void
SimpleMapViewer::createManagerRectangle(IlvGadgetContainer* container)
{
_managerRectangle = new IlvSCManagerRectangle(container->getDisplay(),
IlvRect(0, 0, 450, 435));
container->addObject(_managerRectangle);
// Attachments.
container->getHolder()->attach(_managerRectangle, IlvHorizontal);
container->getHolder()->attach(_managerRectangle, IlvVertical);
IlvManager* manager = _managerRectangle->getManager();
IlvView* view = _managerRectangle->getView();
manager->setKeepingAspectRatio(view, IlTrue);
manager->setDoubleBuffering(view, IlTrue);
}
Then the
createStatusBar method creates and attach the
IlvTextField, used as a status bar:
void
SimpleMapViewer::createStatusBar(IlvGadgetContainer* container)
{
_statusBar = new IlvTextField(container->getDisplay(),
"",
IlvRect(0, 435, 450, 15));
container->addObject(_statusBar, IlTrue);
_statusBar->setEditable(IlFalse);
// Attachments.
container->getHolder()->attach(_statusBar, IlvHorizontal);
container->getHolder()->attach(_statusBar, IlvVertical, 1, 0, 0);
}
When the graphic interface is ready, we can load the map.
void
SimpleMapViewer::loadMap(const char* fileName)
{
IlvManager* manager = _managerRectangle->getManager();
IlvView* view = _managerRectangle->getView();
manager->read(fileName);
_mapInfo = IlvMapInfo::Get(manager);
if (_mapInfo) {
view->setInputCallback(_showMousePosition, this);
addCities();
}
manager->fitTransformerToContents(view, IlTrue);
}
After the map has been loaded, we store the map info that was stored in the .ilv file in our _mapinfo field, install an input callback to show mouse position, then add the cities.
Version 6.2.1
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.