Skip to content

Commit 6b16b14

Browse files
committed
【feature】l7layer 支持map对应layer和Source的方法和事件
1 parent c89f68d commit 6b16b14

File tree

12 files changed

+1046
-199
lines changed

12 files changed

+1046
-199
lines changed

src/mapboxgl/core/MapExtend.js

Lines changed: 248 additions & 141 deletions
Large diffs are not rendered by default.

src/mapboxgl/mapping/utils/L7LayerUtil.js

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,24 @@ function WebMapSourceToL7Source(source, sourceLayer, options) {
649649
return rules[type] && rules[type](source, sourceLayer, options);
650650
}
651651

652-
function getL7Filter(filter) {
652+
function getFilterFields(filter) {
653+
const result = [];
654+
for (const exp of filter) {
655+
if (exp instanceof Array && exp[1] && typeof exp[1] === 'string') {
656+
result.push(exp[1]);
657+
continue;
658+
}
659+
if (exp instanceof Array) {
660+
const subResult = getFilterFields(exp);
661+
if (subResult && subResult.length > 0) {
662+
result.push(...subResult);
663+
}
664+
}
665+
}
666+
return result;
667+
}
668+
669+
export function getL7Filter(filter) {
653670
if (!filter) {
654671
return;
655672
}
@@ -661,7 +678,7 @@ function getL7Filter(filter) {
661678
}
662679
return true;
663680
});
664-
const field = newExpressions.map((exp) => exp[1]);
681+
const field = Array.from(new Set(getFilterFields(newExpressions)));
665682
const fFilter = featureFilter([condition, ...newExpressions]);
666683
const filterFunc = fFilter.filter.bind(fFilter);
667684
return {
@@ -687,14 +704,19 @@ function getL7Filter(filter) {
687704
* @param layer
688705
*/
689706
function getL7LayerCommonInfo(layer) {
690-
const { id, minzoom, maxzoom, layout, filter } = layer;
707+
const { type, id, minzoom, maxzoom, layout, paint, filter, source } = layer;
691708
return {
692709
id,
693710
options: {
711+
type,
694712
name: layer.id,
695713
sourceLayer: layer['source-layer'],
696-
minzoom,
697-
maxzoom,
714+
source,
715+
layout,
716+
paint,
717+
filter,
718+
minZoom: minzoom,
719+
maxZoom: maxzoom,
698720
visible: layout.visibility === 'none' ? false : true
699721
},
700722
filter: getL7Filter(filter)
@@ -1908,15 +1930,15 @@ function getL7Layer(l) {
19081930
[MSLayerType.polygon]: 'PolygonLayer',
19091931
[MSLayerType.heatmap]: 'HeatmapLayer'
19101932
};
1933+
const source = l.source || {};
19111934
const layer = new L7Layer({
19121935
type: typeRule[l.type],
1913-
options: { ...l.options, layerID: (l.options || {}).name }
1936+
options: { ...l.options, layerID: (l.options || {}).name, featureId: (source.parser || {}).type === 'mvt' ? 'smpid' : undefined } // 解决L7结构化数据监听click事件会返回多个features问题
19141937
});
19151938
// getL7Layer返回原生antv l7 layer的实例
19161939
const l7Layer = layer.getL7Layer();
19171940
// 调用原生antv l7 layer的方法,构建图层
19181941
const sourceOptions = {};
1919-
const source = l.source || {};
19201942
const shape = l.shape || {};
19211943
if (source.parser) {
19221944
sourceOptions.parser = l.source.parser;
@@ -1982,7 +2004,9 @@ export async function addL7Layers({ map, webMapInfo, l7Layers, spriteDatas, opti
19822004
ChartController.setSceneChartLayer(l.id, actionLayer);
19832005
} else {
19842006
const layer = getL7Layer(l);
1985-
map.addLayer(layer, beforeLayer && beforeLayer.id);
2007+
if (!map.getLayer(layer.id)) {
2008+
map.addLayer(layer, beforeLayer && beforeLayer.id);
2009+
}
19862010
}
19872011
}
19882012
}

src/mapboxgl/mapping/webmap/v3/WebMap.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,31 @@ export class WebMap extends mapboxgl.Evented {
194194
return this._legendList;
195195
}
196196

197+
async copyLayer(id, layerInfo = {}) {
198+
const matchLayer = this._mapInfo.layers.find(layer => layer.id === id);
199+
if (!matchLayer || this.map.getLayer(layerInfo.id)) {
200+
return;
201+
}
202+
const copyLayerId = layerInfo.id || `${matchLayer.id}_copy`;
203+
const copyLayer = { ...matchLayer, ...layerInfo, id: copyLayerId };
204+
if (isL7Layer(copyLayer)) {
205+
const layers = [copyLayer];
206+
await addL7Layers({
207+
map: this.map,
208+
webMapInfo: { ...this._mapInfo, layers, sources: this._mapInfo.sources },
209+
l7Layers: layers,
210+
spriteDatas: this._spriteDatas,
211+
options: this.options
212+
});
213+
return;
214+
}
215+
if (typeof copyLayer.source === 'object') {
216+
this.map.addSource(copyLayer.id, copyLayer.source);
217+
copyLayer.source = copyLayer.id;
218+
}
219+
this.map.addLayer(copyLayer);
220+
}
221+
197222
/**
198223
* @private
199224
* @function WebMap.prototype._createMap

src/mapboxgl/overlay/Base.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export class CustomOverlayLayer {
2+
constructor(options) {
3+
this.type = 'custom';
4+
this.overlay = true;
5+
this.sourceId = options.sourceId;
6+
// interaction 控制是否支持事件
7+
this.interaction = options.interaction || false;
8+
// query 是否支持查询
9+
this.query = options.query || false;
10+
this.events = options.events || [];
11+
}
12+
13+
// 获取 layer 的信息,如 type, id, sourceLayer, layout 等
14+
getLayer() {}
15+
16+
// 更换 layer 的顺序
17+
moveLayer() {}
18+
19+
// 获取 layer source的信息,如 id,type 等
20+
getSource() {}
21+
22+
// 返回指定样式图层中绘制属性的值
23+
getPaintProperty() {}
24+
25+
// 返回指定样式图层中布局属性的值
26+
getLayoutProperty() {}
27+
28+
// 修改指定样式图层中布局属性的值
29+
setLayoutProperty() {}
30+
31+
// 返回应用于指定样式图层的过滤器
32+
getFilter() {}
33+
34+
// 设定指定样式图层的过滤器
35+
setFilter() {}
36+
37+
// map 添加 layer 时的钩子函数
38+
onAdd() {}
39+
40+
// map 移除 layer 时的钩子函数
41+
onRemove() {}
42+
43+
// map 渲染 layer 时的钩子函数
44+
render() {}
45+
46+
// 注册 layer 事件,触发多次
47+
on() {}
48+
49+
// 注册 layer 事件,触发一次
50+
once() {}
51+
52+
// 移除 layer 事件
53+
off() {}
54+
55+
// 查询足查询参数的可见要素的 GeoJSON 要素对象数组
56+
queryRenderedFeatures() {}
57+
58+
// 查询满足查询参数的指定矢量切片或 GeoJSON 源中的要素
59+
querySourceFeatures() {}
60+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy