Skip to content

安装

私有源配置

GMap SDK 托管在内部私有 npm 仓库,使用前需配置对应环境的源地址。

厅政务外网

bash
npm config set @gmap:registry https://npm.szwt.gov.cn

厅互联网

bash
npm config set @gmap:registry https://npm.szinw.gov.cn

企业政务外网

bash
npm config set @gmap:registry https://npm.qywt.gov.cn

企业互联网

bash
npm config set @gmap:registry https://npm.qyinw.gov.cn

或在 .npmrc 中配置

ini
@gmap:registry=https://npm.szwt.gov.cn
//npm.szwt.gov.cn/:_authToken=${NPM_TOKEN}

包管理器安装

npm

bash
npm install @gmap/core @gmap/standard @gmap/shim-openlayers

yarn

bash
yarn add @gmap/core @gmap/standard @gmap/shim-openlayers

pnpm

bash
pnpm add @gmap/core @gmap/standard @gmap/shim-openlayers

按需安装

核心包(必选)

bash
npm install @gmap/core

API 层(三选一或组合使用)

bash
npm install @gmap/simple      # 简易版:零 new,链式调用
npm install @gmap/standard    # 标准版:ES 模块,完整类型
npm install @gmap/advanced    # 专业版:门面子模式

引擎适配器(按需选择)

bash
npm install @gmap/shim-openlayers ol              # OpenLayers 2D
npm install @gmap/shim-maplibre maplibre-gl       # MapLibre 矢量瓦片
npm install @gmap/shim-cesium cesium              # Cesium 3D

插件

bash
npm install @gmap/services    # 地图服务 API(地理编码/POI/路径/天气)
npm install @gmap/geo         # 量算/分析/坐标投影
npm install @gmap/style-mapbox # Mapbox 样式引擎

一次性安装全部

bash
npm install @gmap/core @gmap/geo @gmap/style-mapbox @gmap/standard @gmap/simple @gmap/advanced @gmap/shim-openlayers @gmap/shim-maplibre @gmap/shim-cesium @gmap/services

包说明

包名说明依赖
@gmap/core核心抽象层
@gmap/geo量算/分析/投影
@gmap/style-mapboxMapbox 样式引擎
@gmap/standard标准版 APIcore, geo
@gmap/simple简易版 APIcore, geo, standard, services
@gmap/advanced专业版 APIcore, geo, standard, services
@gmap/shim-openlayersOpenLayers 适配器core (peer: ol)
@gmap/shim-maplibreMapLibre 适配器core, style-mapbox (peer: maplibre-gl)
@gmap/shim-cesiumCesium 适配器core (peer: cesium)
@gmap/services地图服务

TypeScript 配置

json
{
  "compilerOptions": {
    "module": "ESNext",
    "moduleResolution": "NodeNext",
    "target": "ES2022",
    "strict": true
  }
}

浏览器兼容性

浏览器最低版本
Chrome80+
Firefox78+
Safari14+
Edge80+

验证安装

ts
import { EngineRegistry, MockAdapter } from '@gmap/core';

EngineRegistry.register('mock', () => new MockAdapter(), { default: '2d' });

console.log('GMap SDK 安装成功');

四川省交通运输综合地理服务平台 地图开发框架