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
containsPointif 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.StringcachedDefaultTemplateprivate static java.util.Map<GpxLayer,java.lang.String>cachedTemplatesprivate java.lang.StringcachedTextprivate CachedLatLoncoorprivate TemplateEngineDataProviderdataProviderprivate booleanerroneousstatic java.lang.StringLABEL_PATTERN_AUTOstatic java.lang.StringLABEL_PATTERN_DESCstatic java.lang.StringLABEL_PATTERN_NAMEprivate PreferenceChangedListenerlistenerstatic java.lang.StringMARKER_FORMATTED_OFFSETstatic java.lang.StringMARKER_OFFSETprivate static java.util.List<MarkerProducers>markerProducersPlugins 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).doubleoffsetTime offset in seconds from the gpx point from which it was derived, may be adjusted later to sync with other data, so not finalMarkerLayerparentLayerprivate java.awt.image.BufferedImageredSymbolprotected javax.swing.ImageIconsymbolprivate java.lang.StringtextdoubletimeAbsolute 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)privateMarker(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 voidactionPerformed(java.awt.event.ActionEvent ev)Called when the mouse is clicked in the marker's hotspot.static voidappendMarkerProducer(MarkerProducers mp)Add a new marker producers at the end of the JOSM list.booleancontainsPoint(java.awt.Point p)Checks whether the marker display area contains the given point.WayPointconvertToWayPoint()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.voiddestroy()Called when the object has been destroyed.booleanevaluateCondition(SearchCompiler.Match condition)Check if a condition holds for the object represented by thisTemplateEngineDataProvider.private java.lang.StringformatOffset()BBoxgetBBox()Fetches the bounding box of the primitive.LatLongetCoor()Returns the marker's coordinates.private java.lang.StringgetDefaultTextTemplate()private java.lang.StringgetPreferenceKey()java.util.Collection<java.lang.String>getTemplateKeys()Get the collection of all keys that can be mapped to values.java.lang.ObjectgetTemplateValue(java.lang.String name, boolean special)Map a key to a value given the properties of the object.java.lang.StringgetText()Returns the Text which should be displayed, depending on chosen preferenceprivate java.lang.StringgetTextTemplate()protected java.lang.StringgetTextTemplateKey()booleanisErroneous()Determines if this marker is erroneous.doublelat()Returns the latitude, i.e., the north-south position in degrees.doublelon()Returns the longitude, i.e., the east-west position in degrees.voidpaint(java.awt.Graphics2D g, MapView mv, boolean mousePressed, boolean showTextOrIcon)Paints the marker.protected voidpaintIcon(MapView mv, java.awt.Graphics g, int x, int y)static voidprependMarkerProducer(MarkerProducers mp)Add a new marker producers at the beginning of the JOSM list.voidsetCoor(LatLon coor)Sets the marker's coordinates.voidsetEastNorth(EastNorth eastNorth)Sets the marker's projected coordinates.voidsetErroneous(boolean erroneous)Sets this marker erroneous or not.voidupdateText()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 ornullfor no relative URLsparentLayer- theMarkerLayerthat will contain the createdMarkertime- 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:ILatLonReturns the longitude, i.e., the east-west position in degrees.- Specified by:
lonin interfaceILatLon- Returns:
- the longitude or NaN if
ILatLon.isLatLonKnown()returns false - Since:
- 12725
-
lat
public double lat()
Description copied from interface:ILatLonReturns the latitude, i.e., the north-south position in degrees.- Specified by:
latin 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:
trueif 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:TemplateEngineDataProviderGet the collection of all keys that can be mapped to values.- Specified by:
getTemplateKeysin 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:TemplateEngineDataProviderMap a key to a value given the properties of the object.- Specified by:
getTemplateValuein 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
specialis true
-
evaluateCondition
public boolean evaluateCondition(SearchCompiler.Match condition)
Description copied from interface:TemplateEngineDataProviderCheck if a condition holds for the object represented by thisTemplateEngineDataProvider.- Specified by:
evaluateConditionin 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:
trueif this markers has any kind of error,falseotherwise- Since:
- 6299
-
setErroneous
public final void setErroneous(boolean erroneous)
Sets this marker erroneous or not.- Parameters:
erroneous-trueif this markers has any kind of error,falseotherwise- Since:
- 6299
-
destroy
public void destroy()
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable
-
getPreferenceKey
private java.lang.String getPreferenceKey()
-
getBBox
public BBox getBBox()
Description copied from interface:IQuadBucketTypeFetches the bounding box of the primitive.- Specified by:
getBBoxin interfaceIQuadBucketType- Returns:
- Bounding box of the object
-
-