@ 2gis/ 地图gl
自动加载器 2gis 地图GL API 与打字.
只浏览器使用 !
安装
$ npm install @2gis/mapgl
使用量
import { load } from '@2gis/mapgl';
// or const { load } = require('@2gis/mapgl');
async function start() {
const mapglAPI = await load();
// container — id of the div element in your html
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();
不等待/同步:
load().then((mapglAPI) => {
const map = new mapglAPI.Map('container', {
center: [55.31878, 25.23584],
zoom: 13,
key: 'Your API access key',
});
});
默认, latest mapGL API 版本将加载(https://mapgl.2gis.com/api/js) (中文(简体) ). 但是,您可以指定MapGL API的某些版本来加载:
load('https://mapgl.2gis.com/api/js/v1.4.2').then((mapglAPI) => {});
检查我们 为 MapGL API 发布注释. 需要注意的是,mapgl加载器版本不等于MapGL API版本,因为它有自己的特性.
地图gl 命名空间
@ 2gis/ mapgl 导出 load 函数和 global.d.ts 可引用可访问映射格打字的文件.
要使用地图gl命名空间所需的类型 :
- 在您的工程中添加节点 模块/@2gis/mapgl/global.d.ts
- 或者在模块中引用,其中
load函数被导入
/// <reference path="node_modules/@2gis/mapgl/global.d.ts" />
您可以使用此地图gl 命名空间的 MapGL 输入 :
let marker: mapgl.Marker
查看更多信息的示例 .