TileOverlay

public final class TileOverlay extends Object

A Tile Overlay is a set of images which are displayed on top of the base map tiles. These tiles may be transparent, allowing you to add features to existing maps. A tile overlay has the following properties:

Tile Provider
The TileProvider provides the images that are used in the tile overlay. You must specify the tile provider before it is added to the map. The tile provider cannot be changed once it has been added; however, you can modify the behavior of the tile provider to return different images for specific coordinates. If the tiles provided by the tile provider change, you must call clearTileCache() afterwards to ensure that the previous tiles are no longer rendered.
Z-Index
The order in which this tile overlay is drawn with respect to other overlays (including GroundOverlays, Circles, Polylines, and Polygons but not Markers). An overlay with a larger z-index is drawn over overlays with smaller z-indices. The order of overlays with the same z-index is arbitrary. The default zIndex is 0.
Transparency
Transparency of the tile overlay in the range [0..1] where 0 means the overlay is opaque and 1 means the overlay is fully transparent. If the specified bitmap is already partially transparent, the transparency of each pixel will be scaled accordingly (for example, if a pixel in the bitmap has an alpha value of 200 and you specify the transparency of the tile overlay as 0.25, then the pixel will be rendered on the screen with an alpha value of 150). Specification of this property is optional and the default transparency is 0 (opaque).
Visibility
Indicates if the tile overlay is visible or invisible, i.e., whether it is drawn on the map. An invisible tile overlay is not drawn, but retains all of its other properties. The default is true, i.e., visible.

You must only call methods in this class on the main thread. Failure to do so will result in an IllegalStateException.

Tile Coordinates

Note that the world is projected using the Mercator projection (see Wikipedia) with the left (west) side of the map corresponding to -180 degrees of longitude and the right (east) side of the map corresponding to 180 degrees of longitude. To make the map square, the top (north) side of the map corresponds to 85.0511 degrees of latitude and the bottom (south) side of the map corresponds to -85.0511 degrees of latitude. Areas outside this latitude range are not rendered.

At each zoom level, the map is divided into tiles and only the tiles that overlap the screen are downloaded and rendered. Each tile is square and the map is divided into tiles as follows:

  • At zoom level 0, one tile represents the entire world. The coordinates of that tile are (x, y) = (0, 0).
  • At zoom level 1, the world is divided into 4 tiles arranged in a 2 x 2 grid.
  • ...
  • At zoom level N, the world is divided into 4N tiles arranged in a 2N x 2N grid.
Note that the minimum zoom level that the camera supports (which can depend on various factors) is GoogleMap.getMinZoomLevel and the maximum zoom level is GoogleMap.getMaxZoomLevel.

The coordinates of the tiles are measured from the top left (northwest) corner of the map. At zoom level N, the x values of the tile coordinates range from 0 to 2N - 1 and increase from west to east and the y values range from 0 to 2N - 1 and increase from north to south.

Example

GoogleMap map; // ... get a map.
 TileProvider tileProvider; // ... create a tile provider.
 TileOverlay tileOverlay = map.addTileOverlay(
     new TileOverlayOptions().tileProvider(tileProvider));
 

Public Method Summary

void
clearTileCache()
Clears the tile cache so that all tiles will be requested again from the TileProvider.
boolean
equals(Object other)
Tests if this TileOverlay is equal to another.
boolean
getFadeIn()
Gets whether the overlay tiles should fade in.
String
getId()
Gets this tile overlay's id.
float
getTransparency()
Gets the transparency of this tile overlay.
float
getZIndex()
Gets the zIndex of this tile overlay.
int
boolean
isVisible()
Gets the visibility of this tile overlay.
void
remove()
Removes this tile overlay from the map.
void
setFadeIn(boolean fadeIn)
Sets whether the overlay tiles should fade in.
void
setTransparency(float transparency)
Sets the transparency of this tile overlay.
void
setVisible(boolean visible)
Sets the visibility of this tile overlay.
void
setZIndex(float zIndex)
Sets the zIndex of this tile overlay.

Inherited Method Summary

Public Methods

public void clearTileCache ()

Clears the tile cache so that all tiles will be requested again from the TileProvider. The current tiles from this tile overlay will also be cleared from the map after calling this method. The API maintains a small in-memory cache of tiles. If you want to cache tiles for longer, you should implement an on-disk cache.

public boolean equals (Object other)

Tests if this TileOverlay is equal to another.

Parameters
other an Object.
Returns
  • true if both objects are the same object, that is, this == other.

public boolean getFadeIn ()

Gets whether the overlay tiles should fade in.

Returns
  • true if the tiles are to fade in; false if they are not.

public String getId ()

Gets this tile overlay's id.

public float getTransparency ()

Gets the transparency of this tile overlay.

Returns
  • the transparency of this tile overlay.

public float getZIndex ()

Gets the zIndex of this tile overlay.

Returns
  • the zIndex of the tile overlay.

public int hashCode ()

public boolean isVisible ()

Gets the visibility of this tile overlay. Note that this does not return whether the tile overlay is actually within the screen's viewport, but whether it will be drawn if it is contained in the screen's viewport.

Returns
  • this tile overlay's visibility.

public void remove ()

Removes this tile overlay from the map.

public void setFadeIn (boolean fadeIn)

Sets whether the overlay tiles should fade in.

Parameters
fadeIn true to make the tiles fade in; false to render them instantly.

public void setTransparency (float transparency)

Sets the transparency of this tile overlay. See the documentation at the top of this class for more information.

Parameters
transparency a float in the range [0..1] where 0 means that the tile overlay is opaque and 1 means that the tile overlay is transparent.

public void setVisible (boolean visible)

Sets the visibility of this tile overlay. When not visible, a tile overlay is not drawn, but it keeps all its other properties. Tile overlays are visible by default.

Parameters
visible true to make this overlay visible; false to make it invisible.

public void setZIndex (float zIndex)

Sets the zIndex of this tile overlay. See the documentation at the top of this class for more information.

Parameters
zIndex the zIndex of this tile overlay.