主题
简易版 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.style | Mapbox 样式 |
| 投影 | 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'