@2gis/mapgl
Async loader for 2gis MapGL API with typings.
Browser usage only!
Installation
$ npm install @2gis/mapgl
Usage
import { load } from '@2gis/mapgl';
async function start() {
const mapglAPI = await load();
const map = new mapglAPI.Map('container', {
center: [55.31878, 25.23584],
zoom: 13,
key: 'Your API access key',
});
const marker = new mapglAPI.Marker(map, {
coordinates: [55.31878, 25.23584],
});
}
start();
Without await/async:
load().then((mapglAPI) => {
const map = new mapglAPI.Map('container', {
center: [55.31878, 25.23584],
zoom: 13,
key: 'Your API access key',
});
});
mapgl namespace
@2gis/mapgl exports load
function and global.d.ts
file which you can reference to have access to mapgl typings.
To use types from mapgl namespace you need:
- Add reference to node_modules/@2gis/mapgl/global.d.ts in your project.d.ts
- Or reference in a module, where
load
function is imported
You can use typings for MapGL from mapgl namespace like this:
let marker: mapgl.Marker
Checkout example for more information.