Package 

Class Marker

  • All Implemented Interfaces:
    org.osmdroid.views.util.constants.OverlayConstants

    
    public class Marker
    extends OverlayWithIW
                        

    A marker is an icon placed at a particular point on the map's surface that can have a popup-org.osmdroid.views.overlay.infowindow.InfoWindow (a bubble) Mimics the Marker class from Google Maps Android API v2 as much as possible. Main differences:

    - Doesn't support Z-Index: as other osmdroid overlays, Marker is drawn in the order of appearance. - The icon can be any standard Android Drawable, instead of the BitmapDescriptor introduced in Google Maps API v2. - The icon can be changed at any time. - The InfoWindow hosts a standard Android View. It can handle Android widgets like buttons and so on. - Supports a "sub-description", to be displayed in the InfoWindow, under the snippet, in a smaller text font. - Supports an image, to be displayed in the InfoWindow. - Supports "panning to view" on/off option (when touching a marker, center the map on marker position). - Opening a Marker InfoWindow automatically close others only if it's the same InfoWindow shared between Markers. - Events listeners are set per marker, not per map.

    • Method Summary

      Modifier and Type Method Description
      void setIcon(Drawable icon) Sets the icon for the marker.
      void setDefaultIcon()
      void setTextIcon(String pText)
      Drawable getIcon()
      GeoPoint getPosition()
      void setPosition(GeoPoint position) sets the location on the planet where the icon is rendered
      float getRotation()
      void setRotation(float rotation) rotates the icon in relation to the map
      void setAnchor(float anchorU, float anchorV)
      void setInfoWindowAnchor(float anchorU, float anchorV)
      void setAlpha(float alpha)
      float getAlpha()
      void setDraggable(boolean draggable)
      boolean isDraggable()
      void setFlat(boolean flat)
      boolean isFlat()
      void remove(MapView mapView) Removes this Marker from the MapView.Note that this method will operate only if the Marker is in the MapView overlays(it should not be included in a container like a FolderOverlay).
      void setOnMarkerClickListener(Marker.OnMarkerClickListener listener)
      void setOnMarkerDragListener(Marker.OnMarkerDragListener listener)
      void setImage(Drawable image) set an image to be shown in the InfoWindow - this is not the marker icon
      Drawable getImage() get the image to be shown in the InfoWindow - this is not the marker icon
      void setDragOffset(float mmUp) set the offset in millimeters that the marker is moved up while dragging
      float getDragOffset() get the offset in millimeters that the marker is moved up while dragging
      void setInfoWindow(MarkerInfoWindow infoWindow) Set the InfoWindow to be used.Default is a MarkerInfoWindow, with the layout named "bonuspack_bubble".You can use this method either to use your own layout, or to use your own sub-class of InfoWindow.Note that this InfoWindow will receive the Marker object as an input, so it MUST be able to handle Marker attributes.If you don't want any InfoWindow to open, you can set it to null.
      void setPanToView(boolean panToView) If set to true, when clicking the marker, the map will be centered on the marker position.Default is true.
      void showInfoWindow() shows the info window, if it's open, this will close and reopen it
      boolean isInfoWindowShown()
      void draw(Canvas canvas, Projection pj)
      void onDetach(MapView mapView) Null out the static references when the MapView is detached to prevent memory leaks.
      static void cleanDefaults() Prevent memory leaks and call this when you're done with the mapreference https://github.
      boolean hitTest(MotionEvent event, MapView mapView)
      boolean onSingleTapConfirmed(MotionEvent event, MapView mapView) By default does nothing ({@code return false}).
      void moveToEventPosition(MotionEvent event, MapView mapView)
      boolean onLongPress(MotionEvent event, MapView mapView) By default does nothing ({@code return false}).
      boolean onTouchEvent(MotionEvent event, MapView mapView) You can prevent all(!) other Touch-related events from happening!
      void setVisible(boolean visible)
      int getTextLabelBackgroundColor() used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      void setTextLabelBackgroundColor(int mTextLabelBackgroundColor) used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      int getTextLabelForegroundColor() used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      void setTextLabelForegroundColor(int mTextLabelForegroundColor) used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      int getTextLabelFontSize() used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      void setTextLabelFontSize(int mTextLabelFontSize) used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label
      boolean isDisplayed()
      • Methods inherited from class org.osmdroid.views.overlay.OverlayWithIW

        closeInfoWindow, getId, getInfoWindow, getRelatedObject, getSnippet, getSubDescription, getTitle, isInfoWindowOpen, onDestroy, setId, setInfoWindow, setRelatedObject, setSnippet, setSubDescription, setTitle
      • Methods inherited from class org.osmdroid.views.overlay.Overlay

        draw, draw, getBounds, isEnabled, onDetach, onDoubleTap, onDoubleTapEvent, onDown, onFling, onKeyDown, onKeyUp, onLongPress, onPause, onResume, onScroll, onShowPress, onSingleTapConfirmed, onSingleTapUp, onTrackballEvent, setEnabled
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setIcon

         void setIcon(Drawable icon)

        Sets the icon for the marker. Can be changed at any time.This is used on the map view.The anchor will be left unchanged; you may need to call setAnchor Two exceptions:- for text icons, the anchor is set to (center, center)- for the default icon, the anchor is set to the corresponding position (the tip of the teardrop)Related methods: setTextIcon, setDefaultIcon and setAnchor

        Parameters:
        icon - if null, the default osmdroid marker is used.
      • setPosition

         void setPosition(GeoPoint position)

        sets the location on the planet where the icon is rendered

      • setRotation

         void setRotation(float rotation)

        rotates the icon in relation to the map

      • setAnchor

         void setAnchor(float anchorU, float anchorV)
        Parameters:
        anchorU - WIDTH 0.0-1.
        anchorV - HEIGHT 0.0-1.
      • setFlat

         void setFlat(boolean flat)
      • remove

         void remove(MapView mapView)

        Removes this Marker from the MapView.Note that this method will operate only if the Marker is in the MapView overlays(it should not be included in a container like a FolderOverlay).

      • setImage

         void setImage(Drawable image)

        set an image to be shown in the InfoWindow - this is not the marker icon

      • getImage

         Drawable getImage()

        get the image to be shown in the InfoWindow - this is not the marker icon

      • setDragOffset

         void setDragOffset(float mmUp)

        set the offset in millimeters that the marker is moved up while dragging

      • getDragOffset

         float getDragOffset()

        get the offset in millimeters that the marker is moved up while dragging

      • setInfoWindow

         void setInfoWindow(MarkerInfoWindow infoWindow)

        Set the InfoWindow to be used.Default is a MarkerInfoWindow, with the layout named "bonuspack_bubble".You can use this method either to use your own layout, or to use your own sub-class of InfoWindow.Note that this InfoWindow will receive the Marker object as an input, so it MUST be able to handle Marker attributes.If you don't want any InfoWindow to open, you can set it to null.

      • setPanToView

         void setPanToView(boolean panToView)

        If set to true, when clicking the marker, the map will be centered on the marker position.Default is true.

      • showInfoWindow

         void showInfoWindow()

        shows the info window, if it's open, this will close and reopen it

      • onDetach

         void onDetach(MapView mapView)

        Null out the static references when the MapView is detached to prevent memory leaks.

      • cleanDefaults

        @Deprecated() static void cleanDefaults()

        Prevent memory leaks and call this when you're done with the mapreference https://github.com/MKergall/osmbonuspack/pull/210

      • onSingleTapConfirmed

         boolean onSingleTapConfirmed(MotionEvent event, MapView mapView)

        By default does nothing ({@code return false}). If you handled the Event, return {@code true} , otherwise return {@code false}. If you returned {@code true} none of the following Overlaysor the underlying MapView has the chance to handle this event.

      • onLongPress

         boolean onLongPress(MotionEvent event, MapView mapView)

        By default does nothing ({@code return false}). If you handled the Event, return {@code true} , otherwise return {@code false}. If you returned {@code true} none of the following Overlaysor the underlying MapView has the chance to handle this event.

      • onTouchEvent

         boolean onTouchEvent(MotionEvent event, MapView mapView)

        You can prevent all(!) other Touch-related events from happening!By default does nothing ({@code return false}). If you handled the Event, return {@code true} , otherwise return {@code false}. If you returned {@code true} none of the following Overlaysor the underlying MapView has the chance to handle this event.

      • getTextLabelBackgroundColor

         int getTextLabelBackgroundColor()

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label

      • setTextLabelBackgroundColor

         void setTextLabelBackgroundColor(int mTextLabelBackgroundColor)

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label

      • getTextLabelForegroundColor

         int getTextLabelForegroundColor()

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label

      • setTextLabelForegroundColor

         void setTextLabelForegroundColor(int mTextLabelForegroundColor)

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label

      • getTextLabelFontSize

         int getTextLabelFontSize()

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label

      • setTextLabelFontSize

         void setTextLabelFontSize(int mTextLabelFontSize)

        used for when the icon is explicitly set to null and the title is not, this willstyle the rendered text label