com.bbn.openmap.dataAccess.mapTile
Class StandardMapTileFactory

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

public class StandardMapTileFactory
extends CacheHandler
implements MapTileFactory, PropertyConsumer

The StandardImageTileFactory is a TileFactory implementation that retrieves image tiles from local storage. These tiles are assumed to be stored in the local file system, at some root directory, and then in some hierarchy like zoom-level/x coord/y coord.file-extension. This class can be extended to allow different tile naming/storing conventions to be used.

This component can be configured using properties:

 rootDir=the path to the parent directory of the tiles. The factory will construct specific file paths that are appended to this value. 
 fileExt=the file extension to append to the tile names
 cacheSize=the number of mapTiles the factory should hold on to. The default is 100.
 # default is OSMMapTileCoordinateTransform, but it depends on the source of tiles.  GDAL is TSMMapTileCoordinateTransform
 mapTileTransform=com.bbn.openmap.dataAccess.mapTile.OSMMapTileCoordinateTransform, or com.bbn.openmap.dataAccess.mapTile.TSMMapTileCoordinateTransform
 # what to do about missing tiles?
 emptyTileHandler=com.bbn.openmap.dataAccess.mapTile.SimpleEmptyTileHandler
 

Author:
dietrick

Field Summary
static java.lang.String CACHE_SIZE_PROPERTY
           
static java.lang.String EMPTY_TILE_HANDLER_PROPERTY
           
protected  EmptyTileHandler emptyTileHandler
           
static java.lang.String FILE_EXT_PROPERTY
           
protected  java.lang.String fileExt
           
protected  Projection lastProj
           
protected static java.util.logging.Logger logger
           
protected static java.util.logging.Logger mapTileLogger
           
protected  MapTileCoordinateTransform mtcTransform
          Coordinate transform for the uv coordinates of the tiles.
static java.lang.String MTCTRANSFORM_PROPERTY
           
protected  java.lang.String prefix
           
protected  java.awt.Component repaintCallback
          A component that is painting the tiles to the screen.
static java.lang.String ROOT_DIR_PATH_PROPERTY
          Inserted into properties loaded via tiles.omp, so that the EmptyTileHandler can know where the tile set is located, in case it needs to know the absolute path.
static java.lang.String ROOT_DIR_PROPERTY
           
protected  java.lang.String rootDir
           
protected  java.lang.String rootDirProperty
           
protected  float[] scales
          An array of scales for all of the possible zoom levels, from 1 to 20.
static java.lang.String TILE_PROPERTIES
          The name of the properties file that the factory looks for in the root directory of the data (tiles.omp).
protected  boolean verbose
           
static java.lang.String ZOOM_LEVEL_INFO_PROPERTY
           
static java.lang.String ZOOM_LEVEL_TILE_SIZE_PROPERTY
           
protected  ZoomLevelInfo zoomLevelInfo
           
protected  int 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
StandardMapTileFactory()
           
StandardMapTileFactory(java.awt.Component layer, java.lang.String rootDir, java.lang.String tileFileExt)
           
 
Method Summary
protected  void configureFromProperties(java.io.InputStream is, java.lang.String rootDirectory)
          Called with an input stream for a properties file, used for reading tiles.omp files.
protected  OMGraphic createOMGraphicFromBufferedImage(java.awt.image.BufferedImage bi, int x, int y, int zoomLevel, Projection proj)
          Creates an OMRaster appropriate for projection and other parameters from a buffered image.
 java.lang.Object get(java.lang.Object key, int x, int y, int zoomLevel, Projection proj)
          The main call to retrieve something from the cache, modified to allow load method to do some projection calculations to initialize tile parameters.
 CacheObject getEmptyTile(java.lang.Object key, int x, int y, int zoomLevel, Projection proj)
          Call to make when you want the tile factory to create some empty tile representation for the given location.
 EmptyTileHandler getEmptyTileHandler()
           
 java.lang.String getFileExt()
           
 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.
 MapTileCoordinateTransform getMtcTransform()
           
 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.
 java.lang.String getPropertyPrefix()
          Get the property key prefix that is being used to prepend to the property keys for Properties lookups.
 java.awt.Component getRepaintCallback()
           
 java.lang.String getRootDir()
           
protected  OMGraphic getTileMatchingProjectionType(java.awt.image.BufferedImage image, int x, int y, int zoomLevel)
          Create an OMScalingRaster that matches the basic projection of the current map.
protected  OMGraphic getTileNotMatchingProjectionType(java.awt.image.BufferedImage image, int x, int y, int zoomLevel)
          Create an OMWarpingImage that knows how to re-project itself for different projections.
protected  void getTiles(int uvleft, int uvright, int uvup, int uvbottom, ZoomLevelInfo zoomLevelInfo, Projection proj, OMGraphicList list)
           
 OMGraphicList getTiles(Projection proj)
          Returns projected tiles for the given projection.
 OMGraphicList getTiles(Projection proj, int zoomLevel)
          Returns projected tiles for given projection at specified zoom level.
 OMGraphicList getTiles(Projection proj, int zoomLevel, OMGraphicList list)
          Returns projected tiles for given projection at specified zoom level.
 int getZoomLevelForProj(Projection proj)
          Given a projection, figure out the appropriate zoom level for it.
 ZoomLevelInfo getZoomLevelInfo()
          Get the ZoomLevelInfo set on the factory.
 CacheObject load(java.lang.Object key)
          Called from get if the key doesn't exist, to "load" the new object into the cache before returning it.
 CacheObject load(java.lang.Object key, int x, int y, int zoomLevel, Projection proj)
          Called to load cache object from data source, when not found in cache.
protected  java.awt.image.BufferedImage preprocessImage(java.awt.Image origImage, int imageWidth, int imageHeight)
          Method that allows subclasses to modify the image as necessary before it is passed into an OMGraphic.
 void reset()
          Tell the factory to clean up resources.
 void setEmptyTileHandler(EmptyTileHandler emptyTileHandler)
           
 void setFileExt(java.lang.String fileExt)
           
 void setMtcTransform(MapTileCoordinateTransform mtcTransform)
          Set the map tile coordinate transformed used to figure out lat/lon to tile coordinates.
 void setProperties(java.util.Properties setList)
          Method to set the properties in the PropertyConsumer.
 void setProperties(java.lang.String prefix, java.util.Properties setList)
          Method to set the properties in the PropertyConsumer.
 void setPropertyPrefix(java.lang.String prefix)
          Set the property key prefix that should be used by the PropertyConsumer.
 void setRepaintCallback(java.awt.Component callback)
          Set a component in the tile factory that should be told to repaint when new tiles become available.
 void setRootDir(java.lang.String rootDirectory)
           
 void setZoomLevelInfo(ZoomLevelInfo zoomLevelInfo)
          Get the ZoomLevelInfo set on the factory.
 
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
 

Field Detail

prefix

protected java.lang.String prefix

logger

protected static final java.util.logging.Logger logger

mapTileLogger

protected static final java.util.logging.Logger mapTileLogger

ROOT_DIR_PROPERTY

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

FILE_EXT_PROPERTY

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

CACHE_SIZE_PROPERTY

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

MTCTRANSFORM_PROPERTY

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

EMPTY_TILE_HANDLER_PROPERTY

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

ZOOM_LEVEL_INFO_PROPERTY

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

ZOOM_LEVEL_TILE_SIZE_PROPERTY

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

ROOT_DIR_PATH_PROPERTY

public static final java.lang.String ROOT_DIR_PATH_PROPERTY
Inserted into properties loaded via tiles.omp, so that the EmptyTileHandler can know where the tile set is located, in case it needs to know the absolute path. Will contain the root directory path specified in the factory properties, as opposed to any rootDir property set in the tiles.omp file that would specify a relative root directory path.

See Also:
Constant Field Values

TILE_PROPERTIES

public static final java.lang.String TILE_PROPERTIES
The name of the properties file that the factory looks for in the root directory of the data (tiles.omp).

See Also:
Constant Field Values

zoomLevelInfo

protected ZoomLevelInfo zoomLevelInfo

rootDir

protected java.lang.String rootDir

fileExt

protected java.lang.String fileExt

rootDirProperty

protected java.lang.String rootDirProperty

emptyTileHandler

protected EmptyTileHandler emptyTileHandler

verbose

protected boolean verbose

zoomLevelTileSize

protected int zoomLevelTileSize

repaintCallback

protected java.awt.Component repaintCallback
A component that is painting the tiles to the screen. If this component is set on this tile factory, it will be told to repaint the OMGraphicList it provides with the current contents. If you want the map to update as tiles are created by the factory, they will pop up on the map when they are ready.


mtcTransform

protected MapTileCoordinateTransform mtcTransform
Coordinate transform for the uv coordinates of the tiles. Different sources have different origins for tile coordinates.


lastProj

protected Projection lastProj

scales

protected float[] scales
An array of scales for all of the possible zoom levels, from 1 to 20. They get calculate the first time getZoomLevelForProj is called.

Constructor Detail

StandardMapTileFactory

public StandardMapTileFactory()

StandardMapTileFactory

public StandardMapTileFactory(java.awt.Component layer,
                              java.lang.String rootDir,
                              java.lang.String tileFileExt)
Method Detail

load

public CacheObject load(java.lang.Object key)
Description copied from class: CacheHandler
Called from get if the key doesn't exist, to "load" the new object into the cache before returning it. This function should define how a CacheObject is created, or loaded from the file system, or whatever.

Specified by:
load in class CacheHandler

reset

public void reset()
Tell the factory to clean up resources.

Specified by:
reset in interface MapTileFactory

load

public CacheObject load(java.lang.Object key,
                        int x,
                        int y,
                        int zoomLevel,
                        Projection proj)
Called to load cache object from data source, when not found in cache.

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

createOMGraphicFromBufferedImage

protected OMGraphic createOMGraphicFromBufferedImage(java.awt.image.BufferedImage bi,
                                                     int x,
                                                     int y,
                                                     int zoomLevel,
                                                     Projection proj)
                                              throws java.lang.InterruptedException
Creates an OMRaster appropriate for projection and other parameters from a buffered image.

Parameters:
bi - BufferedImage to use for tile.
x - x uv coordinate for tile.
y - y uv coordinate for tile.
zoomLevel - zoom level for tile.
proj - the current map projection
Returns:
OMGraphic (OMScalingRaster or OMWarpingImage, most likely)
Throws:
java.lang.InterruptedException

getTileMatchingProjectionType

protected OMGraphic getTileMatchingProjectionType(java.awt.image.BufferedImage image,
                                                  int x,
                                                  int y,
                                                  int zoomLevel)
Create an OMScalingRaster that matches the basic projection of the current map. Only scales evenly for the opposite corner points.

Parameters:
image - BufferedImage created from tile file
x - uv x coordinate
y - uv y coordinate
zoomLevel - zoom level for tile retrieval
Returns:
OMGraphic, but really an OMScalingRaster.

getTileNotMatchingProjectionType

protected OMGraphic getTileNotMatchingProjectionType(java.awt.image.BufferedImage image,
                                                     int x,
                                                     int y,
                                                     int zoomLevel)
Create an OMWarpingImage that knows how to re-project itself for different projections. The base projection is going to be defined for the mtc transform set on the factory. Warping images are slower to generate for a map projection than scaling rasters.

Parameters:
image -
x -
y -
zoomLevel -
Returns:
OMGraphic, but really an OMWarpingImage

preprocessImage

protected java.awt.image.BufferedImage preprocessImage(java.awt.Image origImage,
                                                       int imageWidth,
                                                       int imageHeight)
                                                throws java.lang.InterruptedException
Method that allows subclasses to modify the image as necessary before it is passed into an OMGraphic.

Parameters:
origImage - Any java Image
imageWidth - pixel width
imageHeight - pixel height
Returns:
BufferedImage with any changes necessary.
Throws:
java.lang.InterruptedException

get

public java.lang.Object get(java.lang.Object key,
                            int x,
                            int y,
                            int zoomLevel,
                            Projection proj)
The main 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, then load is called to get it from the data source.

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
proj - passed solely to enable checking if the projection of the tiles matches the rendered projection.
Returns:
object from cache.

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.

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.

getEmptyTile

public CacheObject getEmptyTile(java.lang.Object key,
                                int x,
                                int y,
                                int zoomLevel,
                                Projection proj)
Call to make when you want the tile factory to create some empty tile representation for the given location. You can return any type of OMGraphic embedded in a CacheObject.

Parameters:
key - the cache key for this object
x - the uv x coordinate of the tile
y - the uv y coordinate of the tile
zoomLevel - the zoom level for the tile
proj - the projection being used for the map.
Returns:
CacheObject, or null if the empty tile should be blank.

getTiles

public OMGraphicList getTiles(Projection proj)
Returns projected tiles for the given projection.

Specified by:
getTiles in interface MapTileFactory
Parameters:
proj - the projection to fetch tiles for.
Returns:
OMGraphicList containing projected OMGraphics.
Throws:
java.lang.InterruptedException

getTiles

public OMGraphicList getTiles(Projection proj,
                              int zoomLevel)
Returns projected tiles for given projection at specified zoom level.

Specified by:
getTiles in interface MapTileFactory
Parameters:
proj - projection for query
zoomLevel - zoom level 1-20 for tiles to be returned, -1 for code to figure out appropriate zoom level.
Returns:
OMGraphicList with tiles.
Throws:
java.lang.InterruptedException

getTiles

public OMGraphicList getTiles(Projection proj,
                              int zoomLevel,
                              OMGraphicList list)
Returns projected tiles for given projection at specified zoom level. Use this call if you are providing a repaint callback component to the factory, so you will have a handle on the OMGraphicList to render to.

Specified by:
getTiles in interface MapTileFactory
Parameters:
proj - projection for query
zoomLevel - zoom level 1-20 for tiles to be returned, -1 for code to figure out appropriate zoom level.
list - OMGraphicList that is returned, that will also have tiles added to it.
Returns:
OMGraphicList with tiles.
Throws:
java.lang.InterruptedException

getTiles

protected void getTiles(int uvleft,
                        int uvright,
                        int uvup,
                        int uvbottom,
                        ZoomLevelInfo zoomLevelInfo,
                        Projection proj,
                        OMGraphicList list)

getZoomLevelForProj

public int getZoomLevelForProj(Projection proj)
Given a projection, figure out the appropriate zoom level for it. Right now, 0 is totally zoomed with one tile for the entire earth. But we don't return 0, we start at 1. OM can't handle one tile that covers the entire earth because of the restriction for handling OMGraphics to less than half of the earth.

Parameters:
proj -
Returns:
the zoom level.

getRepaintCallback

public java.awt.Component getRepaintCallback()

setRepaintCallback

public void setRepaintCallback(java.awt.Component callback)
Description copied from interface: MapTileFactory
Set a component in the tile factory that should be told to repaint when new tiles become available. Using the callback assumes that you have called getTiles() with an OMGraphicList that will be rendered by the callback. Tiles added to the OMGraphicList should be generated with the projection passed in getTiles();

Specified by:
setRepaintCallback in interface MapTileFactory
Parameters:
callback - java.awt.Component to call repaint on.

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
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
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.

getPropertyPrefix

public java.lang.String getPropertyPrefix()
Description copied from interface: PropertyConsumer
Get the property key prefix that is being used to prepend to the property keys for Properties lookups.

Specified by:
getPropertyPrefix in interface PropertyConsumer
Returns:
the prefix string

setProperties

public void setProperties(java.util.Properties setList)
Description copied from interface: PropertyConsumer
Method to set the properties in the PropertyConsumer. It is assumed that the properties do not have a prefix associated with them, or that the prefix has already been set.

Specified by:
setProperties in interface PropertyConsumer
Parameters:
setList - a properties object that the PropertyConsumer can use to retrieve expected properties it can use for configuration.

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
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.

setPropertyPrefix

public void setPropertyPrefix(java.lang.String prefix)
Description copied from interface: PropertyConsumer
Set the property key prefix that should be used by the PropertyConsumer. The prefix, along with a '.', should be prepended to the property keys known by the PropertyConsumer.

Specified by:
setPropertyPrefix in interface PropertyConsumer
Parameters:
prefix - the prefix String.

getRootDir

public java.lang.String getRootDir()

setRootDir

public void setRootDir(java.lang.String rootDirectory)

configureFromProperties

protected void configureFromProperties(java.io.InputStream is,
                                       java.lang.String rootDirectory)
                                throws java.io.IOException
Called with an input stream for a properties file, used for reading tiles.omp files.

Parameters:
is - input stream for tiles.omp file.
rootDirectory - original path to what was specified as root directory
Throws:
java.io.IOException

getFileExt

public java.lang.String getFileExt()

setFileExt

public void setFileExt(java.lang.String fileExt)

getZoomLevelInfo

public ZoomLevelInfo getZoomLevelInfo()
Get the ZoomLevelInfo set on the factory. The ZoomLevelInfo has basic layout information about tiles for a particular zoom level, including how tiles are named and how the factory should go about loading them. The default ZoomLevelInfo is based on the OpenStreetMap tile layout, zoom levels 0-20 (where level 0 is all the way zoomed out), and the tiles are stored zoomLevel/x/y.(fileExt).

Returns:
the zoomLevelInfo

setZoomLevelInfo

public void setZoomLevelInfo(ZoomLevelInfo zoomLevelInfo)
Get the ZoomLevelInfo set on the factory. The ZoomLevelInfo has basic layout information about tiles for a particular zoom level, including how tiles are named and how the factory should go about loading them. The default ZoomLevelInfo is based on the OpenStreetMap tile layout, zoom levels 0-20 (where level 0 is all the way zoomed out), and the tiles are stored zoomLevel/x/y.(fileExt). You can set a different zoom level info if you want to work with a tile set that is stored/defined differently than OSM.

Won't allow itself to be set to null.

Parameters:
zoomLevelInfo - the zoomLevelInfo to set

getMtcTransform

public MapTileCoordinateTransform getMtcTransform()

setMtcTransform

public void setMtcTransform(MapTileCoordinateTransform mtcTransform)
Set the map tile coordinate transformed used to figure out lat/lon to tile coordinates. Can't be null, if you set it to null an OSMMapTileCoordTransform will be created instead.

Parameters:
mtcTransform -

getEmptyTileHandler

public EmptyTileHandler getEmptyTileHandler()
Returns:
the emptyTileHandler

setEmptyTileHandler

public void setEmptyTileHandler(EmptyTileHandler emptyTileHandler)
Parameters:
emptyTileHandler - the emptyTileHandler to set


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