com.bbn.openmap.dataAccess.mapTile
Class ServerMapTileFactory

java.lang.Object
  extended by com.bbn.openmap.util.cacheHandler.CacheHandler
      extended by com.bbn.openmap.dataAccess.mapTile.StandardMapTileFactory
          extended by com.bbn.openmap.dataAccess.mapTile.ServerMapTileFactory
All Implemented Interfaces:
MapTileFactory, PropertyConsumer
Direct Known Subclasses:
GoogleMapTileFactory

public class ServerMapTileFactory
extends StandardMapTileFactory
implements MapTileFactory, PropertyConsumer

The ServerMapTileFactory is an extension to the StandardMapTileFactory that can go to a http server to retrieve image tiles. You provide it with a root URL that points to the parent directory of the tiles, and then this component will add on the zoom/x/y.extension to that directory path to make the call for a specific tile. Please make sure you have the permission of the server's owner before hammering away at retrieving tiles from it. This component can be configured using properties:

 # Inherited from StandardMapTileFactory
 rootDir=the URL to the parent directory of the tiles on a server. The factory will construct specific file paths that are appended to this value. 
 fileExt=the file extension to append to the tile names, should have a period.
 cacheSize=the number of mapTiles the factory should hold on to. The default is 100.
 
 # Additional properties
 localCacheRootDir=if specified, the factory will store tiles locally at this root directory.  This directory is checked before going to the server, too.
 

Author:
dietrick

Nested Class Summary
 
Nested classes/interfaces inherited from class com.bbn.openmap.dataAccess.mapTile.StandardMapTileFactory
StandardMapTileFactory.TilePathBuilder
 
Field Summary
static java.lang.String LOCAL_CACHE_ROOT_DIR_PROPERTY
           
protected  java.lang.String localCacheDir
           
 
Fields inherited from class com.bbn.openmap.dataAccess.mapTile.StandardMapTileFactory
CACHE_SIZE_PROPERTY, EMPTY_TILE_HANDLER_PROPERTY, emptyTileHandler, FILE_EXT_PROPERTY, fileExt, lastProj, logger, mapTileLogger, mapTileRequester, mtcTransform, MTCTRANSFORM_PROPERTY, prefix, ROOT_DIR_PATH_PROPERTY, ROOT_DIR_PROPERTY, rootDir, rootDirProperty, TILE_IMAGE_PREPARER_PROPERTY, TILE_PROPERTIES, tileImagePreparer, verbose, ZOOM_LEVEL_INFO_PROPERTY, ZOOM_LEVEL_TILE_SIZE_PROPERTY, zoomLevelInfo, zoomLevelTileSize
 
Fields inherited from class com.bbn.openmap.util.cacheHandler.CacheHandler
DEFAULT_MAX_CACHE_SIZE, logicalClock, objs
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Constructor Summary
ServerMapTileFactory()
           
ServerMapTileFactory(java.lang.String rootDir)
           
 
Method Summary
protected  java.lang.String buildCacheKey(int x, int y, int z, java.lang.String fileExt)
          Creates a unique cache key for this tile based on zoom, x, y.
 java.lang.String buildLocalFilePath(int x, int y, int z, java.lang.String fileExt)
          Acts the same as the buildFilePath method, but works for a local directory specified in the properties.
 java.lang.Object getFromCache(java.lang.Object key, int x, int y, int zoomLevel)
          An auxiliary call to retrieve something from the cache, modified to allow load method to do some projection calculations to initialize tile parameters.
 byte[] getImageBytes(java.lang.String imagePath, java.lang.String localFilePath)
          Tries to get the image bytes from imagePath URL.
 java.util.Properties getProperties(java.util.Properties getList)
          Method to fill in a Properties object, reflecting the current values of the PropertyConsumer.
 java.util.Properties getPropertyInfo(java.util.Properties list)
          Method to fill in a Properties object with values reflecting the properties able to be set on this PropertyConsumer.
 CacheObject load(java.lang.Object key, int x, int y, int zoomLevel, Projection proj)
          Checks the local directory first for a locally cached version of the tile before going off to the server.
 void reset()
          Tell the factory to dump the cache.
 void setProperties(java.lang.String prefix, java.util.Properties setList)
          Method to set the properties in the PropertyConsumer.
 
Methods inherited from class com.bbn.openmap.dataAccess.mapTile.StandardMapTileFactory
buildFilePath, configureFromProperties, createOMGraphicFromBufferedImage, get, getEmptyTile, getEmptyTileHandler, getFileExt, getInitPropertiesOrder, getMapTileRequester, getMtcTransform, getPropertyPrefix, getRootDir, getTileImagePreparer, getTileMatchingProjectionType, getTileNotMatchingProjectionType, getTilePathBuilder, getTiles, getTiles, getTiles, getTiles, getZoomLevelInfo, load, preprocessImage, setEmptyTileHandler, setFileExt, setMapTileRequester, setMtcTransform, setProperties, setPropertyPrefix, setRootDir, setTileImagePreparer, setTilePathBuilder, setZoomLevelInfo
 
Methods inherited from class com.bbn.openmap.util.cacheHandler.CacheHandler
clear, get, getCacheSize, listIterator, replaceLeastUsed, resetCache, resetCache, searchCache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bbn.openmap.dataAccess.mapTile.MapTileFactory
getEmptyTileHandler, getTiles, getTiles, getTiles, setMapTileRequester
 
Methods inherited from interface com.bbn.openmap.PropertyConsumer
getPropertyPrefix, setProperties, setPropertyPrefix
 

Field Detail

LOCAL_CACHE_ROOT_DIR_PROPERTY

public static final java.lang.String LOCAL_CACHE_ROOT_DIR_PROPERTY
See Also:
Constant Field Values

localCacheDir

protected java.lang.String localCacheDir
Constructor Detail

ServerMapTileFactory

public ServerMapTileFactory()

ServerMapTileFactory

public ServerMapTileFactory(java.lang.String rootDir)
Method Detail

getFromCache

public java.lang.Object getFromCache(java.lang.Object key,
                                     int x,
                                     int y,
                                     int zoomLevel)
An auxiliary call to retrieve something from the cache, modified to allow load method to do some projection calculations to initialize tile parameters. If the object is not found in the cache, null is returned.

Overrides:
getFromCache in class StandardMapTileFactory
Parameters:
key - cache key, usually string of location of a tile
x - uv x location of tile
y - uv y location of tile
zoomLevel - zoom level of tile
Returns:
cache object if found, null if not.

load

public CacheObject load(java.lang.Object key,
                        int x,
                        int y,
                        int zoomLevel,
                        Projection proj)
Checks the local directory first for a locally cached version of the tile before going off to the server. If a local directory is listed as a cache, any retrieved files will be stored there for future use. We are using the local name of the file as the cache key for all tiles for consistency - all tiles are looked up with local cache locations.

Overrides:
load in class StandardMapTileFactory
Parameters:
key - cache key
x - uv x coordinate
y - uv y coordinate
zoomLevel - zoom level for tile to load
proj - passed solely to enable checking if the projection of the tiles matches the rendered projection.
Returns:
CacheObject returned from cache, null if not found

getImageBytes

public byte[] getImageBytes(java.lang.String imagePath,
                            java.lang.String localFilePath)
Tries to get the image bytes from imagePath URL. If image found, will write it locally to localFilePath for caching.

Parameters:
imagePath - the source URL image path.
localFilePath - the caching local file path
Returns:
byte[] of image

buildLocalFilePath

public java.lang.String buildLocalFilePath(int x,
                                           int y,
                                           int z,
                                           java.lang.String fileExt)
Acts the same as the buildFilePath method, but works for a local directory specified in the properties.

Parameters:
x - tile coordinate
y - tile coordinate
z - zoom level
fileExt - file extension for image tiles.
Returns:
new path for tile file

buildCacheKey

protected java.lang.String buildCacheKey(int x,
                                         int y,
                                         int z,
                                         java.lang.String fileExt)
Creates a unique cache key for this tile based on zoom, x, y. This method was created so the ServerMapTileFactory could override it and use local cache names for keys if a local cache was being used.

Overrides:
buildCacheKey in class StandardMapTileFactory
Parameters:
x - tile coord.
y - tile coord.
z - zoomLevel.
fileExt - file extension.
Returns:
String used in cache.

getProperties

public java.util.Properties getProperties(java.util.Properties getList)
Description copied from interface: PropertyConsumer
Method to fill in a Properties object, reflecting the current values of the PropertyConsumer. If the PropertyConsumer has a prefix set, the property keys should have that prefix plus a separating '.' prepended to each property key it uses for configuration.

Specified by:
getProperties in interface PropertyConsumer
Overrides:
getProperties in class StandardMapTileFactory
Parameters:
getList - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

getPropertyInfo

public java.util.Properties getPropertyInfo(java.util.Properties list)
Description copied from interface: PropertyConsumer
Method to fill in a Properties object with values reflecting the properties able to be set on this PropertyConsumer. The key for each property should be the raw property name (without a prefix) with a value that is a String that describes what the property key represents, along with any other information about the property that would be helpful (range, default value, etc.).

Specified by:
getPropertyInfo in interface PropertyConsumer
Overrides:
getPropertyInfo in class StandardMapTileFactory
Parameters:
list - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
Returns:
Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties setList)
Description copied from interface: PropertyConsumer
Method to set the properties in the PropertyConsumer. The prefix is a string that should be prepended to each property key (in addition to a separating '.') in order for the PropertyConsumer to uniquely identify properties meant for it, in the midst of of Properties meant for several objects.

Specified by:
setProperties in interface PropertyConsumer
Overrides:
setProperties in class StandardMapTileFactory
Parameters:
prefix - a String used by the PropertyConsumer to prepend to each property value it wants to look up - setList.getProperty(prefix.propertyKey). If the prefix had already been set, then the prefix passed in should replace that previous value.
setList - a Properties object that the PropertyConsumer can use to retrieve expected properties it can use for configuration.

reset

public void reset()
Tell the factory to dump the cache. For the ServerMapTileFactory, this also includes the local file cache dir.

Specified by:
reset in interface MapTileFactory
Overrides:
reset in class StandardMapTileFactory


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details