Skip to content

图层工厂

所有图层工厂均返回支持 .addTo(map) 链式调用的对象。

G.tileLayer(options)

创建栅格瓦片图层。G.rasterTileLayer(options) 为别名。

ts
G.tileLayer(options?: TileLayerOptions): Layer
参数类型描述
urlstring瓦片 URL 模板({z}/{x}/{y}
subdomainsstring[]子域名列表
tileSizenumber瓦片大小(像素)
minZoomnumber最小缩放级别
maxZoomnumber最大缩放级别
opacitynumber不透明度 (0-1)
visibleboolean是否可见
attributionstring版权归属信息
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
参数类型描述
tilesstring[]矢量瓦片 URL 列表
urlstring矢量瓦片 URL 模板
sourceLayerstring数据源图层名
styleobject矢量瓦片样式
filterunknown[]过滤器表达式
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
参数类型描述
dataobjectGeoJSON 数据对象
urlstringGeoJSON 数据 URL
rendererobject渲染器配置
clusterboolean是否启用聚合
clusterRadiusnumber聚合半径
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
参数类型描述
sourceobject数据源对象
rendererobject渲染器
definitionExpressionstring要素过滤表达式
labelingobject标注配置
popupTemplatestring弹窗模板
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
参数类型描述
urlstring图片 URL(必填)
extentExtent图片范围 [minX, minY, maxX, maxY]
opacitynumber不透明度
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
参数类型描述
idstring图层 ID
zIndexnumber层级
ts
const gl = G.graphicsLayer({ id: 'drawings' }).addTo(map);

G.heatmapLayer(options)

创建热力图图层。

ts
G.heatmapLayer(options?: HeatmapLayerOptions): Layer
参数类型描述
radiusnumber热点半径
gradientstring[]渐变色数组
intensitynumber强度倍数
weightFieldstring权重字段名
ts
G.heatmapLayer({
  radius: 25,
  gradient: ['#00f', '#0ff', '#0f0', '#ff0', '#f00'],
  weightField: 'intensity',
}).addTo(map);

G.clusterLayer(options)

创建聚合图层。

ts
G.clusterLayer(options?: ClusterLayerOptions): Layer
参数类型描述
clusterRadiusnumber聚合半径(像素)
maxClusterZoomnumber最大聚合缩放级别
clusterSymbolobject聚合点符号
ts
G.clusterLayer({
  clusterRadius: 50,
  maxClusterZoom: 14,
}).addTo(map);

G.dynamicLayer(options)

创建动态更新图层。

ts
G.dynamicLayer(options?: DynamicLayerOptions): Layer
参数类型描述
urlstring数据 URL
intervalnumber刷新间隔(毫秒)
ts
G.dynamicLayer({ url: 'https://api.example.com/realtime', interval: 5000 }).addTo(map);

G.videoLayer(options)

创建视频图层。

ts
G.videoLayer(options?: VideoLayerOptions): Layer
参数类型描述
urlstring视频 URL
loopboolean是否循环播放
autoplayboolean是否自动播放
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
参数类型描述
maximumScreenSpaceErrornumber最大屏幕空间误差
ts
G.tileset3d({ maximumScreenSpaceError: 16 }).addTo(map);

G.pointCloud(options)

创建点云图层。

ts
G.pointCloud(options?: PointCloudOptions): Layer
参数类型描述
pointSizenumber点大小(像素)
attenuationboolean是否启用衰减
ts
G.pointCloud({ pointSize: 2, attenuation: true }).addTo(map);

G.terrain(options)

创建地形图层。

ts
G.terrain(options?: TerrainOptions): Layer
参数类型描述
exaggerationnumber高程夸张倍数
ts
G.terrain({ exaggeration: 1.5 }).addTo(map);

G.graticuleLayer(options)

创建经纬网格图层。

ts
G.graticuleLayer(options?: GraticuleLayerOptions): Layer
参数类型描述
intervalnumber网格间隔(度)
strokeColorstring线条颜色
ts
G.graticuleLayer({ interval: 10, strokeColor: '#ccc' }).addTo(map);

G.tileDebugLayer(options)

创建瓦片调试图层。

ts
G.tileDebugLayer(options?: TileDebugLayerOptions): Layer
参数类型描述
tileSizenumber瓦片大小
showCoordsboolean显示坐标信息
ts
G.tileDebugLayer({ tileSize: 256, showCoords: true }).addTo(map);

G.trafficLayer(options)

创建交通流量图层。

ts
G.trafficLayer(options?: TrafficLayerOptions): Layer
参数类型描述
providerstring数据提供方(如 'amap'
ts
G.trafficLayer({ provider: 'amap' }).addTo(map);

G.buildingLayer(options)

创建建筑物图层。

ts
G.buildingLayer(options?: BuildingLayerOptions): Layer
参数类型描述
colorstring建筑颜色
heightnumber默认高度
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
参数类型描述
radiusnumber六边形半径
coveragenumber覆盖率 (0-1)
elevationScalenumber高程缩放
ts
G.hexagonLayer({ radius: 200, coverage: 0.8, elevationScale: 1 }).addTo(map);

G.gridLayer(options)

创建网格聚合图层。

ts
G.gridLayer(options?: GridLayerOptions): Layer
参数类型描述
cellSizenumber网格单元大小
coveragenumber覆盖率 (0-1)
elevationScalenumber高程缩放
ts
G.gridLayer({ cellSize: 100, elevationScale: 1 }).addTo(map);

G.tripsLayer(options)

创建轨迹动画图层。

ts
G.tripsLayer(options?: TripsLayerOptions): Layer
参数类型描述
getPath(d) => Coordinate[]路径访问器
trailLengthnumber尾迹长度(毫秒)
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
参数类型描述
hexagonColumnstringH3 索引字段名
coveragenumber覆盖率 (0-1)
elevationScalenumber高程缩放
ts
G.h3HexagonLayer({
  hexagonColumn: 'h3Index',
  coverage: 0.9,
  elevationScale: 1,
}).addTo(map);

G.panoramaLayer(options)

创建全景图层。

ts
G.panoramaLayer(options?: PanoramaLayerOptions): Layer
参数类型描述
providerstring全景服务提供方(如 'baidu'
position[number, number]全景位置
radiusnumber视野半径
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);

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