Load-on-demand

JViews Maps offers a mechanism that lets you load into memory only the data that you want to display in a manager view. This mechanism, known as load-on-demand, is extremely valuable, especially when very large maps are concerned. Consider a database storing maps of the whole world with a scale of 1/25,000. If these maps were scanned with a resolution of 300 DPI, the required storage space would be as follows:
  • 654 kilobytes for 1 square kilometer
  • 64 megabytes for 100 square kilometers
  • Approximately 310 terabytes for the whole world
Given the volume of this data, it is crucial to have a load-on-demand mechanism that will load and display only the portion of a map of direct interest.

The IlvTiledLayer Class

The IlvTiledLayer IlvTi extends the IlvManagerLayer class and allows the loading of large sets of data, for example, large maps. It is divided into a number of rectangular areas called tiles (organized into grid cells or into a list of specified areas) and provides a notification mechanism to load only the graphic objects that are required by the application, because a tile is visible in one of the views of the manager or because it has been explicitly required by the application.
An IlvTiledLayer is associated with three important objects:
When an IlvTiledLayer is saved into an .ivl file, it does not save the graphic objects it contains. It saves its tiling parameters (loader, cache, tile controller, tiling structure).

The IlvTileController Class

The IlvTileController class manages the load-on-demand mechanism. It divides the space into a number of rectangular areas called tiles, in two different fashions according to its mode:
  • In indexed mode, tiles are distributed on a regular grid defined by its origin rectangle. A tile is then referenced by its line and column indices. All tiles have the same height and width, and are automatically created as needed by the IlvTileController , according to the visible parts of the tiled layer in the manager views.
  • In free mode, however, the IlvTileController holds a list of IlvFreeTile instances that need to be created and then added to the tile controller. These tiles can have different sizes and locations, and can also overlap.
The tiling mode for an IlvTileController is set at creation time and can not be modified afterwards.
Each time a tile becomes visible in a view of the manager to which it is attached, the tile controller notifies a loader (called tile loader) to load the data attached to this tile. A cache releases the invisible tiles (called the cached tiles) when it is necessary to free memory.

The IlvTileLoader Interface

The IlvTileLoader interface is used to load a tile for an IlvTileController or an IlvTiledLayer.
The following example shows a tile loader that fills a tile with a generated list of graphic objects.
  class SimpleTileLoader 
    implements IlvTileLoader
  {
    public void load(IlvTile tile)
    {
      IlvRect rect = new IlvRect();
      tile.boundingBox(rect);
      IlvPoint p = new IlvPoint();
      p.x = rect.x;
      for (int i = 0; i < 10; i++) {
        p.y = rect.y;
        for (int j = 0; j < 10; j++) {
          tile.addObject(new IlvMarker(p, IlvMarker.IlvMarkerPlus), 
                         null);
          p.y += rect.height / 10;
        }
        p.x += rect.width / 10;
      }
      tile.loadComplete();
    }
    public void release(IlvTile tile)
    {
      tile.deleteAll();
    }

    public boolean isPersistent()
    {
      return false;
    }

    public void write(IlvOutputStream stream)
    {
      // do nothing 
    }
  }

The IlvTileCache Class

The IlvTileCache class is used to manage the cached tiles of one or more tile controllers. A cached tile is a tile that is not visible in any view and that is not locked by any application object. An IlvTileCache object releases the cached tiles to free memory when necessary.

The IlvTile Class

A tile represents an elementary rectangular area that is loaded or released when needed by the application. Tiles are managed by an IlvTileController.
In most cases, the tile controller will be associated with an IlvTiledLayer. This means that the tiles represent areas that must be filled with graphic objects when they become visible due to the user of the application scrolling or zooming on a view.
More sophisticated applications can use a tile controller without attaching it to a layer, for example, to load data that is needed to process an area that becomes visible.
For example, to define a geographic coordinate system expressing latitude and longitude with grads, instead of degrees, you can use the following code:
IlvAngularUnit unit = IlvAngularUnit.GRAD;
IlvGeographicCoordinateSystem gcs = 
   new IlvGeographicCoordinateSystem("My coordsys",
                                      IlvHorizontalShiftDatum.WGS84,
                              IlvMeridian.GREENWICH,
                              unit,
                              null); // No altitude

// A transformation from WGS84 geographic coordinate system
// with degrees as unit to our own coordinate system:
IlvCoordinateTransformation ct =
   IlvCoordinateTransformation.CreateTransformation(
      IlvGeographicCoordinateSystem.WGS84,
      gcs);

// Example of conversion.
double lambda = IlvAngularUnit.DEGREE.toRadians(-45D);
double phi =    IlvAngularUnit.DEGREE.toRadians(30D);
IlvCoordinate coord = new IlvCoordinate(lambda,phi);

// Convert coordinate, letting the transformation allocate the
// result.
IlvCoordinate result = ct.transform(coord,null);

System.out.println("The expression of point 45W 30N is ");
System.out.println("x = " + coord.x + " grad");
System.out.println("y = " + coord.y + " grad");

The IlvFreeTile Class

This class is similar to the IlvTile, except that instead of being part of a regular grid (and therefore indexed by line and column), its bounds can be freely specified. This is particularly useful when overlapping areas are needed, for example, in case of a projected map. Note that although IlvFreeTile is a subclass of IlvTile (for compatibility reasons), the member variables row and column are not relevant in terms of tile location. They are used to locate a superclass IlvTile instance on a grid, but given that IlvFreeTile objects have bounds of their own, there is no need for line and column properties.