de.fhpotsdam.unfolding.marker
Class AbstractMarker

java.lang.Object
  extended by de.fhpotsdam.unfolding.marker.AbstractMarker
All Implemented Interfaces:
Marker
Direct Known Subclasses:
AbstractShapeMarker, SimplePointMarker

public abstract class AbstractMarker
extends java.lang.Object
implements Marker

Abstract marker handling conversion of location to appropriate coordinate system, and handles basic marker functionality. All default marker of Unfolding implement this. Your own class can extend this AbstractMarker or implement the Marker interface, directly.


Field Summary
protected  int color
           
protected  boolean hidden
          Indicates whether this marker is hidden.
protected  int highlightColor
           
protected  int highlightStrokeColor
           
protected  java.lang.String id
          The ID of this marker.
protected  Location location
          The location of this marker.
protected  java.util.HashMap<java.lang.String,java.lang.Object> properties
          Optional data properties.
protected  boolean selected
          Indicates whether this marker is selected.
protected  int strokeColor
           
protected  int strokeWeight
           
 
Constructor Summary
AbstractMarker()
           
AbstractMarker(Location location)
           
AbstractMarker(Location location, java.util.HashMap<java.lang.String,java.lang.Object> props)
           
 
Method Summary
abstract  void draw(processing.core.PGraphics pg, float x, float y)
          Draws a visual representation of this marker.
protected  void draw(processing.core.PGraphics pg, float x, float y, UnfoldingMap map)
          Draws a visual representation of this marker.
 void draw(UnfoldingMap map)
          Draws this marker onto the map.
 double getDistanceTo(Location location)
          Calculate distance between this marker and the given location.
 java.lang.String getId()
          Gets the marker ID.
 Location getLocation()
          Gets the location of this marker.
 java.util.HashMap<java.lang.String,java.lang.Object> getProperties()
          Gets the optional properties of this marker.
 java.lang.Object getProperty(java.lang.String key)
          Gets the property for given key.
 ScreenPosition getScreenPosition(UnfoldingMap map)
           
 java.lang.String getStringProperty(java.lang.String key)
          Gets the property as String for given key.
 boolean isHidden()
          Indicates whether this marker is hidden.
protected abstract  boolean isInside(float checkX, float checkY, float x, float y)
          Checks whether given position is inside the marker.
 boolean isInside(UnfoldingMap map, float checkX, float checkY)
          Checks whether given position is inside this marker, according to the maps coordinate system.
 boolean isSelected()
          Indicates whether this marker is selected.
 void setColor(int color)
          Sets the main color of this marker.
 void setHidden(boolean hidden)
          Sets the visibility status of this marker.
 void setHighlightColor(int highlightColor)
           
 void setHighlightStrokeColor(int highlightStrokeColor)
           
 void setId(java.lang.String id)
          Sets the marker ID.
 void setLocation(float lat, float lon)
          Set the location for this marker.
 void setLocation(Location location)
          Set the location for this marker.
 void setProperties(java.util.HashMap<java.lang.String,java.lang.Object> props)
          Sets the optional properties of this marker.
 void setSelected(boolean selected)
          Changes the select status of this marker.
 void setStrokeColor(int color)
          Sets the color of the border.
 void setStrokeWeight(int strokeWeight)
          Sets the thickness of the border of this marker.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

color

protected int color

strokeColor

protected int strokeColor

strokeWeight

protected int strokeWeight

highlightColor

protected int highlightColor

highlightStrokeColor

protected int highlightStrokeColor

location

protected Location location
The location of this marker.


properties

protected java.util.HashMap<java.lang.String,java.lang.Object> properties
Optional data properties.


selected

protected boolean selected
Indicates whether this marker is selected.


hidden

protected boolean hidden
Indicates whether this marker is hidden.


id

protected java.lang.String id
The ID of this marker.

Constructor Detail

AbstractMarker

public AbstractMarker()

AbstractMarker

public AbstractMarker(Location location)

AbstractMarker

public AbstractMarker(Location location,
                      java.util.HashMap<java.lang.String,java.lang.Object> props)
Method Detail

getId

public java.lang.String getId()
Description copied from interface: Marker
Gets the marker ID.

Specified by:
getId in interface Marker
Returns:
An ID.

setId

public void setId(java.lang.String id)
Description copied from interface: Marker
Sets the marker ID.

Specified by:
setId in interface Marker
Parameters:
id - The ID.

setProperties

public void setProperties(java.util.HashMap<java.lang.String,java.lang.Object> props)
Description copied from interface: Marker
Sets the optional properties of this marker.

Specified by:
setProperties in interface Marker
Parameters:
props - The properties to set. The map consist of key,value pairs for each property.

getProperties

public java.util.HashMap<java.lang.String,java.lang.Object> getProperties()
Description copied from interface: Marker
Gets the optional properties of this marker. The map consist of key,value pairs for each property.

Specified by:
getProperties in interface Marker
Returns:
A map of properties.

getProperty

public java.lang.Object getProperty(java.lang.String key)
Description copied from interface: Marker
Gets the property for given key.

Specified by:
getProperty in interface Marker
Parameters:
key - The key of the property.
Returns:
The property, if found.

getStringProperty

public java.lang.String getStringProperty(java.lang.String key)
Description copied from interface: Marker
Gets the property as String for given key.

Specified by:
getStringProperty in interface Marker
Parameters:
key - The key of the property.
Returns:
The property, if found.

draw

public void draw(UnfoldingMap map)
Draws this marker onto the map. Converts the geo-location to object position, and calls draw(PGraphics, float, float, UnfoldingMap).

Specified by:
draw in interface Marker
Parameters:
map - The map to draw on.

draw

protected void draw(processing.core.PGraphics pg,
                    float x,
                    float y,
                    UnfoldingMap map)
Draws a visual representation of this marker. The given x,y coordinates are already converted into the local coordinate system, so no need for further conversion. That is, a position of (0, 0) is the origin of this marker. Subclasses may override this method to draw a marker depending on map properties.

Parameters:
pg - The PGraphics to draw on.
x - The x position in object coordinates.
y - The y position in object coordinates.
map - The map to draw on. Can be used to draw a marker which depends on other properties of the map.

draw

public abstract void draw(processing.core.PGraphics pg,
                          float x,
                          float y)
Draws a visual representation of this marker. The given x,y coordinates are already converted into the local coordinate system, so no need for further conversion. That is, a position of (0, 0) is the origin of this marker. Subclasses must override this method to draw a marker.

Parameters:
pg - The PGraphics to draw on
x - The x position in outer object coordinates.
y - The y position in outer object coordinates.

isInside

public boolean isInside(UnfoldingMap map,
                        float checkX,
                        float checkY)
Checks whether given position is inside this marker, according to the maps coordinate system. Uses internal implemented isInside(float, float, float, float) of the sub class.

Specified by:
isInside in interface Marker
Parameters:
map - The map to draw on.
checkX - The x position to check in screen coordinates.
checkY - The y position to check in screen coordinates.
Returns:
true if inside, false otherwise.

getScreenPosition

public ScreenPosition getScreenPosition(UnfoldingMap map)

getLocation

public Location getLocation()
Description copied from interface: Marker
Gets the location of this marker. For point marker this returns the single location, for shape markers it should return a meaningful location, e.g. the centroid.

Specified by:
getLocation in interface Marker
Returns:
The location with lat, lng.

setLocation

public void setLocation(Location location)
Description copied from interface: Marker
Set the location for this marker.

Specified by:
setLocation in interface Marker
Parameters:
location - Location with lat, lng

setLocation

public void setLocation(float lat,
                        float lon)
Description copied from interface: Marker
Set the location for this marker.

Specified by:
setLocation in interface Marker
Parameters:
lat - latitude
lon - longitude

getDistanceTo

public double getDistanceTo(Location location)
Description copied from interface: Marker
Calculate distance between this marker and the given location.

Specified by:
getDistanceTo in interface Marker
Parameters:
location - The location to calculate the distance to.
Returns:
Distance to location in kilometers (km).

isInside

protected abstract boolean isInside(float checkX,
                                    float checkY,
                                    float x,
                                    float y)
Checks whether given position is inside the marker. TODO Keep isInside(cx, cy, x, y) also for AbstractShapeMarker?

Parameters:
checkX - The x position to check in screen coordinates.
checkY - The y position to check in screen coordinates.
x - The x position of this marker in screen coordinates.
y - The y position of this marker in screen coordinates.
Returns:
true if inside, false otherwise.

setSelected

public void setSelected(boolean selected)
Description copied from interface: Marker
Changes the select status of this marker. Sub-classes can use the selection status to highlight this marker.

Specified by:
setSelected in interface Marker
Parameters:
selected - Whether this marker is selected or not.

isSelected

public boolean isSelected()
Description copied from interface: Marker
Indicates whether this marker is selected. Can be used for drawing the marker differently, e.g. to highlight it.

Specified by:
isSelected in interface Marker
Returns:
true if it is selected, false otherwise.

setHidden

public void setHidden(boolean hidden)
Description copied from interface: Marker
Sets the visibility status of this marker.

Specified by:
setHidden in interface Marker
Parameters:
hidden - The new status

isHidden

public boolean isHidden()
Description copied from interface: Marker
Indicates whether this marker is hidden. Can be used for drawing the marker differently.

Specified by:
isHidden in interface Marker
Returns:
true if it is hidden, false otherwise.

setColor

public void setColor(int color)
Description copied from interface: Marker
Sets the main color of this marker.

Specified by:
setColor in interface Marker
Parameters:
color - The color (in Processing's color type)

setStrokeWeight

public void setStrokeWeight(int strokeWeight)
Description copied from interface: Marker
Sets the thickness of the border of this marker.

Specified by:
setStrokeWeight in interface Marker
Parameters:
strokeWeight - Thickness in pixel.

setHighlightColor

public void setHighlightColor(int highlightColor)

setHighlightStrokeColor

public void setHighlightStrokeColor(int highlightStrokeColor)

setStrokeColor

public void setStrokeColor(int color)
Description copied from interface: Marker
Sets the color of the border.

Specified by:
setStrokeColor in interface Marker
Parameters:
color - The color (in Processing's color type)