Static or dynamic layers can be used in conjunction with
tiled views on the client side.
Static layers can be cached or pregenerated on the server.
Cached tiles are part of layers that are not expected to change within
the application lifecycle, as, for example, in a background map. Cached
tiles can be retrieved through a tile manager.
Dynamic layers are likely to change between requests
to the server, such as labeling or network display.
The tile manager, an instance of
IlvTileManager, stores and retrieves tiles on the server side.
IlvManagerServlet can
take advantage of such a tile manager if one is installed on the servlet.
When an image request is received by the servlet, if
a tile that matches the current request is managed by the tile manager,
it return this cached tile instead of generating a new image from
IlvManagerView. If a tile
is not yet managed by the tile manager, generate the image from
IlvManagerView
and
ask the tile manager to manage it for future access.
if (useTileManager(request)) {
IlvTileManager tm = getTileManager(request);
if (tm != null) {
Object key = getKey(request);
BufferedImage image = tm.getImage(key);
if (image == null) {
image = doGenerateImageImpl( ... );
tm.putImage(key, image);
}
return image;
}
}
return doGenerateImageImpl( ... );
The tile manager is invoked by default if the request
contains a parameter of the form
tile=true
.
If the request contains such a parameter,
useTileManager return
true
. You can
override the
useTileManager
method to call
the tile manager in other situations.
If a tile manager is installed, it be retrieved and
a key object be constructed from the request to reference the tile.
Then, an attempt is made to retrieve a tile from the tile manager.
If the attempt is successful, the tile is returned as the response
to the request.
If no tile is retrieved, an image be constructed through
the normal image generation process. This image is passed to the tile
manager for use in future retrievals.
The tile manager is not installed by default in an IlvManagerServletSupport object.
You need to subclass it to install a tile manager.
The method to override is
getTileManager. By default, this method returns null.
protected IlvTileManager getTileManager(HttpServletRequest request)
throws ServletException {
return null;
}
A default implementation of the tile manager is supplied.
This implementation stores tiles on disk. You can use it to develop
your own implementation of the getTileManager method.
protected IlvTileManager getTileManager(HttpServletRequest request)
throws ServletException {
ServletContext context = request.getSession().getServletContext();
IlvTileManager tileManager = (IlvTileManager)context.getAttribute("tileManagerKey");
if(tileManager == null) {
tileManager = new IlvFileTileManager(getBase(), getMaxCacheSize(),
getMinCacheSize());
context.setAttribute("tileManagerKey", tileManager);
}
return tileManager;
}
In this implementation you need to provide:
The base directory where the tiles are
written.
The maximum size allowed for the cache.
The size to which the cache be reduced
by removing files when the maximum size is reached.
When the maximum size is reached, the cache is considered
to be full and files be removed to reduce the size of the cache to
the level indicated.
The tile manager is stored and retrieved from the ServletContext
,
so that the same tile manager is used for the same application. You
can use a different strategy for storing and retrieving the tile manager.
You can also customize the reading and writing of tiles
and the name of the file that is generated for each tile. This default
implementation of the tile manager constructs a file name of the form x_y_width_height.jpg
,
where x
, y
, width
,
and height
are the manager coordinates
of the image request passed as the bbox
attribute
of the request.
This file is stored in and retrieved from the base directory
provided when the
IlvFileTileManager is constructed. This customization can be performed
through the
IlvFileTileURLFactory, which is responsible for building a URL from the
key that identifies the tile. The default key is a
Rectangle2D.Double
object,
which is created from the
bbox
parameter
of the request.