Programming with JViews Maps > Creating a Map Application Using the API > Using Load-on-Demand > 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 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:

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:

<installdir>/jviews-maps81/codefragments/lod/srchtml/LodLoader.java