Socket
Socket
Sign inDemoInstall

@joeyklee/compass.js

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @joeyklee/compass.js

A minimal javascript library for accessing the compass direction of a user relative to North.


Version published
Weekly downloads
7
decreased by-22.22%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

compass.js

A minimal javascript library for accessing the compass direction of a user relative to North.

<script src="https://unpkg.com/@joeyklee/compass.js@latest/dist/compass.js"></script>

compass logo

Quickstart

Include the reference to the script:

<script src="https://unpkg.com/@joeyklee/compass.js@latest/dist/compass.js"></script>

Using Async/Await

window.addEventListener("DOMContentLoaded", async() => {
  const compass = new Compass();
  await compass.init();

  const bearingToNorth = compass.getBearingToNorth();
  console.log(bearingToNorth); // 0;
})

Using Callbacks

window.addEventListener("DOMContentLoaded", () => {
  const compass = new Compass();
  compass.init(compassLoaded);


  function compassLoaded(){
    const bearingToNorth = compass.getBearingToNorth();
    console.log(bearingToNorth); // 0;
  }
  
});

Docs

You can read the docs to get a better understanding of the Compass class.

See: Docs

Examples

compass.js demo on mapbox gl map

Here's a few examples to get you started:

Develop

To develop the Compass you can install the development dependencies and run the tests below.

Setup

$ npm install

Tests

$ npm run test

Generate Docs

$ npm run docs

Examples

$ npm run examples

TODO

  • Add webpack build
  • Allow customization for device orientation access trigger

Credits

Notes

  • A note on new iphone devices
    • device orientation requires user to confirm with a gesture
  • A note on compass directions:
    • 0 deg = north
    • 90 deg = east
    • 180 deg = south
    • 270 deg = west

FAQs

Last updated on 06 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc