Class 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.
    • 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<MarkercreateMarkers​(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 marker
        relativePath - An path to use for constructing relative URLs or null for no relative URLs
        parentLayer - the MarkerLayer that will contain the created Marker
        time - time of the marker in seconds since epoch
        offset - 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 interface ILatLon
        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 interface ILatLon
        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 context
        mv - map view
        mousePressed - true if the left mouse button is pressed
        showTextOrIcon - true if text and icon shall be drawn
      • paintIcon

        protected void paintIcon​(MapView mv,
                                 java.awt.Graphics g,
                                 int x,
                                 int y)
      • 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
      • 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 interface TemplateEngineDataProvider
        Parameters:
        name - the key to map
        special - 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
      • 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