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 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
FieldsModifier and TypeFieldDescriptionprivate Stringprivate Stringprivate CachedLatLonprivate final TemplateEngineDataProviderprivate booleanstatic final Stringstatic final Stringstatic final Stringprivate PreferenceChangedListenerstatic final Stringstatic final Stringprivate static final List<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).doubleTime offset in seconds from the gpx point from which it was derived, may be adjusted later to sync with other data, so not finalfinal MarkerLayerprivate BufferedImageprotected final ImageIconprivate final StringdoubleAbsolute time of marker in seconds since epochFields inherited from interface org.openstreetmap.josm.data.coor.ILatLon
MAX_SERVER_PRECISION -
Constructor Summary
ConstructorsModifierConstructorDescriptionMarker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) privateMarker(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
Modifier and TypeMethodDescriptionvoidCalled when the mouse is clicked in the marker's hotspot.static voidAdd a new marker producers at the end of the JOSM list.booleanChecks whether the marker display area contains the given point.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.voiddestroy()Called when the object has been destroyed.booleanevaluateCondition(SearchCompiler.Match condition) Check if a condition holds for the object represented by thisTemplateEngineDataProvider.private StringgetBBox()Fetches the bounding box of the primitive.final LatLongetCoor()Returns the marker's coordinates.private Stringprivate StringGet the collection of all keys that can be mapped to values.getTemplateValue(String name, boolean special) Map a key to a value given the properties of the object.getText()Returns the Text which should be displayed, depending on chosen preferenceprivate Stringprotected Stringfinal booleanDetermines 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(Graphics2D g, MapView mv, boolean mousePressed, boolean showTextOrIcon) Paints the marker.protected voidstatic voidAdd a new marker producers at the beginning of the JOSM list.final voidSets the marker's coordinates.final voidsetEastNorth(EastNorth eastNorth) Sets the marker's projected coordinates.final voidsetErroneous(boolean erroneous) Sets this marker erroneous or not.voidCalled when the template changesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openstreetmap.josm.data.coor.ILatLon
bearing, distanceSq, distanceSq, equalsEpsilon, equalsEpsilon, getEastNorth, greatCircleDistance, interpolate, isLatLonKnown
-
Field Details
-
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
- See Also:
-
MARKER_FORMATTED_OFFSET
- See Also:
-
LABEL_PATTERN_AUTO
- See Also:
-
LABEL_PATTERN_NAME
- See Also:
-
LABEL_PATTERN_DESC
- See Also:
-
dataProvider
-
text
-
symbol
-
redSymbol
-
parentLayer
-
time
Absolute time of marker in seconds since epoch -
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
-
cachedTemplates
-
cachedDefaultTemplate
-
coor
-
listener
-
erroneous
-
-
Constructor Details
-
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 Details
-
appendMarkerProducer
Add a new marker producers at the end of the JOSM list.- Parameters:
mp- a new marker producers- Since:
- 11850
-
prependMarkerProducer
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 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
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
Sets the marker's coordinates.- Parameters:
coor- The marker's coordinates (lat/lon)
-
getCoor
Returns the marker's coordinates.- Returns:
- The marker's coordinates (lat/lon)
-
setEastNorth
Sets the marker's projected coordinates.- Parameters:
eastNorth- The marker's projected coordinates (easting/northing)
-
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
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
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
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
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
-
paintIcon
-
getTextTemplateKey
-
getTextTemplate
-
getDefaultTextTemplate
-
getText
Returns the Text which should be displayed, depending on chosen preference- Returns:
- Text of the label
-
updateText
Called when the template changes -
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
-
getTemplateValue
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
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
Determines if this marker is erroneous.- Returns:
trueif this markers has any kind of error,falseotherwise- Since:
- 6299
-
setErroneous
Sets this marker erroneous or not.- Parameters:
erroneous-trueif this markers has any kind of error,falseotherwise- Since:
- 6299
-
destroy
Description copied from interface:DestroyableCalled when the object has been destroyed.- Specified by:
destroyin interfaceDestroyable
-
getPreferenceKey
-
getBBox
Description copied from interface:IQuadBucketTypeFetches the bounding box of the primitive.- Specified by:
getBBoxin interfaceIQuadBucketType- Returns:
- Bounding box of the object
-