@2gis/mapgl

中文文档
1.80.0发布于 2026/10/28BSD-2-ClauseTypeScriptCommonJS近 30 天下载 2.9万

MapGL API script loader with typings

原始使用文档
文档目录3 节
  1. Installation
  2. Usage
  3. mapgl namespace

@2gis/mapgl

Async loader for 2gis MapGL API with typings.

Browser usage only!

Installation

$ npm install @2gis/mapgl

Usage

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();

Without await/async:

load().then((mapglAPI) => {
    const map = new mapglAPI.Map('container', {
        center: [55.31878, 25.23584],
        zoom: 13,
        key: 'Your API access key',
    });
});

By default, latest version of MapGL API will be loaded (https://mapgl.2gis.com/api/js). But you can specify certain version of MapGL API to load:

load('https://mapgl.2gis.com/api/js/v1.4.2').then((mapglAPI) => {});

Checkout our release notes for MapGL API. Important to note, mapgl loader version is not equal to MapGL API version, cause it has its own features.

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:

  1. Add reference to node_modules/@2gis/mapgl/global.d.ts in your project.d.ts
  2. Or reference in a module, where load function is imported
/// <reference path="node_modules/@2gis/mapgl/global.d.ts" />

You can use typings for MapGL from mapgl namespace like this:

let marker: mapgl.Marker

Checkout example for more information.

版本与发布记录

@2gis/mapgl 共发布 119 个版本,首次发布于 2020/05/08;过去 12 个月发布了 18 个版本。

版本发布日期距今
1.80.0latest2026/10/2810 天前
1.79.02026/10/2018 天前
1.78.12026/09/241 个月前
1.78.02026/09/141 个月前
1.77.02026/09/022 个月前
1.76.12026/08/142 个月前

关于 @2gis/mapgl 的常见问题

@2gis/mapgl 是什么?

MapGL API script loader with typings

如何安装 @2gis/mapgl?

在项目目录运行 npm install @2gis/mapgl,或使用 pnpm add / yarn add / bun add。

@2gis/mapgl 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@2gis/mapgl 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@2gis/mapgl 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@2gis/mapgl 可以商用吗?

@2gis/mapgl 使用 BSD-2-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@2gis/mapgl 的下载量有多少?

根据 npm 官方下载统计,@2gis/mapgl 在 2026/10/05 – 2026/11/03 这 30 天内被下载 29,240 次,日均约 975 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@2gis/mapgl 还在维护吗?

最新版本 1.80.0 发布于 2026/10/28(10 天前);至今共发布 119 个版本,其中过去 12 个月发布了 18 个;首次发布于 2020/05/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。