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 or the IlvMapTileLoader interface. Notice, however,
that for the predefined map formats supplied with JViews Maps, 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. The
IlvMapTileLoader
class and the predefined formats are described in Readers and writers.
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.
Its
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
tile.addObject()
method. When loading is complete, it calls the
tile.loadComplete
method to notify the listeners that the data in the tile is ready
for use.
public class LodLoader implements IlvTileLoader { [...] public void load(IlvTile tile) throws Exception { IlvRect bbox = new IlvRect(); tile.boundingBox(bbox); // Add a rectangle inside the tile bounding box tile.addObject(new IlvRectangle(bbox),null); // Add text String text = this.layerName + " (" + tile.getColumn() + "," + tile.getRow() + ")"; IlvPoint textCenter = new IlvPoint(bbox.x + bbox.width / 2, bbox.y + bbox.height / 2); tile.addObject(new IlvLabel(textCenter,text),null); tile.loadComplete(); } [...]
Its
release()
method is invoked when the tile cache releases a tile. The
tile.deleteAll
method clears the tile.
/** * Releases the objects on this tile. */ public void release(IlvTile tile) { tile.deleteAll(); }
The complete source code of this example can
be found in the following file: