Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including leaflet-compass with all npm packages installed. Try it out:

leaflet-compass lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("leaflet-compass/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

leaflet-compass v1.5.2

A leaflet control plugin to make simple rotating compass


A leaflet control plugin to make simple rotating compass

Tested in Leaflet 0.7 and 1.2

require HTML5 API on mobile device!

Tested platforms:

  • Chrome on Android
  • Safari on iOS

Demo online:



Adding the Compass Control to the map:

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


autoActivefalseactivate control at startup
showDigittrueshow 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


  • getAngle return Azimut angle
  • setAngle set rotation compass
  • activate active tracking on runtime
  • deactivate deactive tracking on runtime


  • compass:rotated fired after compass data is rotated
  • compass:disabled fired when compass is disabled


Source code:

Atmosphere NPM

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free