主题
LayersFacade — 图层子门面
通过 app.layers 访问图层管理功能。所有 add* 方法返回 LayerRef,支持链式调用。
添加图层
addTile(options)
添加栅格瓦片图层。
ts
addTile(options: { id?: string; url?: string; tiles?: string[]; opacity?: number; minZoom?: number; maxZoom?: number; subdomains?: string[] }): LayerRefts
const ref = app.layers.addTile({
id: 'osm',
url: 'https://tile.example.com/{z}/{x}/{y}.png',
opacity: 0.8,
});addVectorTile(options)
添加矢量瓦片图层。
ts
addVectorTile(options: { id?: string; tiles?: string[]; url?: string; sourceLayer?: string; style?: unknown; filter?: unknown[] }): LayerRefts
const ref = app.layers.addVectorTile({
id: 'vtile',
tiles: ['https://v.example.com/{z}/{x}/{y}.pbf'],
sourceLayer: 'roads',
});addGeoJson(options)
添加 GeoJSON 图层。
ts
addGeoJson(options: { id?: string; data?: object; url?: string; intoLayer?: boolean }): LayerRefts
const ref = app.layers.addGeoJson({
id: 'geojson',
data: { type: 'FeatureCollection', features: [] },
});addFeatures(options)
添加要素图层。
ts
addFeatures(options: { id?: string; source?: unknown; renderer?: unknown }): LayerRefts
const ref = app.layers.addFeatures({ id: 'features' });addImage(options)
添加图片图层。
ts
addImage(options: { id?: string; url?: string; extent?: Extent; opacity?: number }): LayerRefts
const ref = app.layers.addImage({
id: 'img',
url: 'https://example.com/overlay.png',
opacity: 0.7,
});addHeatmap(options)
添加热力图图层。
ts
addHeatmap(options: { id?: string; radius?: number; gradient?: unknown; intensity?: number; weightField?: string }): LayerRefts
const ref = app.layers.addHeatmap({ id: 'heat', radius: 20 });addCluster(options)
添加聚合图层。
ts
addCluster(options: { id?: string; clusterRadius?: number; maxClusterZoom?: number }): LayerRefts
const ref = app.layers.addCluster({ id: 'cluster', clusterRadius: 50 });addWms(options)
添加 WMS 图层。
ts
addWms(options: { id?: string; url?: string; layers?: string[]; format?: string; transparent?: boolean }): LayerRefts
const ref = app.layers.addWms({
id: 'wms',
url: 'https://wms.example.com',
layers: ['layer1'],
});addDynamic(options)
添加动态更新图层。
ts
addDynamic(options: { id?: string; url?: string; interval?: number }): LayerRefts
const ref = app.layers.addDynamic({
id: 'dyn',
url: 'https://api.example.com/realtime',
interval: 5000,
});addCustom(options)
添加自定义图层。
ts
addCustom(options: { id?: string }): LayerRefts
const ref = app.layers.addCustom({ id: 'custom' });addTileset3D(options)
添加 3D Tileset 图层。
ts
addTileset3D(options: { id?: string; url?: string; maximumScreenSpaceError?: number }): LayerRefts
const ref = app.layers.addTileset3D({
id: 'tileset3d',
url: 'https://3dtiles.example.com',
});addPointCloud(options)
添加点云图层。
ts
addPointCloud(options: { id?: string; pointSize?: number; attenuation?: boolean }): LayerRefts
const ref = app.layers.addPointCloud({
id: 'pc',
pointSize: 3,
attenuation: true,
});管理图层
get(id)
获取图层引用。
ts
get(id: string): LayerRef | nullts
const ref = app.layers.get('osm');
if (ref) {
ref.setVisible(false);
}list()
列出所有图层。
ts
list(): LayerRef[]ts
const allLayers = app.layers.list();
allLayers.forEach(l => console.log(l.id));remove(id)
移除图层。
ts
remove(id: string): voidts
app.layers.remove('osm');setVisible(id, visible)
设置图层可见性。
ts
setVisible(id: string, visible: boolean): voidts
app.layers.setVisible('osm', false);setBasemap(id)
切换底图。
ts
setBasemap(id: string): voidts
app.layers.setBasemap('satellite');reorder(id, options)
调整图层顺序。
ts
reorder(id: string, options?: { position?: number; beforeId?: string }): void| 参数 | 类型 | 描述 |
|---|---|---|
| position | number | 目标位置索引 |
| beforeId | string | 插入到指定图层之前 |
ts
app.layers.reorder('osm', { position: 0 });clear()
移除所有图层。
ts
clear(): voidts
app.layers.clear();LayerRef
所有 add* 方法返回 LayerRef,支持以下方法:
| 方法 | 返回值 | 说明 |
|---|---|---|
| setVisible(visible) | LayerRef | 设置可见性(链式) |
| setOpacity(opacity) | LayerRef | 设置不透明度 (0-1)(链式) |
| setZIndex(z) | LayerRef | 设置层级(链式) |
| remove() | void | 移除图层自身 |
ts
ref.setVisible(false).setOpacity(0.5).setZIndex(10);
ref.remove();