-
- All Implemented Interfaces:
-
org.osmdroid.views.overlay.IOverlayMenuProvider,org.osmdroid.views.overlay.compass.IOrientationConsumer,org.osmdroid.views.util.constants.OverlayConstants
public class CompassOverlay extends Overlay implements IOverlayMenuProvider, IOrientationConsumer
Note: the compass overlay causes issues on API 8 devices. See https://github.com/osmdroid/osmdroid/issues/218
Note: this class can cause issues if you're also relying on addOnFirstLayoutListener If you happen to be using both, see Issue 324
-
-
Field Summary
Fields Modifier and Type Field Description public IOrientationProvidermOrientationProviderpublic final static intMENU_COMPASS
-
Constructor Summary
Constructors Constructor Description CompassOverlay(Context context, MapView mapView)CompassOverlay(Context context, IOrientationProvider orientationProvider, MapView mapView)
-
Method Summary
Modifier and Type Method Description voidonPause()Triggered on application lifecycle changes, assuming the mapview is triggered appropriatelyrelated issue https://github.com/osmdroid/osmdroid/issues/823https://github. voidonResume()Triggered on application lifecycle changes, assuming the mapview is triggered appropriatelyrelated issue https://github.com/osmdroid/osmdroid/issues/823https://github. voidonDetach(MapView mapView)Override to perform clean up of resources before shutdown. voidsetLastRenderLag(int pLastRenderLag)voidsetAzimuthPrecision(float pAzimuthPrecision)voidsetCompassCenter(float x, float y)voidsetCompassInCenter(boolean b)Put the compass in the center of the map regardless of the supplied coordinates. booleanisCompassInCenter()voidsetAzimuthOffset(float f)An offset added to the bearing when drawing the compass.eg. floatgetAzimuthOffset()IOrientationProvidergetOrientationProvider()voidsetOrientationProvider(IOrientationProvider orientationProvider)voiddraw(Canvas c, Projection pProjection)voidsetOptionsMenuEnabled(boolean pOptionsMenuEnabled)booleanisOptionsMenuEnabled()Can be used to signal to external callers that this Overlay should not be used for providingoption menu items. booleanonCreateOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)booleanonPrepareOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)booleanonOptionsItemSelected(MenuItem pItem, int pMenuIdOffset, MapView pMapView)voidonOrientationChanged(float orientation, IOrientationProvider source)booleanenableCompass(IOrientationProvider orientationProvider)booleanenableCompass()Enable receiving orientation updates from the provided IOrientationProvider and show acompass on the map. voiddisableCompass()Disable orientation updates. booleanisCompassEnabled()If enabled, the map is receiving orientation updates and drawing your location on the map. floatgetOrientation()voidsetPointerMode(boolean usePointArrow)The compass can operate in two modes. booleanisPointerMode()-
Methods inherited from class org.osmdroid.views.overlay.Overlay
draw, draw, getBounds, isEnabled, onDetach, onDoubleTap, onDoubleTapEvent, onDown, onFling, onKeyDown, onKeyUp, onLongPress, onScroll, onShowPress, onSingleTapConfirmed, onSingleTapUp, onTouchEvent, onTrackballEvent, setEnabled -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
CompassOverlay
CompassOverlay(Context context, IOrientationProvider orientationProvider, MapView mapView)
-
-
Method Detail
-
onPause
void onPause()
Triggered on application lifecycle changes, assuming the mapview is triggered appropriatelyrelated issue https://github.com/osmdroid/osmdroid/issues/823https://github.com/osmdroid/osmdroid/issues/806
-
onResume
void onResume()
Triggered on application lifecycle changes, assuming the mapview is triggered appropriatelyrelated issue https://github.com/osmdroid/osmdroid/issues/823https://github.com/osmdroid/osmdroid/issues/806
-
onDetach
void onDetach(MapView mapView)
Override to perform clean up of resources before shutdown. By default does nothing.
-
setLastRenderLag
void setLastRenderLag(int pLastRenderLag)
-
setAzimuthPrecision
void setAzimuthPrecision(float pAzimuthPrecision)
-
setCompassCenter
void setCompassCenter(float x, float y)
-
setCompassInCenter
void setCompassInCenter(boolean b)
Put the compass in the center of the map regardless of the supplied coordinates.
-
isCompassInCenter
boolean isCompassInCenter()
-
setAzimuthOffset
void setAzimuthOffset(float f)
An offset added to the bearing when drawing the compass.eg. to account for local magnetic declination to indicate true north
-
getAzimuthOffset
float getAzimuthOffset()
-
getOrientationProvider
IOrientationProvider getOrientationProvider()
-
setOrientationProvider
void setOrientationProvider(IOrientationProvider orientationProvider)
-
draw
void draw(Canvas c, Projection pProjection)
-
setOptionsMenuEnabled
void setOptionsMenuEnabled(boolean pOptionsMenuEnabled)
-
isOptionsMenuEnabled
boolean isOptionsMenuEnabled()
Can be used to signal to external callers that this Overlay should not be used for providingoption menu items.
-
onCreateOptionsMenu
boolean onCreateOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)
-
onPrepareOptionsMenu
boolean onPrepareOptionsMenu(Menu pMenu, int pMenuIdOffset, MapView pMapView)
-
onOptionsItemSelected
boolean onOptionsItemSelected(MenuItem pItem, int pMenuIdOffset, MapView pMapView)
-
onOrientationChanged
void onOrientationChanged(float orientation, IOrientationProvider source)
- Parameters:
orientation- this is magnetic north, not true north
-
enableCompass
boolean enableCompass(IOrientationProvider orientationProvider)
-
enableCompass
boolean enableCompass()
Enable receiving orientation updates from the provided IOrientationProvider and show acompass on the map. You will likely want to call enableCompass() from your Activity'sActivity.onResume() method, to enable the features of this overlay. Remember to call thecorresponding disableCompass() in your Activity's Activity.onPause() method to turn offupdates when in the background.
-
disableCompass
void disableCompass()
Disable orientation updates.
Note the behavior has changed since v6.0.0. This method no longer releasesreferences to the orientation provider. Instead, that happens in the onDetachedmethod.
-
isCompassEnabled
boolean isCompassEnabled()
If enabled, the map is receiving orientation updates and drawing your location on the map.
-
getOrientation
float getOrientation()
-
setPointerMode
void setPointerMode(boolean usePointArrow)
The compass can operate in two modes.
- false - a conventional compass needle pointing north/south (false, default)
- true - a pointer arrow that indicates the device's real world orientation on the map (true)
- Parameters:
usePointArrow- if true the pointer arrow is used, otherwise a compass rose is used
-
isPointerMode
boolean isPointerMode()
-
-
-
-