Maps > Using Load-On-Demand > Implementing Load-on-Demand for a New Data Source
 
Implementing Load-on-Demand for a New Data Source
To implement load-on-demand for a new data source, all you have to do is write a specific tile loader that implements the IlvTileLoader abstract class. Notice, however, that for the predefined map formats supplied with Rogue Wave® Views, such as CADRG, load-on-demand has been implemented in a subclass of IlvTiledLayer that defines both the tile loader (as a private class) and the tiling parameters appropriate for the concerned format. As far as CADRG is concerned, load-on-demand has been implemented so that tiles are aligned with frames. Predefined formats are described in Predefined Readers.
For your tile loader to be fully efficient, the following requirements should be satisfied:
*You should be able to determine which objects are to be loaded on the tile. These objects can be read from a file whose name is known, or be the result of a query to a cartographic database.
*You should be able to have a direct random access to data.
*The size of the data to be loaded should be in proportion to the size of the tiles to allow fast loading. For example, raster images with a size of 100x100 are faster to load than images with a size of 6000x6000.
The following example of a tile loader simulates the loading of two graphic objects, a rectangle, and a label.
The load method takes the tile to be loaded as its parameter. It generates the graphic objects to be displayed within the tile and adds them to the tiled layer by calling the addObject method. When loading is complete, it calls the loadComplete method to notify the listeners that the data in the tile is ready for use.
 
class TileLoader
:public IlvTileLoader
{
public:
TileLoader(IlvDisplay*);
virtual IlvMapsError load(IlvTile* tile);
virtual void release(IlvTile* tile);
virtual IlvBoolean isPersistent() const;
private:
IlvDisplay* _display;
};
 
IlvMapsError
TileLoader::load(IlvTile* tile)
{
IlvRect rbbox;
tile->boundingBox(rbbox);
IlvRectangle *rect = new IlvRectangle(_display, rbbox);
tile->addObject(rect);
 
IlString str;
str += "(";
str += tile->getColumn();
str += ", ";
str += tile->getRow();
str += ")";
IlvMapLabel* label = new IlvMapLabel(_display,
IlvPoint(),
IlvPoint(),
IlvCenter,
10,
str.getValue());
IlvRect lbbox;
label->boundingBox(lbbox);
IlvPos cx = rbbox.x() + rbbox.w() / 2;
IlvPos cy = rbbox.y() + rbbox.h() / 2;
label->move(cx - lbbox.w() / 2,
cy - lbbox.h() / 2);
tile->addObject(label);
tile->loadComplete();
return IlvMaps::NoError();
}
 
Its release method is invoked when the tile cache releases a tile. The tile.deleteAll method clears the tile.
 
void
TileLoader::release(IlvTile* tile) {
tile->deleteAll();
}
 

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.