de.fhpotsdam.unfolding.marker
Class AbstractShapeMarker

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

public abstract class AbstractShapeMarker
extends AbstractMarker

Abstract marker representing multiple locations and can be implemented as lines, polygons, or other shapes. Handles multiple locations, and implements the main marker methods for handling those properly.


Field Summary
protected  java.util.List<Location> locations
          All locations defining this shape.
 
Fields inherited from class de.fhpotsdam.unfolding.marker.AbstractMarker
color, hidden, highlightColor, highlightStrokeColor, id, location, properties, selected, strokeColor, strokeWeight
 
Constructor Summary
AbstractShapeMarker()
          Creates an empty shape marker with no locations.
AbstractShapeMarker(java.util.List<Location> locations)
          Creates a shape marker for the given locations.
AbstractShapeMarker(java.util.List<Location> locations, java.util.HashMap<java.lang.String,java.lang.Object> properties)
          Creates a shape marker for the given locations.
 
Method Summary
 void addLocation(float lat, float lon)
          Adds a Location to the list of locations.
 void addLocations(java.util.List<Location> locations)
          Adds all locations to the list of locations.
 void addLocations(Location... locations)
          Adds all locations to the list of locations.
 void draw(processing.core.PGraphics pg, float x, float y)
          Draws a visual representation of this marker.
abstract  void draw(processing.core.PGraphics pg, java.util.List<MapPosition> objectPositions)
          Draws these markers in outer object coordinate system.
protected  void draw(processing.core.PGraphics pg, java.util.List<MapPosition> mapPositions, java.util.HashMap<java.lang.String,java.lang.Object> properties, UnfoldingMap map)
           
 void draw(UnfoldingMap map)
          Draws this marker onto the map.
 Location getCentroid()
          Returns the geometric center of this shape.
 Location getLocation()
          Gets the geometric center location of this marker.
 Location getLocation(int index)
          Gets the location at the specified index.
 java.util.List<Location> getLocations()
          Gets all locations.
protected  boolean isInside(float checkX, float checkY, float x, float y)
          Checks whether given position is inside the marker.
protected  boolean isInside(float checkX, float checkY, java.util.List<? extends processing.core.PVector> vectors)
          Checks whether the position is within the border of the vectors.
 boolean isInside(UnfoldingMap map, float checkX, float checkY)
          Checks whether given position is inside this marker, according to the maps coordinate system.
 boolean isInsideByLocation(float latitude, float longitude)
          Checks whether given position is inside this marker, according to the shape defined by the marker's locations.
 boolean isInsideByLocation(Location location)
           
 void removeLocation(int index)
          Deletes a Location from the list of locations.
 void removeLocation(Location location)
          Deletes a Location from the list of locations.
 void setLocation(Location location)
          Adds the given location to the list of locations.
 void setLocations(java.util.List<Location> locations)
          Sets the list of locations.
 
Methods inherited from class de.fhpotsdam.unfolding.marker.AbstractMarker
draw, getDistanceTo, getId, getProperties, getProperty, getScreenPosition, getStringProperty, isHidden, isSelected, setColor, setHidden, setHighlightColor, setHighlightStrokeColor, setId, setLocation, setProperties, setSelected, setStrokeColor, setStrokeWeight
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locations

protected java.util.List<Location> locations
All locations defining this shape.

Constructor Detail

AbstractShapeMarker

public AbstractShapeMarker()
Creates an empty shape marker with no locations. Locations can be added dynamically after creation.


AbstractShapeMarker

public AbstractShapeMarker(java.util.List<Location> locations)
Creates a shape marker for the given locations.

Parameters:
locations - The list of locations.

AbstractShapeMarker

public AbstractShapeMarker(java.util.List<Location> locations,
                           java.util.HashMap<java.lang.String,java.lang.Object> properties)
Creates a shape marker for the given locations.

Parameters:
locations - The list of locations.
properties - Some data properties for this marker.
Method Detail

setLocations

public void setLocations(java.util.List<Location> locations)
Sets the list of locations.

Parameters:
locations - A list of Locations.

getLocations

public java.util.List<Location> getLocations()
Gets all locations.

Returns:
A list of Locations.

addLocations

public void addLocations(Location... locations)
Adds all locations to the list of locations.

Parameters:
locations - One or multiple Location.

addLocations

public void addLocations(java.util.List<Location> locations)
Adds all locations to the list of locations.

Parameters:
locations - A list of Locations.

addLocation

public void addLocation(float lat,
                        float lon)
Adds a Location to the list of locations.

Parameters:
lat - The latitude value.
lon - The longitude value.

getLocation

public Location getLocation(int index)
Gets the location at the specified index.

Parameters:
index - The index of the location.
Returns:
A Location.

removeLocation

public void removeLocation(Location location)
Deletes a Location from the list of locations.

Parameters:
location - The Location to remove.

removeLocation

public void removeLocation(int index)
Deletes a Location from the list of locations.

Parameters:
index - The index of the Location to remove.

setLocation

public void setLocation(Location location)
Adds the given location to the list of locations. NB: Does not set this as the only location! This implementation is just prevent mistakes by using this method as more general Marker method.

Specified by:
setLocation in interface Marker
Overrides:
setLocation in class AbstractMarker
Parameters:
location - The location to add.

getLocation

public Location getLocation()
Gets the geometric center location of this marker.

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

getCentroid

public Location getCentroid()
Returns the geometric center of this shape.

Returns:
The centroid location.

draw

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

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

draw

protected void draw(processing.core.PGraphics pg,
                    java.util.List<MapPosition> mapPositions,
                    java.util.HashMap<java.lang.String,java.lang.Object> properties,
                    UnfoldingMap map)

draw

public abstract void draw(processing.core.PGraphics pg,
                          java.util.List<MapPosition> objectPositions)
Draws these markers in outer object coordinate system. e.g. for labels oriented to the map

Parameters:
pg - The PGraphics to draw on
objectPositions - The positions in outer object coordinates.

draw

public void draw(processing.core.PGraphics pg,
                 float x,
                 float y)
Description copied from class: AbstractMarker
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.

Specified by:
draw in class AbstractMarker
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)
Description copied from class: AbstractMarker
Checks whether given position is inside this marker, according to the maps coordinate system. Uses internal implemented AbstractMarker.isInside(float, float, float, float) of the sub class.

Specified by:
isInside in interface Marker
Overrides:
isInside in class AbstractMarker
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.

isInside

protected boolean isInside(float checkX,
                           float checkY,
                           java.util.List<? extends processing.core.PVector> vectors)
Checks whether the position is within the border of the vectors. Uses a polygon containment algorithm. This method is used for both ScreenPosition as well as Location checks.

Parameters:
checkX - The x position to check if inside.
checkY - The y position to check if inside.
vectors - The vectors of the polygon
Returns:
True if inside, false otherwise.

isInsideByLocation

public boolean isInsideByLocation(float latitude,
                                  float longitude)
Checks whether given position is inside this marker, according to the shape defined by the marker's locations. Note: This is only in AbstractShapeMarker and not in AbstractMarker (nor Marker) as only shape markers have an area to test whether a point is inside. All others (Point and Lines) have no area, and thus an inside check always have to return false. (The screen-pos inside tests check whether a point is inside the visual representation, which has an area.)

Parameters:
longitude - The longitude.
latitude - The latitude.
Returns:
True if inside, false otherwise.

isInsideByLocation

public boolean isInsideByLocation(Location location)

isInside

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

Specified by:
isInside in class AbstractMarker
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.