public class MapView extends ZoomPanLayout
It might be best described as a hybrid of com.google.android.maps.MapView and iOS's CATiledLayer, and is appropriate for a variety of uses but was intended for map-type applications, especially high-detail or custom implementations (e.g., inside a building).
A minimal implementation might look like this:
MapView mapView = new MapView(this);
mapView.addZoomLevel(3090, 2536, "path/to/tiles/%col%-%row%.jpg");
A more advanced implementation might look like this:
MapView mapView = new MapView(this);
mapView.addMapEventListener(someMapEventListener);
mapView.registerGeolocator(42.379676, -71.094919, 42.346550, -71.040280);
mapView.addZoomLevel(6180, 5072, "tiles/boston-1000-%col%_%row%.jpg", 256, 256);
mapView.addZoomLevel(3090, 2536, "tiles/boston-500-%col%_%row%.jpg", 256, 256);
mapView.addZoomLevel(1540, 1268, "tiles/boston-250-%col%_%row%.jpg", 256, 256);
mapView.addZoomLevel(770, 634, "tiles/boston-125-%col%_%row%.jpg", 128, 128);
mapView.addMarker(someView, 42.35848, -71.063736);
mapView.addMarker(anotherView, 42.3665, -71.05224);
Licensed under Creative Commons
Modifier and Type | Class and Description |
---|---|
static interface |
MapView.MapEventListener
Interface for implementations to recieve MapView events.
|
static class |
MapView.MapEventListenerImplementation
Convenience class that implements
|
ZoomPanLayout.GestureListener, ZoomPanLayout.ZoomPanListener
Constructor and Description |
---|
MapView(Context context)
Constructor to use when creating a MapView from code.
|
Modifier and Type | Method and Description |
---|---|
View |
addCallout(View view,
double x,
double y)
Add a callout to the the MapView.
|
View |
addCallout(View view,
double x,
double y,
boolean absolute)
Add a callout to the the MapView.
|
View |
addCallout(View view,
double x,
double y,
float aX,
float aY)
Add a callout to the the MapView.
|
View |
addCallout(View view,
double x,
double y,
float aX,
float aY,
boolean absolute)
Add a callout to the the MapView.
|
void |
addChild(View view)
Adds a View to the intermediary ViewGroup that manages layout for the ZoomPanLayout.
|
void |
addHotSpot(Rect rectangle,
View.OnClickListener listener)
Register a rectangle that should fire an OnClickListener when a touch event occurs that intersects that rectangle.
|
void |
addMapEventListener(MapView.MapEventListener listener)
Register a map event listener callback object for this MapView.
|
View |
addMarker(View view,
double x,
double y)
Add a marker to the the MapView.
|
View |
addMarker(View view,
double x,
double y,
boolean absolute)
Add a marker to the the MapView.
|
View |
addMarker(View view,
double x,
double y,
float aX,
float aY)
Add a marker to the the MapView.
|
View |
addMarker(View view,
double x,
double y,
float aX,
float aY,
boolean absolute)
Add a marker to the the MapView.
|
View |
addMarkerAtZoom(View view,
double x,
double y,
float aX,
float aY,
int zoom)
Add a marker to the the MapView.
|
View |
addMarkerAtZoom(View view,
double x,
double y,
float aX,
float aY,
int zoom,
boolean absolute)
Add a marker to the the MapView.
|
View |
addMarkerAtZoom(View view,
double x,
double y,
int zoom)
Add a marker to the the MapView.
|
View |
addMarkerAtZoom(View view,
double x,
double y,
int zoom,
boolean absolute)
Add a marker to the the MapView.
|
void |
addZoomLevel(int wide,
int tall,
java.lang.String pattern)
Register a tile set to be used for a particular zoom level.
|
void |
addZoomLevel(int wide,
int tall,
java.lang.String pattern,
int tileWidth,
int tileHeight)
Register a tile set to be used for a particular zoom level.
|
void |
addZoomLevel(int wide,
int tall,
java.lang.String pattern,
java.lang.String downsample)
Register a tile set to be used for a particular zoom level.
|
void |
addZoomLevel(int wide,
int tall,
java.lang.String pattern,
java.lang.String downsample,
int tileWidth,
int tileHeight)
Register a tile set to be used for a particular zoom level.
|
void |
cancelRender()
Notify the map view that it may stop rendering tiles.
|
void |
clear()
Clear bitmap tiles, appropriate for onPause.
|
void |
destroy()
Clear bitmap tiles and remove all views, appropriate for onDestroy
References to MapView should be set to null following invocations of this method.
|
View |
drawPath(double[]... positions)
Draw a path (line) on the MapView that will be rendered beneath any Marker or Callout views.
|
View |
drawPath(java.util.List<double[]> positions)
Draw a path (line) on the MapView that will be rendered beneath any Marker or Callout views.
|
View |
drawPathAtZoom(int zoom,
double[]... positions)
Draw a path (line) on the MapView that will be rendered beneath any Marker or Callout views.
|
View |
drawPathAtZoom(int zoom,
java.util.List<double[]> positions)
Draw a path (line) on the MapView that will be rendered beneath any Marker or Callout views.
|
int |
getZoom()
Get the current zoom level (index) used by the MapView
|
double[] |
latLngToPixels(double[] coordinates)
Converts coordinates values to pixels using the geolocation rectangle provided by @link #registerGeolocator(double, double, double, double)
|
double[] |
latLngToPixels(double lat,
double lng)
Converts coordinates values to pixels using the geolocation rectangle provided by @link #registerGeolocator(double, double, double, double)
|
void |
lockZoom()
While zoom is locked (after this method is invoked, and before unlockZoom is invoked),
the ZoomLevel will not change, and the current ZoomLevel will be scaled beyond the normal
bounds.
|
void |
moveTo(double x,
double y)
Scroll the MapView to the x and y positions provided.
|
void |
moveTo(double x,
double y,
boolean absolute)
Scroll the MapView to the x and y positions provided.
|
void |
moveToAndCenter(double x,
double y)
Scroll the MapView to the x and y positions provided and center to the screen.
|
void |
moveToAndCenter(double x,
double y,
boolean absolute)
Scroll the MapView to the x and y positions provided and center to the screen.
|
double[] |
pixelsToLatLng(double[] points)
Converts pixels values to coordinates using the geolocation rectangle provided by @link #registerGeolocator(double, double, double, double)
|
double[] |
pixelsToLatLng(double x,
double y)
Converts pixels values to coordinates using the geolocation rectangle provided by @link #registerGeolocator(double, double, double, double)
|
void |
registerGeolocator(double left,
double top,
double right,
double bottom)
Register a set of offset points to use when calculating position within the MapView.
|
boolean |
removeCallout(View view)
Removes a callout View from the MapView's view tree.
|
void |
removeHotSpot(Rect rectangle,
View.OnClickListener listener)
Remove a hotspot registered with addHotSpot
|
void |
removeMapEventListener(MapView.MapEventListener listener)
Removes a MapEventListener object from those listening to this MapView.
|
boolean |
removeMarker(View view)
Removes a marker View from the MapView's view tree.
|
boolean |
removePath(View view)
Removes a path View from the MapView's view tree.
|
void |
requestRender()
Request that the current tile set is re-examined and re-drawn.
|
void |
resetZoomLevels()
Clear all previously registered zoom levels.
|
void |
setCacheEnabled(boolean shouldCache)
Enables or disables map-tile image caching (in-memory and on-disk)
|
void |
setMarkerAnchorPoints(float anchorX,
float anchorY)
Markers added to this MapView will have anchor logic applied on the values provided here.
|
void |
setTileDecoder(MapTileDecoder decoder)
Sets a custom class to perform the decode operation when tile bitmaps are requested.
|
void |
setZoom(int zoom)
Changes the zoom level used by the MapView.
|
void |
slideTo(double x,
double y)
Scroll the MapView to the x and y positions provided, using scrolling animation.
|
void |
slideTo(double x,
double y,
boolean absolute)
Scroll the MapView to the x and y positions provided, using scrolling animation.
|
void |
slideToAndCenter(double x,
double y)
Scroll the MapView to the x and y positions provide and center to the screen,
using scrolling animation.
|
void |
slideToAndCenter(double x,
double y,
boolean absolute)
Scroll the MapView to the x and y positions provide and center to the screen,
using scrolling animation.
|
void |
unlockZoom()
Unlocks a ZoomLevel locked with lockZoom
|
void |
unregisterGeolocator()
Removes the geolocation rectangle from this MapView's registry.
|
addGestureListener, addView, addZoomPanListener, computeScroll, getBaseHeight, getBaseWidth, getScale, getScaledHeight, getScaledWidth, isFlinging, onInterceptTouchEvent, onTouchEvent, removeChild, removeGestureListener, removeView, removeZoomPanListener, scrollToAndCenter, scrollToPoint, setScale, setScaleLimits, setScaleToFit, setShouldIntercept, setSize, slideToAndCenter, slideToPoint, smoothScaleTo
public MapView(Context context)
context
- (Context) The Context the MapView is running in, through which it can access the current theme, resources, etc.public int getZoom()
public void setZoom(int zoom)
zoom
- (int) zoom index to usepublic void addMapEventListener(MapView.MapEventListener listener)
listener
- (MapEventListener) an implementation of the MapEventListener interfacepublic void removeMapEventListener(MapView.MapEventListener listener)
listener
- (MapEventListener) an implementation of the MapEventListener interfacepublic void requestRender()
public void cancelRender()
public void setCacheEnabled(boolean shouldCache)
shouldCache
- (boolean) true to enable caching, false to disable it (default)public void setTileDecoder(MapTileDecoder decoder)
MapTileDecoderHttp
is an example of such an implementation.decoder
- (MapTileDecoder) A class instance that implements MapTileDecoder, and must define a decode method, which accepts a String file name and a Context object, and returns a Bitmappublic void addZoomLevel(int wide, int tall, java.lang.String pattern)
wide
- (int) total width of the tile settall
- (int) total height of the tile setpattern
- (String) string path to the location of the map tiles (in the assets directory), with %col% and %row% to be replaced by their respective integer positions. E.g., "folder/tile-%col%-%row%.jpg"public void addZoomLevel(int wide, int tall, java.lang.String pattern, java.lang.String downsample)
wide
- (int) total width of the tile settall
- (int) total height of the tile setpattern
- (String) string path to the location of the map tiles (in the assets directory), with %col% and %row% to be replaced by their respective integer positions. E.g., "folder/tile-%col%-%row%.jpg"downsample
- (String) string path to the location of an optional non-tiled image to serve as the background for a ZoomLevel. It's recommended that this image is low-res and small in size.public void addZoomLevel(int wide, int tall, java.lang.String pattern, int tileWidth, int tileHeight)
wide
- (int) total width of the tile settall
- (int) total height of the tile setpattern
- (String) string path to the location of the map tiles (in the assets directory), with %col% and %row% to be replaced by their respective integer positions. E.g., "folder/tile-%col%-%row%.jpg"tileWidth
- (int) size of each tiled columntileHeight
- (int) size of each tiled rowpublic void addZoomLevel(int wide, int tall, java.lang.String pattern, java.lang.String downsample, int tileWidth, int tileHeight)
wide
- (int) total width of the tile settall
- (int) total height of the tile setpattern
- (String) string path to the location of the map tiles (in the assets directory), with %col% and %row% to be replaced by their respective integer positions. E.g., "folder/tile-%col%-%row%.jpg"downsample
- (String) string path to the location of an optional non-tiled image to serve as the background for a ZoomLevel. It's recommended that this image is low-res and small in size.tileWidth
- (int) size of each tiled columntileHeight
- (int) size of each tiled rowpublic void resetZoomLevels()
public void lockZoom()
public void unlockZoom()
public void registerGeolocator(double left, double top, double right, double bottom)
left
- (double) the left edge of the rectangle used when calculating position (longitude of the bottom-right coordinate)top
- (double) the top edge of the rectangle used when calculating position (latitude of the top-left coordinate)right
- (double) the right edge of the rectangle used when calculating position (longitude of the top-left coordinate)bottom
- (double) the bottom edge of the rectangle used when calculating position (latitude of the bottom-right coordinate)public void unregisterGeolocator()
public double[] pixelsToLatLng(double x, double y)
x
- (double) pixel value of the x-axis to be translatedy
- (double) pixel value of the y-axis to be translatedjava.lang.UnsupportedOperationException
- if no geolocation rectangle has been previously registered.public double[] pixelsToLatLng(double[] points)
points
- (double[]) 2-element array of pixel values. The x-value should be at position 0, and the y-value at position 1java.lang.UnsupportedOperationException
- if no geolocation rectangle has been previously registered.public double[] latLngToPixels(double lat, double lng)
lat
- (double) latitude of the value to be translated to y-axis pixellng
- (double) longitude of the value to be translated to x-axis pixeljava.lang.UnsupportedOperationException
- if no geolocation rectangle has been previously registered.public double[] latLngToPixels(double[] coordinates)
points
- (double[]) 2-element array of pixel values. Latitude should be at position 0, and longitude at position 1java.lang.UnsupportedOperationException
- if no geolocation rectangle has been previously registered.public void moveTo(double x, double y)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus topublic void moveTo(double x, double y, boolean absolute)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus toabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic void moveToAndCenter(double x, double y)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus topublic void moveToAndCenter(double x, double y, boolean absolute)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus toabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic void slideTo(double x, double y)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus topublic void slideTo(double x, double y, boolean absolute)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus toabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic void slideToAndCenter(double x, double y)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus topublic void slideToAndCenter(double x, double y, boolean absolute)
x
- (double) x position the MapView should focus toy
- (double) y position the MapView should focus toabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic void setMarkerAnchorPoints(float anchorX, float anchorY)
anchorX
- (float) the x-axis position of a marker will be offset by a number equal to the negative width of the marker multiplied by this valueanchorY
- (float) the y-axis position of a marker will be offset by a number equal to the negative height of the marker multiplied by this valuepublic View addMarker(View view, double x, double y)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atpublic View addMarker(View view, double x, double y, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic View addMarker(View view, double x, double y, float aX, float aY)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a marker will be offset by a number equal to the negative width of the marker multiplied by this valueaY
- (float) the y-axis position of a marker will be offset by a number equal to the negative height of the marker multiplied by this valuepublic View addMarker(View view, double x, double y, float aX, float aY, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a marker will be offset by a number equal to the negative width of the marker multiplied by this valueaY
- (float) the y-axis position of a marker will be offset by a number equal to the negative height of the marker multiplied by this valueabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic View addMarkerAtZoom(View view, double x, double y, int zoom)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atzoom
- (int) the zoom level (index) that this view should be shown atpublic View addMarkerAtZoom(View view, double x, double y, int zoom, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atzoom
- (int) the zoom level (index) that this view should be shown atabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic View addMarkerAtZoom(View view, double x, double y, float aX, float aY, int zoom)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a marker will be offset by a number equal to the negative width of the marker multiplied by this valueaY
- (float) the y-axis position of a marker will be offset by a number equal to the negative height of the marker multiplied by this valuezoom
- (int) the zoom level (index) that this view should be shown atpublic View addMarkerAtZoom(View view, double x, double y, float aX, float aY, int zoom, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a marker will be offset by a number equal to the negative width of the marker multiplied by this valueaY
- (float) the y-axis position of a marker will be offset by a number equal to the negative height of the marker multiplied by this valuezoom
- (int) the zoom level (index) that this view should be shown atabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic boolean removeMarker(View view)
view
- The marker View to be removed.public View addCallout(View view, double x, double y)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atpublic View addCallout(View view, double x, double y, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned atabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic View addCallout(View view, double x, double y, float aX, float aY)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a callout view will be offset by a number equal to the negative width of the callout view multiplied by this valueaY
- (float) the y-axis position of a callout view will be offset by a number equal to the negative height of the callout view multiplied by this valuepublic View addCallout(View view, double x, double y, float aX, float aY, boolean absolute)
view
- (View) View instance to be added to the MapViewx
- (double) x position the View instance should be positioned aty
- (double) y position the View instance should be positioned ataX
- (float) the x-axis position of a callout view will be offset by a number equal to the negative width of the callout view multiplied by this valueaY
- (float) the y-axis position of a callout view will be offset by a number equal to the negative height of the callout view multiplied by this valueabsolute
- (boolean) true to always use pixel values and omit geolocation translationpublic boolean removeCallout(View view)
view
- The callout View to be removed.public void addHotSpot(Rect rectangle, View.OnClickListener listener)
rectangle
- (Rect) the rectangle that is tested against touch events that occur on the MapViewlistener
- (View.OnClickListener) the OnClickListener instance that is fired if the rectangle intersects a touch eventpublic void removeHotSpot(Rect rectangle, View.OnClickListener listener)
rectangle
- (Rect) the rectangle to test forlistener
- (View.OnClickListener) the listener that was registered to this hotspotpublic View drawPath(java.util.List<double[]> positions)
positions
- (Listpublic View drawPath(double[]... positions)
positions
- (double[]...) array (or var-args) of 2-element double arrays. Each element or argument represents a position; each position represents a point.public View drawPathAtZoom(int zoom, java.util.List<double[]> positions)
zoom
- (int) the zoom level (index) that this view should be shown atpositions
- (Listpublic View drawPathAtZoom(int zoom, double[]... positions)
zoom
- (int) the zoom level (index) that this view should be shown atpositions
- (double[]...) array (or var-args) of 2-element double arrays. Each element or argument represents a position; each position represents a point.public boolean removePath(View view)
view
- The path View to be removed.public void clear()
public void destroy()
public void addChild(View view)
ZoomPanLayout
addChild
in class ZoomPanLayout
view
- (View) The View to be added to the ZoomPanLayout view treejava.lang.UnsupportedOperationException
- MapView does not allow direct insertion of child views.