Home

Awesome

Leaflet.Control.Compass

npm version

A leaflet control plugin to make simple rotating compass

If this project helped your work help me to keep this alive by Paypal DONATION ❤

Tested in Leaflet 0.7 and 1.2

require HTML5 API on mobile device!

Try the Demo online here:
opengeo.tech/maps/leaflet-compass

Tested platforms:

this project needs many tests on different devices, please help us using the demo page and report problems by opening an issue.

Image

Usage

Adding the Compass Control to the map:

map.addControl( new L.Control.Compass() );

Options

OptionDefaultDescription
autoActivefalseactivate control at startup
showDigitfalseshow angle value bottom compass
textErr''error message on alert notification
callErrnullfunction that run on compass error activating
angleOffset2min angle deviation before rotate, big angleOffset is need for device have noise in orientation sensor
position'topright'position of control inside map

Methods

MethodArgumentsDescription
autoActivefalseactivate control at startup
getAnglereturn Azimut angle
setAngleangleset rotation compass
activateactive tracking on runtime
deactivatedeactive tracking on runtime

Events

EventDataDescription
'compass:rotated'anglefired after compass data is rotated
'compass:disabled'fired when compass is disabled

Where

Source code:

Github
NPM