Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/soal/map-promisified

Wrapper for Mapbox Gl JS library that gives nice Promise-based API to asynchronous map functions
https://github.com/soal/map-promisified

mapbox-gl mapbox-gl-js promise

Last synced: 3 months ago
JSON representation

Wrapper for Mapbox Gl JS library that gives nice Promise-based API to asynchronous map functions

Awesome Lists containing this project

README

        

# map-promisified
Wrapper for Mapbox Gl JS library that gives nice Promise-based API to asynchronous map functions

Usage:
```javascript
import promisify from 'map-promisified'
import Mapbox from 'mapbox-gl'

const map = new Mapbox.Map({
// … map properties …
})

// promisify single method:
const flyToPromisified = promisify(map, 'flyTo')

async function flyToPosition () {
const newPosition = await flyToPromisified([10, 20])
console.log(newPosition)
// ⇒ { bearing: 0
//​ center: Object { lng: …, lat: … },
// pitch: 0,
// zoom: 9
// }
}

// promisify all async map methods:
const actions = promisify(map)

async function flyToPositionAction () {
const newPosition = await actions.flyTo([10, 20])
console.log(newPosition)
// ⇒ { bearing: 0
//​ center: Object { lng: …, lat: … },
// pitch: 0,
// zoom: 9
// }
}
```

Promisified methods:
* setCenter
* panBy
* panTo
* setZoom
* zoomTo
* zoomIn
* zoomOut
* setBearing
* rotateTo
* resetNorth
* snapToNorth
* setPitch
* fitBounds
* fitScreenCoordinates
* jumpTo
* easeTo
* flyTo