com.esri.map
Class OpenStreetMapLayer

java.lang.Object
  extended by com.esri.map.Layer
      extended by com.esri.map.OpenStreetMapLayer

public class OpenStreetMapLayer
extends Layer

Layer that supports OpenStreetMap (OSM) tile servers.

Default tile servers used are:

To use different tile servers, create this layer using OpenStreetMapLayer(ArrayList, int, int, String), or use #setTileServerURLs(ArrayList, int, int). Some of the tile servers available are listed at Tile Servers.

If access to the tile servers require a key that should not be hard-coded into the URL string, then the URLs can have a placeholder for key identified by "{KEY}". setKey(String) can be used replace the placeholder with actual key at runtime.

NOTE: Attribution is provided for the default tile servers. Please check whether it is appropriate at the time of usage. Refer to Tile usage policy to provide attribution appropriate to the tile servers used. Use Layer.getCopyrightText(), Layer.setCopyrightText(String).

The visibility and location of copyright is controlled by the corresponding JMap.

Since:
10.1.1

Nested Class Summary
 
Nested classes/interfaces inherited from class com.esri.map.Layer
Layer.LayerStatus
 
Field Summary
protected  int[] displayLevels
           
static int DPI
          Resolution - dots per inch.
protected  ConcurrentHashMap<String,Future<?>> pending
           
protected static ExecutorService pool
           
static double XMAX
          Maximum X coordinate in meters for the full extent.
static double XMIN
          Minimum X coordinate in meters for the full extent.
static double YMAX
          Maximum Y coordinate in meters for the full extent.
static double YMIN
          Minimum Y coordinate in meters for the full extent.
 
Fields inherited from class com.esri.map.Layer
_credentials, _progress, _resolutionList, serviceInfo
 
Constructor Summary
OpenStreetMapLayer()
          Creates an instance of OpenStreetMapLayer with default tile servers and attribution.
OpenStreetMapLayer(ArrayList<String> tileServerURLs, int minZoomLevel, int maxZoomLevel, String attributionText)
          Creates an instance of OpenStreetMapLayer with specified tile servers.
 
Method Summary
protected  void cancelRequest(int lod, int col, int row)
           
 void clearTiles()
          Cancels all current tile request.
protected  void createNativeLayer()
           
 SpatialReference getDefaultSpatialReference()
          Gets the defaultSpatialReference of the Layer.
protected  Rectangle getExtentBoundsOnScreen()
           
 LayerLegendInfoCollection getLegend()
           
 com.esri.map.JMap.LogoInfo getLogoInfo()
          Gets the logo info.
 int getMaxZoomLevel()
          Returns the maximum zoom level.
 int getMinZoomLevel()
          Returns the minimum zoom level.
 double getResolution()
          Gets the resolution of the Layer.
protected  void getTileAsynch(int lod, int col, int row, com.esri.map.TiledMapServiceLayer.TileListener tilecallback)
           
 ArrayList<String> getTileServerURLs()
          The URLs used to fetch tiles from.
 String getUrl()
          Gets the URL of the map service associated with the layer.
protected  void init(boolean isVisible, int[] displayLevels, String title, float opacity)
          This method is called only when composing a Map from a Web Map.
protected  void initializeNativeLayer()
           
protected  void internalInit()
           
protected  long nativeCreateLayer()
           
protected  boolean nativeInitialize(long layerHandle, int pWKT, String wkt, double originX, double originY, double minX, double minY, double maxX, double maxY, double[] lodScale, double[] lodResolution, int lodCount, int dpi, int tilePixelWidth, int tilePixelHeight)
           
protected  void nativeSetCachePath(long layerHandle, String path)
           
protected  void nativeSetTile(long layerHandle, int lod, int col, int row, byte[] pData, int size)
           
 void refresh()
          Fetches the information for the tiles again if any of the parameters have changed (map style, attribution) and refreshes the tiles accordingly.
protected  void requestTile(int lod, int col, int row)
           
 void setKey(String key)
          Replaces the placeholder "{KEY}" in the tile server URLs.
 void setLogoInfo(com.esri.map.JMap.LogoInfo logoInfo)
          Sets the logo info.
 void setTileServerURLs(ArrayList<String> tileServerURLs, int minZoomLevel, int maxZoomLevel, String attributionText)
          Sets the URLs used to fetch tiles from.
 void setUrl(String url)
          Sets the URL.
protected  void updateProgress()
          Update progress.
 
Methods inherited from class com.esri.map.Layer
addLayerInitializeCompleteListener, finalize, fireLayerCreateCompleteEvent, fireLayerCreateErrorEvent, fireLayerCreateErrorEvent, getCopyrightText, getCredentialsInternal, getDescription, getException, getExtent, getFullExtent, getInitialExtent, getInitializationError, getLayerHandle, getMap, getMapServer, getMapServerInfo, getMapServerLegendInfo, getMaxScale, getMinScale, getName, getOpacity, getPopupInfo, getResolutionList, getServiceDescription, getSpatialReference, getStatus, getUrlHashCode, initializeAsync, internalGetLayerLegendInfos, isHidingNoDataTiles, isInitialized, isReady, isShowingCopyright, isVisible, loadServiceInfo, lock, recycle, reinitializeAsync, removeLayerInitializeCompleteListener, setCopyrightText, setCredentials, setDefaultSpatialReference, setDescription, setError, setException, setFullExtent, setInitialExtent, setLayerHandle, setMap, setMapServer, setName, setOpacity, setPopupInfos, setServiceDescription, setShowingCopyright, setStatus, setVisible, unlock, updateSpatialReferenceStatus
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XMIN

public static final double XMIN
Minimum X coordinate in meters for the full extent.

See Also:
Constant Field Values

YMIN

public static final double YMIN
Minimum Y coordinate in meters for the full extent.

See Also:
Constant Field Values

XMAX

public static final double XMAX
Maximum X coordinate in meters for the full extent.

See Also:
Constant Field Values

YMAX

public static final double YMAX
Maximum Y coordinate in meters for the full extent.

See Also:
Constant Field Values

DPI

public static final int DPI
Resolution - dots per inch.

See Also:
Constant Field Values

displayLevels

protected int[] displayLevels

pending

protected final ConcurrentHashMap<String,Future<?>> pending

pool

protected static final ExecutorService pool
Constructor Detail

OpenStreetMapLayer

public OpenStreetMapLayer()
Creates an instance of OpenStreetMapLayer with default tile servers and attribution. Default tile servers used are:

See Also:
OpenStreetMapLayer(ArrayList, int, int, String)

OpenStreetMapLayer

public OpenStreetMapLayer(ArrayList<String> tileServerURLs,
                          int minZoomLevel,
                          int maxZoomLevel,
                          String attributionText)
Creates an instance of OpenStreetMapLayer with specified tile servers.

Parameters:
tile - servers that follow OSM specification to fetch tiles from.
minimum - zoom level
maximum - zoom level
attributionText - attribution to be used.
Throws:
IllegalArgumentException - if the tile server URLs are null or empty, or if the zoom levels are negative.
See Also:
OpenStreetMapLayer()
Method Detail

getLogoInfo

public com.esri.map.JMap.LogoInfo getLogoInfo()
Gets the logo info.

Returns:
the logo info.

setLogoInfo

public void setLogoInfo(com.esri.map.JMap.LogoInfo logoInfo)
Sets the logo info.

Parameters:
logoInfo - the logo info.

getTileServerURLs

public ArrayList<String> getTileServerURLs()
The URLs used to fetch tiles from.

Returns:
set of URLs.
See Also:
setTileServerURLs(ArrayList, int, int, String)

setTileServerURLs

public void setTileServerURLs(ArrayList<String> tileServerURLs,
                              int minZoomLevel,
                              int maxZoomLevel,
                              String attributionText)
Sets the URLs used to fetch tiles from.

Parameters:
tileServerURLs - URLs to be used to fetch tiles. Should not be null or empty.
minZoomLevel - minimum zoom level supported by the tile servers.
maxZoomLevel - maximum zoom level supported by the tile servers.
attributionText - text to be displayed as attribution.
Throws:
IllegalArgumentException - if the tile server URLs are null or empty, or if the zoom levels are negative.
See Also:
getTileServerURLs()

getMinZoomLevel

public int getMinZoomLevel()
Returns the minimum zoom level.

Returns:
the minimum zoom level.

getMaxZoomLevel

public int getMaxZoomLevel()
Returns the maximum zoom level.

Returns:
the maximum zoom level.

refresh

public void refresh()
Fetches the information for the tiles again if any of the parameters have changed (map style, attribution) and refreshes the tiles accordingly.


getLegend

public LayerLegendInfoCollection getLegend()
Specified by:
getLegend in class Layer

getResolution

public double getResolution()
Description copied from class: Layer
Gets the resolution of the Layer.

Overrides:
getResolution in class Layer
Returns:
resolution.

getDefaultSpatialReference

public SpatialReference getDefaultSpatialReference()
Description copied from class: Layer
Gets the defaultSpatialReference of the Layer. For service layers this is defined by the service.

Overrides:
getDefaultSpatialReference in class Layer
Returns:
Returns the defaultSpatialReference.

getUrl

public String getUrl()
Description copied from class: Layer
Gets the URL of the map service associated with the layer.

Overrides:
getUrl in class Layer
Returns:
the URL as a string.

setUrl

public void setUrl(String url)
Sets the URL.

Parameters:
url - the URL

setKey

public void setKey(String key)
Replaces the placeholder "{KEY}" in the tile server URLs.

Example:
String tileServerURL = "http://a.tile.cloudmade.com/{KEY}/3/256/";
After setKey("081abc");
tileServerURL = "http://a.tile.cloudmade.com/081abc/3/256/";

Parameters:
key - key to be used.

internalInit

protected void internalInit()

getExtentBoundsOnScreen

protected Rectangle getExtentBoundsOnScreen()

getTileAsynch

protected void getTileAsynch(int lod,
                             int col,
                             int row,
                             com.esri.map.TiledMapServiceLayer.TileListener tilecallback)

cancelRequest

protected void cancelRequest(int lod,
                             int col,
                             int row)

initializeNativeLayer

protected void initializeNativeLayer()
Specified by:
initializeNativeLayer in class Layer

requestTile

protected void requestTile(int lod,
                           int col,
                           int row)

clearTiles

public void clearTiles()
Cancels all current tile request. This method will cause the tiled layer to fetch new tiles in current extent and redraw.


init

protected void init(boolean isVisible,
                    int[] displayLevels,
                    String title,
                    float opacity)
Description copied from class: Layer
This method is called only when composing a Map from a Web Map. The web map contains properties that every layer should be initialized with, up front.

Specified by:
init in class Layer

createNativeLayer

protected void createNativeLayer()
Specified by:
createNativeLayer in class Layer

updateProgress

protected void updateProgress()
Update progress.


nativeCreateLayer

protected long nativeCreateLayer()

nativeInitialize

protected boolean nativeInitialize(long layerHandle,
                                   int pWKT,
                                   String wkt,
                                   double originX,
                                   double originY,
                                   double minX,
                                   double minY,
                                   double maxX,
                                   double maxY,
                                   double[] lodScale,
                                   double[] lodResolution,
                                   int lodCount,
                                   int dpi,
                                   int tilePixelWidth,
                                   int tilePixelHeight)

nativeSetTile

protected void nativeSetTile(long layerHandle,
                             int lod,
                             int col,
                             int row,
                             byte[] pData,
                             int size)

nativeSetCachePath

protected void nativeSetCachePath(long layerHandle,
                                  String path)


Copyright © 2012. All Rights Reserved.