com.bbn.openmap.dataAccess.mapTile
Class WholeWorldTileHandler

java.lang.Object
  extended by com.bbn.openmap.dataAccess.mapTile.SimpleEmptyTileHandler
      extended by com.bbn.openmap.dataAccess.mapTile.ShpFileEmptyTileHandler
          extended by com.bbn.openmap.dataAccess.mapTile.WholeWorldTileHandler
All Implemented Interfaces:
EmptyTileHandler, PropertyConsumer

public class WholeWorldTileHandler
extends ShpFileEmptyTileHandler

The WholeWorldTileHandler is a special EmptyTileHandler that manages a special set of jar files containing tiles that cover the entire earth. If you put all of the tiles from zoom levels 0-12 into a jar file, you end up with a 5Gb jar, and java doesn't handle it. Having zoom levels 0-14 on disk takes up 30Gb without being compressed.

This class, run as an application, organizes tiles into several jar files, depending on their zoom level and location. All tiles for the world in zoom levels 0-10 are placed in a single jar file. For all other zoom levels, they are placed together geographically, based on the tile boundaries of some higher level (zoom level 3 is the default, higher numbers might be chosen if tiles are created for higher zoom levels than 15).

This class is consulted when the MapTileFactory can't find a map tile. Since this class is an EmptyTileHandler, it is given free reign to return a tile for the missing one. Instead of assuming that the tiles don't exist and a quick replacement needs to be created, this EmtpyTileHandler assumes that the proper jar file hasn't been loaded yet, which is why the tile wasn't found as a resource. It uses the ux, uv, and zoom level for the tile to figure out what jar it would have been in, and checks to see if that jar has been added to the classpath. If the jar has been added, then the tile doesn't exist. If the jar needs to be added, it is and then the tile retrieval starts.

The properties for the tile set are a little different when using this EmptyTileHandler:

 # specify this empty tile handler
 emptyTileHandler=com.bbn.openmap.dataAccess.mapTile.WholeWorldTileHandler
 # instead of the root directory to the jars, specify the root directory of the tiles 
 # inside the jars.  All of the jars within a set should share the root directory name 
 # within them.  Each set of jars should have a unique root directory name for that dataset.
 rootDir=main_tiles
 # The name of the jar containing world-level coverage.  All of the sub-jars should be 
 # named based on this jar name.  If this class is run to build the tile jars, 
 # it should have done this automatically.
 parentJarName=main_tiles.jar
 # This is the grid that defines how the subjars are divided.  It matches the tile boundaries 
 # of a certain zoom level. Level 3 is the default.
 subJarZoomLevel=9
 # This is the highest level of tiles held in the part jar name.  Tells the layer when it should
 # start looking in subjars for tiles at higher zoom levels.
 worldWideZoomLevel=10
 # Tells the layer when to stop trying to fill tile orders.
 noCoverageZoom=15
 # optional, png is default.
 fileExt=.png
 # You can also specify how empty tiles are handled, using the ShpFileEmptyTileHandler.
 shpFile=/Users/dietrick/dev/openmap/share/data/shape/cntry02/cntry02.shp
 land.fillColor=DECD8B
 background.fillColor=EAFFF4
 mapTileTransform=com.bbn.openmap.dataAccess.mapTile.OSMMapTileCoordinateTransform
 land.lineColor=DECD8B
 background.lineColor=EAFFF4
 
 
NOTE: If you create a set of tile jars to use with a Windows jre, and you're having problems when the jars are added to the classpath, it's because there are too many tiles in the jars. The number for files in this case can't exceed 262144. So you have to increase the zoom level used for the layout of the subjar files.

Author:
ddietrick

Nested Class Summary
static class WholeWorldTileHandler.Builder
          The builder class takes a map tile directory and creates a set of jars from it, divided so that the WholeWorldTileHandler can deal with it.
 
Field Summary
static int DEFAULT_SUBJAR_DEF_ZOOMLEVEL
           
static int DEFAULT_WORLDWIDE_ZOOMLEVEL
           
protected  java.util.Set<java.lang.String> loadedJars
           
static java.lang.String PARENT_JAR_NAME_PROPERTY
           
protected  java.lang.String parentJarName
           
protected  java.lang.String rootDirForJars
           
protected  int subFrameDefZoomLevel
           
static java.lang.String SUBJAR_ZOOMLEVEL_PROPERTY
           
static int WIN_MAX_FILES_IN_JAR
          Turns out that the Windows JRE won't add jar files with more than 262144 tiles in them.
static java.lang.String WORLDWIDE_ZOOMLEVEL_PROPERTY
           
protected  int worldWideZoomLevel
           
 
Fields inherited from class com.bbn.openmap.dataAccess.mapTile.ShpFileEmptyTileHandler
LAND_ATTRIBUTES_PROPERTY, landAttributes, shapeStuff, SHP_FILE_PROPERTY
 
Fields inherited from class com.bbn.openmap.dataAccess.mapTile.SimpleEmptyTileHandler
BACKGROUND_PROPERTY, backgroundAtts, backgroundTileImage, emptyTileImage, logger, NO_COVERAGE_PROPERTY, NO_COVERAGE_ZOOM_PROPERTY, noCoverageAtts, noCoverageZoom, prefix, TILE_SIZE
 
Fields inherited from interface com.bbn.openmap.PropertyConsumer
EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty
 
Constructor Summary
WholeWorldTileHandler()
           
 
Method Summary
static java.lang.String buildSubJarName(java.lang.String parentJarNme, double x, double y)
           
 byte[] getImageBytes(java.lang.String imagePath)
          Tries to get the image bytes from imagePath URL.
 java.awt.image.BufferedImage getImageForEmptyTile(java.lang.String imagePath, int x, int y, int zoomLevel, MapTileCoordinateTransform mtcTransform, Projection proj)
          The main call from the MapTileFactory to return something for the given missing tile.
 java.lang.String getParentJarName()
          Get the name of the jar with worldwide coverage, for zoom levels 0-worldWideZoomLevel.
 java.util.Properties getProperties(java.util.Properties props)
          Method to fill in a Properties object, reflecting the current values of the PropertyConsumer.
 int getSubFrameDefZoomLevel()
          Get the tile zoom level that the subjar borders are based on.
 int getWorldWideZoomLevel()
          Get the maximum tile zoom level that is contained in the worldwide jar.
protected  boolean loadJar(java.lang.String jarFileName)
          Load the jar if necessary.
static void main(java.lang.String[] args)
          Takes arguments for source tile directory, target directory, and option sub-jar zoom level, and creates jars in the right place with expected tiles.
 void setParentJarName(java.lang.String parentJarName)
          Set the name of the jar with worldwide coverage, for tiles with zoom levels 0-worldWideZoomLevel.
 void setProperties(java.lang.String prefix, java.util.Properties props)
          Method to set the properties in the PropertyConsumer.
 void setSubFrameDefZoomLevel(int subFrameZoomLevel)
          Set the tile zoom level that the subjar borders will be based on.
 void setWorldWideZoomLevel(int worldWideZoomLevel)
          Set the maximum tile zoom level that is contained in the worldwide jar.
 
Methods inherited from class com.bbn.openmap.dataAccess.mapTile.ShpFileEmptyTileHandler
getLandAttributes, getShapeStuff, setLandAttributes, setShapeStuff
 
Methods inherited from class com.bbn.openmap.dataAccess.mapTile.SimpleEmptyTileHandler
createTileImageFromDrawingAttributes, getBackgroundAtts, getNoCoverageAtts, getNoCoverageZoom, getPropertyInfo, getPropertyPrefix, setBackgroundAtts, setNoCoverageAtts, setNoCoverageZoom, setProperties, setPropertyPrefix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUBJAR_ZOOMLEVEL_PROPERTY

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

WORLDWIDE_ZOOMLEVEL_PROPERTY

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

PARENT_JAR_NAME_PROPERTY

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

DEFAULT_SUBJAR_DEF_ZOOMLEVEL

public static final int DEFAULT_SUBJAR_DEF_ZOOMLEVEL
See Also:
Constant Field Values

DEFAULT_WORLDWIDE_ZOOMLEVEL

public static final int DEFAULT_WORLDWIDE_ZOOMLEVEL
See Also:
Constant Field Values

subFrameDefZoomLevel

protected int subFrameDefZoomLevel

worldWideZoomLevel

protected int worldWideZoomLevel

parentJarName

protected java.lang.String parentJarName

loadedJars

protected java.util.Set<java.lang.String> loadedJars

rootDirForJars

protected java.lang.String rootDirForJars

WIN_MAX_FILES_IN_JAR

public static final int WIN_MAX_FILES_IN_JAR
Turns out that the Windows JRE won't add jar files with more than 262144 tiles in them.

See Also:
Constant Field Values
Constructor Detail

WholeWorldTileHandler

public WholeWorldTileHandler()
Method Detail

getImageForEmptyTile

public java.awt.image.BufferedImage getImageForEmptyTile(java.lang.String imagePath,
                                                         int x,
                                                         int y,
                                                         int zoomLevel,
                                                         MapTileCoordinateTransform mtcTransform,
                                                         Projection proj)
Description copied from interface: EmptyTileHandler
The main call from the MapTileFactory to return something for the given missing tile.

Specified by:
getImageForEmptyTile in interface EmptyTileHandler
Overrides:
getImageForEmptyTile in class ShpFileEmptyTileHandler
Parameters:
imagePath - the path of the missing tile that is going to be used as cache lookup later.
x - the uv x coordinate of the tile.
y - the uv y coordinate of the tile.
zoomLevel - the zoom level of the tile.
mtcTransform - the transform that converts x,y coordinates to lat/lon and describes the layout of the uv tile coordinates.
proj - the map projection, in case that matters what should be returned for the empty tile.
Returns:
BufferedImage for image tile

buildSubJarName

public static java.lang.String buildSubJarName(java.lang.String parentJarNme,
                                               double x,
                                               double y)

getImageBytes

public byte[] getImageBytes(java.lang.String imagePath)
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.
Returns:
byte[] of image

loadJar

protected boolean loadJar(java.lang.String jarFileName)
Load the jar if necessary. Not called anymore, but left here as a note on how to dynamically modify the classpath to add a jar at runtime.

Parameters:
jarFileName - the absolute path to the jar.
Returns:
true if the jar was loaded, false if it was added before and no attempt made.

setProperties

public void setProperties(java.lang.String prefix,
                          java.util.Properties props)
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 ShpFileEmptyTileHandler
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.
props - a Properties object that the PropertyConsumer can use to retrieve expected properties it can use for configuration.

getProperties

public java.util.Properties getProperties(java.util.Properties props)
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 ShpFileEmptyTileHandler
Parameters:
props - 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.

getSubFrameDefZoomLevel

public int getSubFrameDefZoomLevel()
Get the tile zoom level that the subjar borders are based on.

Returns:
the subFrameDefZoomLevel

setSubFrameDefZoomLevel

public void setSubFrameDefZoomLevel(int subFrameZoomLevel)
Set the tile zoom level that the subjar borders will be based on.

Parameters:
subFrameZoomLevel - the subFrameDefZoomLevel to set

getParentJarName

public java.lang.String getParentJarName()
Get the name of the jar with worldwide coverage, for zoom levels 0-worldWideZoomLevel.

Returns:
the parentJarName

setParentJarName

public void setParentJarName(java.lang.String parentJarName)
Set the name of the jar with worldwide coverage, for tiles with zoom levels 0-worldWideZoomLevel.

Parameters:
parentJarName - the parentJarName to set

getWorldWideZoomLevel

public int getWorldWideZoomLevel()
Get the maximum tile zoom level that is contained in the worldwide jar.

Returns:
the worldWideZoomLevel

setWorldWideZoomLevel

public void setWorldWideZoomLevel(int worldWideZoomLevel)
Set the maximum tile zoom level that is contained in the worldwide jar.

Parameters:
worldWideZoomLevel - the worldWideZoomLevel to set

main

public static void main(java.lang.String[] args)
Takes arguments for source tile directory, target directory, and option sub-jar zoom level, and creates jars in the right place with expected tiles. Prints usage statement.

Parameters:
args -


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