com.maryanovsky.map.client
Class ImageTileLayer

java.lang.Object
  extended by com.maryanovsky.map.client.ImageTileLayer
All Implemented Interfaces:
TileLayer
Direct Known Subclasses:
OsmTileLayer

public class ImageTileLayer
extends Object
implements TileLayer

An implementation of tile layers in which each tile consists of a single image retrieved from a URL. The URL for each tile is constructed from a pattern; see ImageTileLayer(SizeView, String) for more information.

Author:
Alexander Maryanovsky

Constructor Summary
ImageTileLayer(SizeView tileImageSize, String tileUrlPattern)
          Creates a new ImageTileLayer with the specified tile image size and tile URL pattern.
 
Method Summary
 Tile getTile(int x, int y, int zoom)
          Returns the tile to display at the specified location (in pixels, relative to the top-left of the map) and zoom.
 SizeView getTileSize()
          Returns the size of tiles.
protected  String getTileUrl(int xIndex, int yIndex, int zoom)
          Returns the URL of the tile image at the specified zoom and indices, or null if none.
protected  String getTileUrl(String xArg, String yArg, String zoomArg)
          Returns the URL of the tile image at the specified zoom and indices.
 void releaseTile(Tile tile)
          Releases any resources associated with the specified tile that was returned by TileLayer.getTile(int, int, int).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageTileLayer

public ImageTileLayer(SizeView tileImageSize,
                      String tileUrlPattern)

Creates a new ImageTileLayer with the specified tile image size and tile URL pattern. The pattern is used to obtain a URL from the x index, y index and the zoom of a tile in the following manner:

The first three replacement rules allow specifying the positions of the x and y indices and the zoom value within the URL. The last rule allows specifying the different domains at which the tiles are available. This is commonly used to work around the browser limitation on the number of simultaneous connections to a single domain.

Example: the pattern http://tile[1,2,3].mymaps.com/plain/{zoom}/{x}_{y}.png could produce the URL http://tile2.mymaps.com/plain/9/734_983.png.

Method Detail

getTileSize

public SizeView getTileSize()
Returns the size of tiles.

Specified by:
getTileSize in interface TileLayer

getTile

public Tile getTile(int x,
                    int y,
                    int zoom)
Returns the tile to display at the specified location (in pixels, relative to the top-left of the map) and zoom. Returns null if there is no tile at the specified location, if, for example, it is outside the boundaries of the map.

Specified by:
getTile in interface TileLayer

releaseTile

public void releaseTile(Tile tile)
Releases any resources associated with the specified tile that was returned by TileLayer.getTile(int, int, int).

Specified by:
releaseTile in interface TileLayer

getTileUrl

protected String getTileUrl(int xIndex,
                            int yIndex,
                            int zoom)
Returns the URL of the tile image at the specified zoom and indices, or null if none. Note that xIndex and yIndex are not pixel coordinates like in TileLayer.getTile(int, int, int), but the indices of the tiles in their respective row and column at the tile grid of the specified zoom. The default implementation converts the three arguments to string representations via String.valueOf(int) and invokes getTileUrl(int, int, int). You should override this method if you need to perform some checks or possibly change the values of the parameters, or if you need a different representation of them to be inserted into the pattern.


getTileUrl

protected String getTileUrl(String xArg,
                            String yArg,
                            String zoomArg)
Returns the URL of the tile image at the specified zoom and indices. The arguments have already been checked and converted to their final string form. The default implementation applies them to the tile URL pattern and returns the result.