Class Marker
- java.lang.Object
-
- org.openstreetmap.josm.gui.layer.markerlayer.Marker
-
- All Implemented Interfaces:
ILatLon
,Destroyable
,TemplateEngineDataProvider
- Direct Known Subclasses:
ButtonMarker
,PlayHeadMarker
public class Marker extends Object implements TemplateEngineDataProvider, ILatLon, Destroyable
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 String
cachedDefaultTemplate
private static Map<GpxLayer,String>
cachedTemplates
private String
cachedText
private CachedLatLon
coor
private TemplateEngineDataProvider
dataProvider
private boolean
erroneous
static String
LABEL_PATTERN_AUTO
static String
LABEL_PATTERN_DESC
static String
LABEL_PATTERN_NAME
private PreferenceChangedListener
listener
static String
MARKER_FORMATTED_OFFSET
static String
MARKER_OFFSET
private static 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 BufferedImage
redSymbol
protected ImageIcon
symbol
private String
text
double
time
Absolute time of marker in seconds since epoch
-
Constructor Summary
Constructors Modifier Constructor Description Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset)
private
Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String text, String iconName, MarkerLayer parentLayer, double time, double offset)
Marker(LatLon ll, TemplateEngineDataProvider dataProvider, 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(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(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 Collection<Marker>
createMarkers(WayPoint wpt, 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 String
formatOffset()
LatLon
getCoor()
Returns the marker's coordinates.private String
getDefaultTextTemplate()
private String
getPreferenceKey()
Collection<String>
getTemplateKeys()
Get the collection of all keys that can be mapped to values.Object
getTemplateValue(String name, boolean special)
Map a key to a value given the properties of the object.String
getText()
Returns the Text which should be displayed, depending on chosen preferenceprivate String
getTextTemplate()
protected 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(Graphics2D g, MapView mv, boolean mousePressed, boolean showTextOrIcon)
Paints the marker.protected void
paintIcon(MapView mv, 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
getEastNorth, isLatLonKnown
-
-
-
-
Field Detail
-
markerProducers
private static final 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 String MARKER_OFFSET
- See Also:
- Constant Field Values
-
MARKER_FORMATTED_OFFSET
public static final String MARKER_FORMATTED_OFFSET
- See Also:
- Constant Field Values
-
LABEL_PATTERN_AUTO
public static final String LABEL_PATTERN_AUTO
- See Also:
- Constant Field Values
-
LABEL_PATTERN_NAME
public static final String LABEL_PATTERN_NAME
- See Also:
- Constant Field Values
-
LABEL_PATTERN_DESC
public static final String LABEL_PATTERN_DESC
- See Also:
- Constant Field Values
-
dataProvider
private final TemplateEngineDataProvider dataProvider
-
redSymbol
private 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 String cachedText
-
cachedTemplates
private static Map<GpxLayer,String> cachedTemplates
-
cachedDefaultTemplate
private String cachedDefaultTemplate
-
coor
private CachedLatLon coor
-
listener
private PreferenceChangedListener listener
-
erroneous
private boolean erroneous
-
-
Constructor Detail
-
Marker
public Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String iconName, MarkerLayer parentLayer, double time, double offset)
-
Marker
public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset)
-
Marker
private Marker(LatLon ll, TemplateEngineDataProvider dataProvider, String text, 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 Collection<Marker> createMarkers(WayPoint wpt, 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(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(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(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 String getTextTemplateKey()
-
getTextTemplate
private String getTextTemplate()
-
getDefaultTextTemplate
private String getDefaultTextTemplate()
-
getText
public 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 Collection<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 String formatOffset()
-
getTemplateValue
public Object getTemplateValue(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 String getPreferenceKey()
-
-