Skip to content

Commit effefaf

Browse files
committed
【feature】L7 filter 优化; map 加载相同的l7layer优化;
1 parent fa52c72 commit effefaf

File tree

7 files changed

+137
-13
lines changed

7 files changed

+137
-13
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
"jsonsql": "0.2.5",
155155
"leaflet": "1.9.4",
156156
"lodash.clonedeep": "^4.5.0",
157+
"lodash.debounce": "^4.0.8",
157158
"lodash.difference": "^4.5.0",
158159
"lodash.remove": "^4.7.0",
159160
"lodash.topairs": "4.3.0",

src/mapboxgl/mapping/utils/L7LayerUtil.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as G2 from '@antv/g2';
77
import { Util } from '../../core/Util';
88
import { L7Layer, L7 } from '../../overlay/L7Layer';
99
import Color from './Color';
10+
import debounce from 'lodash.debounce';
1011

1112
const SelectStyleTypes = {
1213
basic: 'base',
@@ -1990,7 +1991,16 @@ function getL7Layer(l, sourceInfo) {
19901991
l7Layer.animate(l.animate);
19911992
}
19921993
if (l.filter) {
1993-
l7Layer.filter(l.filter.field, l.filter.values);
1994+
const refresh = debounce(function () {
1995+
layer.reRender();
1996+
}, 500);
1997+
l7Layer.filter(l.filter.field, (...args) => {
1998+
const result = l.filter.values(...args);
1999+
if (result) {
2000+
refresh();
2001+
}
2002+
return result;
2003+
});
19942004
}
19952005
return layer;
19962006
}

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class WebMap extends mapboxgl.Evented {
196196

197197
async copyLayer(id, layerInfo = {}) {
198198
const matchLayer = this._mapInfo.layers.find(layer => layer.id === id);
199-
if (!matchLayer || this.map.getLayer(layerInfo.id)) {
199+
if (!matchLayer || this.getLayerOnMap(layerInfo.id)) {
200200
return;
201201
}
202202
const copyLayerId = layerInfo.id || `${matchLayer.id}_copy`;
@@ -496,7 +496,7 @@ export class WebMap extends mapboxgl.Evented {
496496
}
497497
for (const layer of layersToMap) {
498498
const originId = layer.id;
499-
if (this.map.getLayer(layer.id)) {
499+
if (this.getLayerOnMap(layer.id)) {
500500
const layerId = layer.id + timestamp;
501501
layer.id = layerId;
502502
}
@@ -526,6 +526,34 @@ export class WebMap extends mapboxgl.Evented {
526526
};
527527
}
528528

529+
getLayerOnMap(layerId) {
530+
const overlayLayer = this.map.overlayLayersManager[layerId];
531+
if (overlayLayer) {
532+
return overlayLayer;
533+
}
534+
const l7MarkerLayers = getL7MarkerLayers();
535+
const l7MarkerLayer = l7MarkerLayers[layerId];
536+
if (l7MarkerLayer) {
537+
return l7MarkerLayer;
538+
}
539+
return this.map.getLayer(layerId);
540+
}
541+
542+
_findLayerCatalog(items, id) {
543+
for (const item of items) {
544+
if (item.id === id) {
545+
return item;
546+
}
547+
if (item.children) {
548+
const found = this._findLayerCatalog(item.children, id);
549+
if (found) {
550+
return found;
551+
}
552+
}
553+
}
554+
return null;
555+
}
556+
529557
_deleteLayerCatalog(catalogs, id) {
530558
for (let index = 0; index < catalogs.length; index++) {
531559
const catalog = catalogs[index];
@@ -539,14 +567,20 @@ export class WebMap extends mapboxgl.Evented {
539567
}
540568
}
541569

542-
_updateLayerCatalogsId({ loopData, catalogs, layerIdMapList, catalogTypeField = 'type', layerIdsField = 'parts', unspportedLayers }) {
570+
_updateLayerCatalogsId({
571+
loopData,
572+
catalogs,
573+
layerIdMapList,
574+
catalogTypeField = 'type',
575+
layerIdsField = 'parts',
576+
unspportedLayers
577+
}) {
543578
loopData.forEach((loopItem) => {
544-
const catalog = catalogs.find(item => item.id === loopItem.id);
545-
const { id, children } = catalog;
546-
if (catalog[catalogTypeField] === 'group') {
579+
const { id, children } = loopItem;
580+
if (loopItem[catalogTypeField] === 'group') {
547581
this._updateLayerCatalogsId({
548582
loopData: children,
549-
catalogs: children,
583+
catalogs,
550584
layerIdMapList,
551585
catalogTypeField,
552586
layerIdsField,
@@ -556,6 +590,7 @@ export class WebMap extends mapboxgl.Evented {
556590
}
557591
const matchLayer = layerIdMapList.find((item) => item.originId === id);
558592
if (matchLayer) {
593+
const catalog = this._findLayerCatalog(catalogs, id);
559594
catalog.id = matchLayer.renderId;
560595
if (catalog[layerIdsField]) {
561596
catalog[layerIdsField] = this._renameLayerIdsContent(catalog[layerIdsField], layerIdMapList);
@@ -683,6 +718,7 @@ export class WebMap extends mapboxgl.Evented {
683718
const { catalogs = [], datas = [] } = this._mapResourceInfo;
684719
const projectCataglogs = this._getLayerInfosFromCatalogs(catalogs, 'catalogType');
685720
const metadataCatalogs = this._getLayerInfosFromCatalogs(this._mapInfo.metadata.layerCatalog);
721+
const l7MarkerLayers = getL7MarkerLayers();
686722
const layers = allLayersOnMap.reduce((layersList, layer) => {
687723
const containLayer = metadataCatalogs.find((item) => {
688724
if (item.parts && item.id !== layer.id) {
@@ -743,6 +779,9 @@ export class WebMap extends mapboxgl.Evented {
743779
dataSource,
744780
themeSetting: {}
745781
});
782+
if (l7MarkerLayers[layer.id]) {
783+
overlayLayers.l7MarkerLayer = l7MarkerLayers[layer.id];
784+
}
746785
if (isL7Layer(layer)) {
747786
overlayLayers.l7Layer = true;
748787
}
@@ -813,6 +852,9 @@ export class WebMap extends mapboxgl.Evented {
813852
if (l7MarkerLayers[id]) {
814853
formatItem.l7MarkerLayer = l7MarkerLayers[id];
815854
}
855+
if (matchLayer.l7Layer) {
856+
formatItem.l7Layer = matchLayer.l7Layer;
857+
}
816858
}
817859
return formatItem;
818860
});
@@ -1106,7 +1148,7 @@ export class WebMap extends mapboxgl.Evented {
11061148
if (currentType === 'simple') {
11071149
return !!this._getImageIdFromValue(symbolsContent.value.style, SymbolType[symbolType]).length;
11081150
}
1109-
const styles = (symbolsContent.values).map((v) => v.value).concat(symbolsContent.defaultValue);
1151+
const styles = symbolsContent.values.map((v) => v.value).concat(symbolsContent.defaultValue);
11101152
return styles.every((v) => {
11111153
return !!this._getImageIdFromValue(v.style, SymbolType[symbolType]).length;
11121154
});

src/mapboxgl/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"canvg": "3.0.10",
2727
"fast-xml-parser": "^4.2.7",
2828
"flatgeobuf": "3.31.1",
29+
"lodash.debounce": "^4.0.8",
2930
"rbush": "^2.0.2",
3031
"proj4": "2.11.0",
3132
"flv.js": "^1.6.2",

test/mapboxgl/mapping/utils/L7LayerUtilSpec.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { addL7Layers, isL7Layer, getL7Filter } from '../../../../src/mapboxgl/mapping/utils/L7LayerUtil';
22
import * as mockL7 from '../../../tool/mock_l7';
3+
import * as L7 from '../../../../src/mapboxgl/overlay/L7/l7-render';
34
import { FetchRequest } from '@supermap/iclient-common/util/FetchRequest';
45

56
describe('L7LayerUtil', () => {
@@ -481,6 +482,72 @@ describe('L7LayerUtil', () => {
481482
});
482483
});
483484

485+
it('filter reRender', (done) => {
486+
spyOn(FetchRequest, 'post').and.callFake((url) => {
487+
if (url.indexOf('/data-ZhongGuoDiTu/rest/data/featureResults.geojson') > -1) {
488+
return Promise.resolve(new Response(RESTDATA_FEATURES_RES));
489+
}
490+
return Promise.resolve();
491+
});
492+
const layers = [
493+
{
494+
filter: ['all', ['==', '$type', 'Polygon']],
495+
layout: {
496+
visibility: 'visible',
497+
'line-extrusion-pattern-interval': 20,
498+
'line-extrusion-animate-duration': 6,
499+
'line-extrusion-pattern-blend': 'normal',
500+
'line-extrusion-animate-trailLength': 1.5,
501+
'line-extrusion-animate-interval': 0.6
502+
},
503+
metadata: {
504+
MapStudio: {
505+
title: '县级行政区划@link'
506+
}
507+
},
508+
maxzoom: 24,
509+
paint: {
510+
'line-extrusion-base': 0,
511+
'line-extrusion-opacity': 1,
512+
'line-extrusion-width': 20,
513+
'line-extrusion-base-fixed': false,
514+
'line-extrusion-color': '#4CC8A3',
515+
'line-extrusion-pattern': 'ms_icon_shape1'
516+
},
517+
source: 'ms_县级行政区划@link_1719822607738_6',
518+
'source-layer': '县级行政区划@link',
519+
id: '县级行政区划@link_outline(0_24)',
520+
type: 'line-extrusion',
521+
minzoom: 0
522+
}
523+
];
524+
const sources = {
525+
'ms_县级行政区划@link_1719822607738_6': {
526+
tiles: [
527+
'http://localhost:8195/portalproxy/592c4095f464540e/iserver/services/map-LinkMap/restjsr/v1/vectortile/maps/%E5%8E%BF%E7%BA%A7%E8%A1%8C%E6%94%BF%E5%8C%BA%E5%88%92%40link/tiles/{z}/{x}/{y}.mvt'
528+
],
529+
bounds: [102.98962307000005, 30.090978575000065, 104.89626180000005, 31.437765225000078],
530+
type: 'vector',
531+
promoteId: 'spmid'
532+
}
533+
};
534+
const nextOptions = {
535+
...addOptions,
536+
webMapInfo: { ...mapstudioWebMap_L7LayersRes, layers, sources },
537+
l7Layers: layers
538+
};
539+
const spy = spyOn(nextOptions.map, 'addLayer').and.callThrough();
540+
const spy1 = spyOn(L7, 'LineLayer').and.callFake(mockL7.PointLayer);
541+
addL7Layers(nextOptions).then(() => {
542+
setTimeout(() => {
543+
expect(nextOptions.map.addLayer.calls.count()).toEqual(1);
544+
spy.calls.reset();
545+
spy1.calls.reset();
546+
done();
547+
}, 1100);
548+
});
549+
});
550+
484551
it('filter expression', () => {
485552
const expr = ['any', ['all', ['==', ['get', 'smpid'], 5], ['==', ['get', '新建字段'], '']]];
486553
const result = getL7Filter(expr);

0 commit comments

Comments
 (0)