Class Marker
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.markerlayer.Marker
-
- All Implemented Interfaces:
ILatLon
,IQuadBucketType
,Destroyable
,TemplateEngineDataProvider
- Direct Known Subclasses:
ButtonMarker
,PlayHeadMarker
public class Marker extends java.lang.Object implements TemplateEngineDataProvider, ILatLon, Destroyable, IQuadBucketType
Basic marker class. Requires a position, and supports a custom icon and a name. This class is also used to create appropriate Marker-type objects when waypoints are imported. It hosts a public list object, named makers, containing implementations of the MarkerMaker interface. Whenever a Marker needs to be created, each object in makers is called with the waypoint parameters (Lat/Lon and tag data), and the first one to return a Marker object wins. By default, one the list contains one default "Maker" implementation that will create AudioMarkers for supported audio files, ImageMarkers for supported image files, and WebMarkers for everything else. (The creation of a WebMarker will fail if there's no valid URL in the <link> tag, so it might still make sense to add Makers for such waypoints at the end of the list.) The default implementation only looks at the value of the <link> tag inside the <wpt> tag of the GPX file.HowTo implement a new Marker
- Subclass Marker or ButtonMarker and override
containsPoint
if you like to respond to user clicks - Override paint, if you want a custom marker look (not "a label and a symbol")
- Implement MarkerCreator to return a new instance of your marker class
- In you plugin constructor, add an instance of your MarkerCreator implementation either on top or bottom of Marker.markerProducers. Add at top, if your marker should overwrite an current marker or at bottom if you only add a new marker style.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
cachedDefaultTemplate
private static java.util.Map<GpxLayer,java.lang.String>
cachedTemplates
private java.lang.String
cachedText
private CachedLatLon
coor
private TemplateEngineDataProvider
dataProvider
private boolean
erroneous
static java.lang.String
LABEL_PATTERN_AUTO
static java.lang.String
LABEL_PATTERN_DESC
static java.lang.String
LABEL_PATTERN_NAME
private PreferenceChangedListener
listener
static java.lang.String
MARKER_FORMATTED_OFFSET
static java.lang.String
MARKER_OFFSET
private static java.util.List<MarkerProducers>
markerProducers
Plugins can add their Marker creation stuff at the bottom or top of this list (depending on whether they want to override default behaviour or just add new stuff).double
offset
Time offset in seconds from the gpx point from which it was derived, may be adjusted later to sync with other data, so not finalMarkerLayer
parentLayer
private java.awt.image.BufferedImage
redSymbol
protected javax.swing.ImageIcon
symbol
private java.lang.String
text
double
time
Absolute time of marker in seconds since epoch-
Fields inherited from interface org.openstreetmap.josm.data.coor.ILatLon
MAX_SERVER_PRECISION
-
-
Constructor Summary
Constructors Modifier Constructor Description Marker(LatLon ll, java.lang.String text, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
private
Marker(LatLon ll, TemplateEngineDataProvider dataProvider, java.lang.String text, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
Marker(LatLon ll, TemplateEngineDataProvider dataProvider, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent ev)
Called when the mouse is clicked in the marker's hotspot.static void
appendMarkerProducer(MarkerProducers mp)
Add a new marker producers at the end of the JOSM list.boolean
containsPoint(java.awt.Point p)
Checks whether the marker display area contains the given point.WayPoint
convertToWayPoint()
Convert Marker to WayPoint so it can be exported to a GPX file.static java.util.Collection<Marker>
createMarkers(WayPoint wpt, java.io.File relativePath, MarkerLayer parentLayer, double time, double offset)
Returns an object of class Marker or one of its subclasses created from the parameters given.void
destroy()
Called when the object has been destroyed.boolean
evaluateCondition(SearchCompiler.Match condition)
Check if a condition holds for the object represented by thisTemplateEngineDataProvider
.private java.lang.String
formatOffset()
BBox
getBBox()
Fetches the bounding box of the primitive.LatLon
getCoor()
Returns the marker's coordinates.private java.lang.String
getDefaultTextTemplate()
private java.lang.String
getPreferenceKey()
java.util.Collection<java.lang.String>
getTemplateKeys()
Get the collection of all keys that can be mapped to values.java.lang.Object
getTemplateValue(java.lang.String name, boolean special)
Map a key to a value given the properties of the object.java.lang.String
getText()
Returns the Text which should be displayed, depending on chosen preferenceprivate java.lang.String
getTextTemplate()
protected java.lang.String
getTextTemplateKey()
boolean
isErroneous()
Determines if this marker is erroneous.double
lat()
Returns the latitude, i.e., the north-south position in degrees.double
lon()
Returns the longitude, i.e., the east-west position in degrees.void
paint(java.awt.Graphics2D g, MapView mv, boolean mousePressed, boolean showTextOrIcon)
Paints the marker.protected void
paintIcon(MapView mv, java.awt.Graphics g, int x, int y)
static void
prependMarkerProducer(MarkerProducers mp)
Add a new marker producers at the beginning of the JOSM list.void
setCoor(LatLon coor)
Sets the marker's coordinates.void
setEastNorth(EastNorth eastNorth)
Sets the marker's projected coordinates.void
setErroneous(boolean erroneous)
Sets this marker erroneous or not.void
updateText()
Called when the template changes-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.data.coor.ILatLon
bearing, distanceSq, distanceSq, equalsEpsilon, equalsEpsilon, getEastNorth, greatCircleDistance, interpolate, isLatLonKnown
-
-
-
-
Field Detail
-
markerProducers
private static final java.util.List<MarkerProducers> markerProducers
Plugins can add their Marker creation stuff at the bottom or top of this list (depending on whether they want to override default behaviour or just add new stuff).
-
MARKER_OFFSET
public static final java.lang.String MARKER_OFFSET
- See Also:
- Constant Field Values
-
MARKER_FORMATTED_OFFSET
public static final java.lang.String MARKER_FORMATTED_OFFSET
- See Also:
- Constant Field Values
-
LABEL_PATTERN_AUTO
public static final java.lang.String LABEL_PATTERN_AUTO
- See Also:
- Constant Field Values
-
LABEL_PATTERN_NAME
public static final java.lang.String LABEL_PATTERN_NAME
- See Also:
- Constant Field Values
-
LABEL_PATTERN_DESC
public static final java.lang.String LABEL_PATTERN_DESC
- See Also:
- Constant Field Values
-
dataProvider
private final TemplateEngineDataProvider dataProvider
-
text
private final java.lang.String text
-
symbol
protected final javax.swing.ImageIcon symbol
-
redSymbol
private java.awt.image.BufferedImage redSymbol
-
parentLayer
public final MarkerLayer parentLayer
-
time
public double time
Absolute time of marker in seconds since epoch
-
offset
public double offset
Time offset in seconds from the gpx point from which it was derived, may be adjusted later to sync with other data, so not final
-
cachedText
private java.lang.String cachedText
-
cachedTemplates
private static java.util.Map<GpxLayer,java.lang.String> cachedTemplates
-
cachedDefaultTemplate
private java.lang.String cachedDefaultTemplate
-
coor
private CachedLatLon coor
-
listener
private PreferenceChangedListener listener
-
erroneous
private boolean erroneous
-
-
Constructor Detail
-
Marker
public Marker(LatLon ll, TemplateEngineDataProvider dataProvider, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
-
Marker
public Marker(LatLon ll, java.lang.String text, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
-
Marker
private Marker(LatLon ll, TemplateEngineDataProvider dataProvider, java.lang.String text, java.lang.String iconName, MarkerLayer parentLayer, double time, double offset)
-
-
Method Detail
-
appendMarkerProducer
public static void appendMarkerProducer(MarkerProducers mp)
Add a new marker producers at the end of the JOSM list.- Parameters:
mp
- a new marker producers- Since:
- 11850
-
prependMarkerProducer
public static void prependMarkerProducer(MarkerProducers mp)
Add a new marker producers at the beginning of the JOSM list.- Parameters:
mp
- a new marker producers- Since:
- 11850
-
createMarkers
public static java.util.Collection<Marker> createMarkers(WayPoint wpt, java.io.File relativePath, MarkerLayer parentLayer, double time, double offset)
Returns an object of class Marker or one of its subclasses created from the parameters given.- Parameters:
wpt
- waypoint data for markerrelativePath
- An path to use for constructing relative URLs ornull
for no relative URLsparentLayer
- theMarkerLayer
that will contain the createdMarker
time
- time of the marker in seconds since epochoffset
- double in seconds as the time offset of this marker from the GPX file from which it was derived (if any).- Returns:
- a new Marker object
-
convertToWayPoint
public WayPoint convertToWayPoint()
Convert Marker to WayPoint so it can be exported to a GPX file. Override in subclasses to add all necessary attributes.- Returns:
- the corresponding WayPoint with all relevant attributes
-
setCoor
public final void setCoor(LatLon coor)
Sets the marker's coordinates.- Parameters:
coor
- The marker's coordinates (lat/lon)
-
getCoor
public final LatLon getCoor()
Returns the marker's coordinates.- Returns:
- The marker's coordinates (lat/lon)
-
setEastNorth
public final void setEastNorth(EastNorth eastNorth)
Sets the marker's projected coordinates.- Parameters:
eastNorth
- The marker's projected coordinates (easting/northing)
-
lon
public double lon()
Description copied from interface:ILatLon
Returns the longitude, i.e., the east-west position in degrees.- Specified by:
lon
in interfaceILatLon
- Returns:
- the longitude or NaN if
ILatLon.isLatLonKnown()
returns false - Since:
- 12725
-
lat
public double lat()
Description copied from interface:ILatLon
Returns the latitude, i.e., the north-south position in degrees.- Specified by:
lat
in interfaceILatLon
- Returns:
- the latitude or NaN if
ILatLon.isLatLonKnown()
returns false - Since:
- 12725
-
containsPoint
public boolean containsPoint(java.awt.Point p)
Checks whether the marker display area contains the given point. Markers not interested in mouse clicks may always return false.- Parameters:
p
- The point to check- Returns:
true
if the marker "hotspot" contains the point.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent ev)
Called when the mouse is clicked in the marker's hotspot. Never called for markers which always return false from containsPoint.- Parameters:
ev
- A dummy ActionEvent
-
paint
public void paint(java.awt.Graphics2D g, MapView mv, boolean mousePressed, boolean showTextOrIcon)
Paints the marker.- Parameters:
g
- graphics contextmv
- map viewmousePressed
- true if the left mouse button is pressedshowTextOrIcon
- true if text and icon shall be drawn
-
getTextTemplateKey
protected java.lang.String getTextTemplateKey()
-
getTextTemplate
private java.lang.String getTextTemplate()
-
getDefaultTextTemplate
private java.lang.String getDefaultTextTemplate()
-
getText
public java.lang.String getText()
Returns the Text which should be displayed, depending on chosen preference- Returns:
- Text of the label
-
updateText
public void updateText()
Called when the template changes
-
getTemplateKeys
public java.util.Collection<java.lang.String> getTemplateKeys()
Description copied from interface:TemplateEngineDataProvider
Get the collection of all keys that can be mapped to values.- Specified by:
getTemplateKeys
in interfaceTemplateEngineDataProvider
- Returns:
- all keys that can be mapped to values
-
formatOffset
private java.lang.String formatOffset()
-
getTemplateValue
public java.lang.Object getTemplateValue(java.lang.String name, boolean special)
Description copied from interface:TemplateEngineDataProvider
Map a key to a value given the properties of the object.- Specified by:
getTemplateValue
in interfaceTemplateEngineDataProvider
- Parameters:
name
- the key to mapspecial
- if the key is a "special:*" keyword that is used to get certain information or automated behavior- Returns:
- a value that the key is mapped to or "special" information in case
special
is true
-
evaluateCondition
public boolean evaluateCondition(SearchCompiler.Match condition)
Description copied from interface:TemplateEngineDataProvider
Check if a condition holds for the object represented by thisTemplateEngineDataProvider
.- Specified by:
evaluateCondition
in interfaceTemplateEngineDataProvider
- Parameters:
condition
- the condition to check (which is a search expression)- Returns:
- true if the condition holds
-
isErroneous
public final boolean isErroneous()
Determines if this marker is erroneous.- Returns:
true
if this markers has any kind of error,false
otherwise- Since:
- 6299
-
setErroneous
public final void setErroneous(boolean erroneous)
Sets this marker erroneous or not.- Parameters:
erroneous
-true
if this markers has any kind of error,false
otherwise- Since:
- 6299
-
destroy
public void destroy()
Description copied from interface:Destroyable
Called when the object has been destroyed.- Specified by:
destroy
in interfaceDestroyable
-
getPreferenceKey
private java.lang.String getPreferenceKey()
-
getBBox
public BBox getBBox()
Description copied from interface:IQuadBucketType
Fetches the bounding box of the primitive.- Specified by:
getBBox
in interfaceIQuadBucketType
- Returns:
- Bounding box of the object
-
-