主题
图层工厂
所有图层工厂均返回支持 .addTo(map) 链式调用的对象。
G.tileLayer(options)
创建栅格瓦片图层。G.rasterTileLayer(options) 为别名。
ts
G.tileLayer(options?: TileLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 瓦片 URL 模板({z}/{x}/{y}) |
| subdomains | string[] | 子域名列表 |
| tileSize | number | 瓦片大小(像素) |
| minZoom | number | 最小缩放级别 |
| maxZoom | number | 最大缩放级别 |
| opacity | number | 不透明度 (0-1) |
| visible | boolean | 是否可见 |
| attribution | string | 版权归属信息 |
ts
G.tileLayer({
url: 'https://tile.example.com/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
opacity: 0.8,
}).addTo(map);G.vectorTileLayer(options)
创建矢量瓦片图层。
ts
G.vectorTileLayer(options?: VectorTileLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| tiles | string[] | 矢量瓦片 URL 列表 |
| url | string | 矢量瓦片 URL 模板 |
| sourceLayer | string | 数据源图层名 |
| style | object | 矢量瓦片样式 |
| filter | unknown[] | 过滤器表达式 |
ts
G.vectorTileLayer({
tiles: ['https://v.example.com/{z}/{x}/{y}.pbf'],
sourceLayer: 'roads',
style: { 'line-color': '#333', 'line-width': 2 },
}).addTo(map);G.geoJsonLayer(options)
创建 GeoJSON 图层,自动创建 GeoJsonSource。
ts
G.geoJsonLayer(options?: GeoJsonLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| data | object | GeoJSON 数据对象 |
| url | string | GeoJSON 数据 URL |
| renderer | object | 渲染器配置 |
| cluster | boolean | 是否启用聚合 |
| clusterRadius | number | 聚合半径 |
ts
G.geoJsonLayer({
data: { type: 'FeatureCollection', features: [] },
renderer: G.simpleRenderer(G.lineSymbol({ color: '#3498db', width: 2 })),
}).addTo(map);G.featureLayer(options)
创建要素图层,可指定数据源和渲染器。
ts
G.featureLayer(options?: FeatureLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| source | object | 数据源对象 |
| renderer | object | 渲染器 |
| definitionExpression | string | 要素过滤表达式 |
| labeling | object | 标注配置 |
| popupTemplate | string | 弹窗模板 |
ts
G.featureLayer({
source: G.geojson(myData),
renderer: G.uniqueValueRenderer({
field: 'type',
uniqueValues: [{ value: 'A', symbol: G.fillSymbol({ color: '#f00' }) }],
}),
labeling: { field: 'name', fontSize: 12 },
}).addTo(map);G.imageLayer(options)
创建图片叠加图层。
ts
G.imageLayer(options: ImageLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 图片 URL(必填) |
| extent | Extent | 图片范围 [minX, minY, maxX, maxY] |
| opacity | number | 不透明度 |
ts
G.imageLayer({
url: 'https://example.com/overlay.png',
extent: [116.0, 39.0, 117.0, 40.0],
opacity: 0.7,
}).addTo(map);G.graphicsLayer(options)
创建图形图层,用于动态添加图形。
ts
G.graphicsLayer(options?: GraphicsLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| id | string | 图层 ID |
| zIndex | number | 层级 |
ts
const gl = G.graphicsLayer({ id: 'drawings' }).addTo(map);G.heatmapLayer(options)
创建热力图图层。
ts
G.heatmapLayer(options?: HeatmapLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| radius | number | 热点半径 |
| gradient | string[] | 渐变色数组 |
| intensity | number | 强度倍数 |
| weightField | string | 权重字段名 |
ts
G.heatmapLayer({
radius: 25,
gradient: ['#00f', '#0ff', '#0f0', '#ff0', '#f00'],
weightField: 'intensity',
}).addTo(map);G.clusterLayer(options)
创建聚合图层。
ts
G.clusterLayer(options?: ClusterLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| clusterRadius | number | 聚合半径(像素) |
| maxClusterZoom | number | 最大聚合缩放级别 |
| clusterSymbol | object | 聚合点符号 |
ts
G.clusterLayer({
clusterRadius: 50,
maxClusterZoom: 14,
}).addTo(map);G.dynamicLayer(options)
创建动态更新图层。
ts
G.dynamicLayer(options?: DynamicLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 数据 URL |
| interval | number | 刷新间隔(毫秒) |
ts
G.dynamicLayer({ url: 'https://api.example.com/realtime', interval: 5000 }).addTo(map);G.videoLayer(options)
创建视频图层。
ts
G.videoLayer(options?: VideoLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| url | string | 视频 URL |
| loop | boolean | 是否循环播放 |
| autoplay | boolean | 是否自动播放 |
ts
G.videoLayer({ url: 'https://example.com/video.mp4', autoplay: true }).addTo(map);G.customLayer(options)
创建自定义渲染图层。
ts
G.customLayer(options?: CustomLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| renderFunction | (gl, matrix) => void | 自定义渲染函数 |
ts
G.customLayer({
renderFunction: (gl, matrix) => { /* WebGL 渲染 */ },
}).addTo(map);G.tileset3d(options)
创建 3D Tileset 图层。
ts
G.tileset3d(options?: Tileset3DOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| maximumScreenSpaceError | number | 最大屏幕空间误差 |
ts
G.tileset3d({ maximumScreenSpaceError: 16 }).addTo(map);G.pointCloud(options)
创建点云图层。
ts
G.pointCloud(options?: PointCloudOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| pointSize | number | 点大小(像素) |
| attenuation | boolean | 是否启用衰减 |
ts
G.pointCloud({ pointSize: 2, attenuation: true }).addTo(map);G.terrain(options)
创建地形图层。
ts
G.terrain(options?: TerrainOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| exaggeration | number | 高程夸张倍数 |
ts
G.terrain({ exaggeration: 1.5 }).addTo(map);G.graticuleLayer(options)
创建经纬网格图层。
ts
G.graticuleLayer(options?: GraticuleLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| interval | number | 网格间隔(度) |
| strokeColor | string | 线条颜色 |
ts
G.graticuleLayer({ interval: 10, strokeColor: '#ccc' }).addTo(map);G.tileDebugLayer(options)
创建瓦片调试图层。
ts
G.tileDebugLayer(options?: TileDebugLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| tileSize | number | 瓦片大小 |
| showCoords | boolean | 显示坐标信息 |
ts
G.tileDebugLayer({ tileSize: 256, showCoords: true }).addTo(map);G.trafficLayer(options)
创建交通流量图层。
ts
G.trafficLayer(options?: TrafficLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| provider | string | 数据提供方(如 'amap') |
ts
G.trafficLayer({ provider: 'amap' }).addTo(map);G.buildingLayer(options)
创建建筑物图层。
ts
G.buildingLayer(options?: BuildingLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| color | string | 建筑颜色 |
| height | number | 默认高度 |
ts
G.buildingLayer({ color: '#ccc', height: 100 }).addTo(map);G.arcLayer(options)
创建弧线图层(deck.gl 风格)。
ts
G.arcLayer(options?: ArcLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| getSourcePosition | () => [number, number] | 起点位置访问器 |
| getTargetPosition | () => [number, number] | 终点位置访问器 |
| getWidth | () => number | 线宽访问器 |
ts
G.arcLayer({
getSourcePosition: (d) => d.from,
getTargetPosition: (d) => d.to,
getWidth: (d) => d.weight,
}).addTo(map);G.hexagonLayer(options)
创建六边形聚合图层。
ts
G.hexagonLayer(options?: HexagonLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| radius | number | 六边形半径 |
| coverage | number | 覆盖率 (0-1) |
| elevationScale | number | 高程缩放 |
ts
G.hexagonLayer({ radius: 200, coverage: 0.8, elevationScale: 1 }).addTo(map);G.gridLayer(options)
创建网格聚合图层。
ts
G.gridLayer(options?: GridLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| cellSize | number | 网格单元大小 |
| coverage | number | 覆盖率 (0-1) |
| elevationScale | number | 高程缩放 |
ts
G.gridLayer({ cellSize: 100, elevationScale: 1 }).addTo(map);G.tripsLayer(options)
创建轨迹动画图层。
ts
G.tripsLayer(options?: TripsLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| getPath | (d) => Coordinate[] | 路径访问器 |
| trailLength | number | 尾迹长度(毫秒) |
ts
G.tripsLayer({
getPath: (d) => d.waypoints,
trailLength: 200,
}).addTo(map);G.greatCircleLayer(options)
创建大圆弧线图层。
ts
G.greatCircleLayer(options?: GreatCircleLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| getSourcePosition | () => [number, number] | 起点位置 |
| getTargetPosition | () => [number, number] | 终点位置 |
ts
G.greatCircleLayer({
getSourcePosition: () => [0, 0],
getTargetPosition: () => [180, 0],
}).addTo(map);G.h3HexagonLayer(options)
创建 H3 六边形索引图层。
ts
G.h3HexagonLayer(options?: H3HexagonLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| hexagonColumn | string | H3 索引字段名 |
| coverage | number | 覆盖率 (0-1) |
| elevationScale | number | 高程缩放 |
ts
G.h3HexagonLayer({
hexagonColumn: 'h3Index',
coverage: 0.9,
elevationScale: 1,
}).addTo(map);G.panoramaLayer(options)
创建全景图层。
ts
G.panoramaLayer(options?: PanoramaLayerOptions): Layer| 参数 | 类型 | 描述 |
|---|---|---|
| provider | string | 全景服务提供方(如 'baidu') |
| position | [number, number] | 全景位置 |
| radius | number | 视野半径 |
ts
G.panoramaLayer({
provider: 'baidu',
position: [116, 39],
radius: 100,
}).addTo(map);链式调用
所有图层工厂返回的对象都支持 .addTo(map) 链式调用:
ts
G.tileLayer({ url: '...' }).addTo(map);
G.heatmapLayer({ radius: 25 }).addTo(map);
G.clusterLayer({ clusterRadius: 50 }).addTo(map);