de.fhpotsdam.unfolding.mapdisplay
Class AbstractMapDisplay

java.lang.Object
  extended by de.fhpotsdam.unfolding.mapdisplay.AbstractMapDisplay
All Implemented Interfaces:
TileLoaderListener
Direct Known Subclasses:
Java2DMapDisplay

public abstract class AbstractMapDisplay
extends java.lang.Object
implements TileLoaderListener

Handles tiles management and display, and map location and screen position conversions. Use UnfoldingMap in your application. This is the internal class, and should be used only if you know what you are doing.


Nested Class Summary
 class AbstractMapDisplay.QueueSorter
           
 class AbstractMapDisplay.ZoomComparator
           
 
Field Summary
protected  boolean allTilesLoaded
          Check whether all currently visible tiles have been loaded.
 float angle
          Rotation of this MapDisplay.
 int grid_padding
           
protected  float height
           
protected  java.util.Hashtable<Coordinate,java.lang.Object> images
           
 float innerAngle
           
 double innerOffsetX
           
 double innerOffsetY
           
 float innerScale
           
protected  processing.core.PVector innerTransformationCenter
           
static org.apache.log4j.Logger log
           
protected  java.util.List<MarkerManager<Marker>> markerManagerList
           
 int max_images_to_keep
           
 int max_pending
           
 float offsetX
          Vertical offset of this MapDisplay (in screen coordinates).
 float offsetY
          Horizontal offset of this MapDisplay (in screen coordinates).
protected  java.util.Hashtable<Coordinate,java.lang.Runnable> pending
           
protected  AbstractMapProvider provider
           
protected  java.util.Vector<Coordinate> queue
           
protected  AbstractMapDisplay.QueueSorter queueSorter
           
protected  java.util.Vector<java.lang.Object> recent_images
           
 float scale
          Scale of this MapDisplay.
static int TILE_HEIGHT
           
static int TILE_WIDTH
           
protected  processing.core.PVector transformationCenter
          Center of outer transformations in screen pixel.
protected  float width
           
protected  AbstractMapDisplay.ZoomComparator zoomComparator
           
 
Constructor Summary
protected AbstractMapDisplay(AbstractMapProvider provider, float width, float height)
           
 
Method Summary
 void addMarker(Marker marker)
          Adds a marker to the default marker manager.
 void addMarkerManager(MarkerManager<Marker> markerManager)
          You need to set the map of the given MarkerManager before using.
 void addMarkers(java.util.List<Marker> markers)
          Adds multiple markers to the default marker manager.
 boolean allTilesLoaded()
          Check whether all currently visible tiles have been loaded.
abstract  void calculateInnerMatrix()
           
abstract  void calculateMatrix()
          Updates the matrix to transform the map with with the current transformation center.
protected  void cleanupImageBuffer()
          Cleans oldest images if too many images exist, or if memory is too full.
protected  void cleanupImageBuffer(boolean force)
           
protected  void createDefaultMarkerManager(UnfoldingMap map)
           
protected abstract  TileLoader createTileLoader(Coordinate coord)
           
abstract  void draw()
           
 MarkerManager<Marker> getDefaultMarkerManager()
           
 float getHeight()
           
abstract  float[] getInnerObject(ScreenPosition screenPosition)
           
abstract  float[] getInnerObjectFromLocation(Location location)
           
abstract  float[] getInnerObjectFromObjectPosition(float x, float y)
           
abstract  float[] getInnerObjectFromScreenPosition(float x, float y)
          Deprecated. 
abstract  processing.core.PGraphics getInnerPG()
           
 processing.core.PVector getInnerTransformationCenter()
           
 MarkerManager<Marker> getLastMarkerManager()
           
abstract  Location getLocation(float x, float y)
           
abstract  Location getLocation(ScreenPosition screenPosition)
           
abstract  Location getLocationFromInnerObjectPosition(float x, float y)
           
abstract  Location getLocationFromObjectPosition(float x, float y)
           
abstract  Location getLocationFromScreenPosition(float x, float y)
          Deprecated. 
 AbstractMapProvider getMapProvider()
           
 MarkerManager<Marker> getMarkerManager()
          Deprecated. 
 MarkerManager<Marker> getMarkerManager(int index)
           
 java.util.List<MarkerManager<Marker>> getMarkerManagerList()
           
 processing.core.PGraphics getMask()
           
abstract  float[] getObjectFromInnerObjectPosition(float x, float y)
           
abstract  float[] getObjectFromLocation(Location location)
           
abstract  float[] getObjectFromScreenPosition(float x, float y)
           
abstract  processing.core.PGraphics getOuterPG()
           
abstract  float[] getScreenFromInnerObjectPosition(float x, float y)
           
abstract  float[] getScreenFromObjectPosition(float x, float y)
           
abstract  ScreenPosition getScreenPosition(Location location)
           
abstract  float[] getScreenPositionFromLocation(Location location)
          Deprecated. 
 processing.core.PVector getTransformationCenter()
           
protected abstract  float[] getTransformedPosition(float x, float y, boolean inverse)
          Calculates offset and rotation for screen canvas position, to be used with the internal transformation matrix.
 float getWidth()
           
 void grabTile(Coordinate coord)
           
 void processQueue()
           
 void removeMarkerManager(int i)
           
 void removeMarkerManager(MarkerManager<Marker> markerManager)
           
 void resize(float width, float height)
           
abstract  void setBackgroundColor(java.lang.Integer color)
          Sets background color of map.
 void setInnerTransformationCenter(processing.core.PVector innerTransformationCenter)
          Set inner transformation center.
 void setMapProvider(AbstractMapProvider provider)
           
 void setProvider(AbstractMapProvider provider)
          Set the map provider, dynamically.
 void setTransformationCenter(processing.core.PVector transformationCenter)
          Set outer transformation center.
 void tileLoaded(Coordinate coord, java.lang.Object image)
           
abstract  void tilesLoaded()
          Will be called if all tiles have been loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TILE_WIDTH

public static final int TILE_WIDTH
See Also:
Constant Field Values

TILE_HEIGHT

public static final int TILE_HEIGHT
See Also:
Constant Field Values

log

public static org.apache.log4j.Logger log

width

protected float width

height

protected float height

innerOffsetX

public double innerOffsetX

innerOffsetY

public double innerOffsetY

innerScale

public float innerScale

innerAngle

public float innerAngle

offsetX

public float offsetX
Vertical offset of this MapDisplay (in screen coordinates).


offsetY

public float offsetY
Horizontal offset of this MapDisplay (in screen coordinates).


angle

public float angle
Rotation of this MapDisplay.


scale

public float scale
Scale of this MapDisplay. Not used yet!


transformationCenter

protected processing.core.PVector transformationCenter
Center of outer transformations in screen pixel.


innerTransformationCenter

protected processing.core.PVector innerTransformationCenter

markerManagerList

protected java.util.List<MarkerManager<Marker>> markerManagerList

max_pending

public int max_pending

max_images_to_keep

public int max_images_to_keep

grid_padding

public int grid_padding

allTilesLoaded

protected boolean allTilesLoaded
Check whether all currently visible tiles have been loaded.


provider

protected AbstractMapProvider provider

pending

protected java.util.Hashtable<Coordinate,java.lang.Runnable> pending

images

protected java.util.Hashtable<Coordinate,java.lang.Object> images

queue

protected java.util.Vector<Coordinate> queue

recent_images

protected java.util.Vector<java.lang.Object> recent_images

zoomComparator

protected AbstractMapDisplay.ZoomComparator zoomComparator

queueSorter

protected AbstractMapDisplay.QueueSorter queueSorter
Constructor Detail

AbstractMapDisplay

protected AbstractMapDisplay(AbstractMapProvider provider,
                             float width,
                             float height)
Method Detail

resize

public void resize(float width,
                   float height)

getMapProvider

public AbstractMapProvider getMapProvider()

setMapProvider

public void setMapProvider(AbstractMapProvider provider)

getInnerPG

public abstract processing.core.PGraphics getInnerPG()

getOuterPG

public abstract processing.core.PGraphics getOuterPG()

getMask

public processing.core.PGraphics getMask()

draw

public abstract void draw()

setBackgroundColor

public abstract void setBackgroundColor(java.lang.Integer color)
Sets background color of map.

Parameters:
color - Color for the background canvas. Can be semi-transparent. If null it is not used.

addMarkerManager

public void addMarkerManager(MarkerManager<Marker> markerManager)
You need to set the map of the given MarkerManager before using.


getLastMarkerManager

public MarkerManager<Marker> getLastMarkerManager()

getDefaultMarkerManager

public MarkerManager<Marker> getDefaultMarkerManager()

getMarkerManager

@Deprecated
public MarkerManager<Marker> getMarkerManager()
Deprecated. 


getMarkerManager

public MarkerManager<Marker> getMarkerManager(int index)

addMarker

public void addMarker(Marker marker)
Adds a marker to the default marker manager. If you have more than one marker manager, use MarkerManager.addMarker(Marker) instead.

Parameters:
marker - The marker to add.

addMarkers

public void addMarkers(java.util.List<Marker> markers)
Adds multiple markers to the default marker manager. If you have more than one marker manager, use MarkerManager.addMarkers(List) instead.

Parameters:
markers - The markers to add.

getWidth

public float getWidth()

getHeight

public float getHeight()

calculateMatrix

public abstract void calculateMatrix()
Updates the matrix to transform the map with with the current transformation center.


calculateInnerMatrix

public abstract void calculateInnerMatrix()

getTransformedPosition

protected abstract float[] getTransformedPosition(float x,
                                                  float y,
                                                  boolean inverse)
Calculates offset and rotation for screen canvas position, to be used with the internal transformation matrix.

Parameters:
x - Cartesian x coordinate.
y - Cartesian y coordinate.
inverse - Indicates back and forward matrix calculation. Inverse is used for point2location, non-inverse for location2point.
Returns:
An 1d-2elements-array with x and y.

getObjectFromInnerObjectPosition

public abstract float[] getObjectFromInnerObjectPosition(float x,
                                                         float y)

getInnerObjectFromObjectPosition

public abstract float[] getInnerObjectFromObjectPosition(float x,
                                                         float y)

getScreenFromInnerObjectPosition

public abstract float[] getScreenFromInnerObjectPosition(float x,
                                                         float y)

getInnerObjectFromScreenPosition

@Deprecated
public abstract float[] getInnerObjectFromScreenPosition(float x,
                                                                    float y)
Deprecated. 


getInnerObject

public abstract float[] getInnerObject(ScreenPosition screenPosition)

getScreenFromObjectPosition

public abstract float[] getScreenFromObjectPosition(float x,
                                                    float y)

getObjectFromScreenPosition

public abstract float[] getObjectFromScreenPosition(float x,
                                                    float y)

getLocationFromInnerObjectPosition

public abstract Location getLocationFromInnerObjectPosition(float x,
                                                            float y)

getLocationFromScreenPosition

@Deprecated
public abstract Location getLocationFromScreenPosition(float x,
                                                                  float y)
Deprecated. 


getLocation

public abstract Location getLocation(float x,
                                     float y)

getLocation

public abstract Location getLocation(ScreenPosition screenPosition)

getLocationFromObjectPosition

public abstract Location getLocationFromObjectPosition(float x,
                                                       float y)

getInnerObjectFromLocation

public abstract float[] getInnerObjectFromLocation(Location location)

getScreenPositionFromLocation

@Deprecated
public abstract float[] getScreenPositionFromLocation(Location location)
Deprecated. 


getScreenPosition

public abstract ScreenPosition getScreenPosition(Location location)

getObjectFromLocation

public abstract float[] getObjectFromLocation(Location location)

getTransformationCenter

public processing.core.PVector getTransformationCenter()

getInnerTransformationCenter

public processing.core.PVector getInnerTransformationCenter()

setTransformationCenter

public void setTransformationCenter(processing.core.PVector transformationCenter)
Set outer transformation center.

Parameters:
transformationCenter - Point in screen coordinates.

setInnerTransformationCenter

public void setInnerTransformationCenter(processing.core.PVector innerTransformationCenter)
Set inner transformation center.

Parameters:
innerTransformationCenter - Point in screen coordinates.

processQueue

public void processQueue()

createTileLoader

protected abstract TileLoader createTileLoader(Coordinate coord)

grabTile

public void grabTile(Coordinate coord)

tileLoaded

public void tileLoaded(Coordinate coord,
                       java.lang.Object image)
Specified by:
tileLoaded in interface TileLoaderListener

allTilesLoaded

public boolean allTilesLoaded()
Check whether all currently visible tiles have been loaded.

Returns:
True if all tiles have been loaded, false otherwise.

tilesLoaded

public abstract void tilesLoaded()
Will be called if all tiles have been loaded. Subclasses can implement this method to notify a method in the client app.


cleanupImageBuffer

protected void cleanupImageBuffer()
Cleans oldest images if too many images exist, or if memory is too full. Tiles are added to the recency-based list to allow removing oldest ones from images-array. REVISIT Check java.lang.ref.SoftReference for better solution.


cleanupImageBuffer

protected void cleanupImageBuffer(boolean force)

setProvider

public void setProvider(AbstractMapProvider provider)
Set the map provider, dynamically. The currently selected area, as well as all events etc will stay. Note that the image buffer will be cleaned, i.e. all tiles need to be loaded anew.

Parameters:
provider - The provider to use.

createDefaultMarkerManager

protected void createDefaultMarkerManager(UnfoldingMap map)

getMarkerManagerList

public java.util.List<MarkerManager<Marker>> getMarkerManagerList()

removeMarkerManager

public void removeMarkerManager(MarkerManager<Marker> markerManager)

removeMarkerManager

public void removeMarkerManager(int i)