Skip to content

简易版 API 概览

简易版 API (@gmap/simple) 提供全局 G 命名空间,零 new,链式调用。

设计原则

  • 零 new:所有对象通过工厂函数创建
  • 链式调用.addTo(map) 无缝集成
  • 全局命名空间G.* 统一入口
  • 渐进增强:从简单开始,按需切换到标准版

快速示例

ts
import G from '@gmap/simple';

// 注册引擎
G.use('ol', () => new OlAdapter(), { default: '2d' });

// 创建地图
const map = G.map({ target: 'map', engine: 'ol', center: [116, 39], zoom: 10 });

// 添加图层
G.tileLayer({ url: 'https://...' }).addTo(map);

// 添加要素
G.marker({ coord: [116, 39], attributes: { name: '北京' } }).addTo(map);

全局配置

ts
G.config({ locale: 'zh-CN', projection: 'EPSG:3857' });
const cfg = G.getConfig(); // 读取配置

G.use('ol', () => new OlAdapter(), { default: '2d' });
G.setDefaultEngine('ol', '2d');

G.noConflict(); // 恢复 window.G 的原始值

API 分类

分类方法说明
配置G.config, G.getConfig, G.use, G.setDefaultEngine, G.noConflict全局配置
地图G.map创建地图
图层G.tileLayer, G.vectorTileLayer, G.geoJsonLayer, G.featureLayer, ...图层工厂
数据源G.source, G.geojson, G.vectorTileSource, G.wms, ...数据源工厂
要素G.marker, G.polyline, G.polygon, G.circle, G.rectangle, ...要素工厂
几何G.geom.point, G.geom.lineString, G.geom.polygon, ...几何构造
符号G.fillSymbol, G.lineSymbol, G.markerSymbol, G.textSymbol, ...符号工厂
渲染器G.simpleRenderer, G.uniqueValueRenderer, G.classBreaksRenderer, ...渲染器工厂
控件G.zoomControl, G.scaleBarControl, G.compassControl, ...控件工厂
交互G.draw, G.edit, G.measure, G.snap交互工厂
弹窗G.popup, G.tooltip弹窗/提示
样式G.styleMapbox 样式
投影G.projection坐标投影
格式G.format数据格式
服务G.services.geocode, G.services.regeocode, G.services.routing, G.services.search地图服务
动画G.animation.moveAlong, G.animation.bounce, G.animation.breathe动画
工具G.utils.measurement, G.utils.analysis, G.utils.geom, G.utils.projection量算/分析

版本

ts
G.version; // '0.1.0'

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