Skip to content

Commit 265ddfe

Browse files
committed
【feature】l7layer getlayer 新增接口reRender; l7 指定featureId优化
1 parent bfa32a7 commit 265ddfe

File tree

4 files changed

+50
-15
lines changed

4 files changed

+50
-15
lines changed

src/mapboxgl/mapping/utils/L7LayerUtil.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,9 +640,9 @@ function vectorSourceToL7Source(source, sourceLayer, options) {
640640
};
641641
if (isIportalProxyServiceUrl(result.data, options)) {
642642
Object.assign(result.parser, {
643-
requestParameters: {
644-
credentials: 'include'
645-
}
643+
requestParameters: {
644+
credentials: 'include'
645+
}
646646
});
647647
}
648648
return result;
@@ -978,12 +978,12 @@ function isSolidDasharray(dasharray) {
978978
}
979979

980980
/**
981-
* 根据dasharray获取线型
982-
* @param dasharray
983-
*/
981+
* 根据dasharray获取线型
982+
* @param dasharray
983+
*/
984984
function getLineTypeByDashArray(dasharray) {
985985
if (dasharray && dasharray.length > 1 && !isSolidDasharray(dasharray)) {
986-
return 'dash';
986+
return 'dash';
987987
}
988988
return 'solid';
989989
}
@@ -1957,9 +1957,18 @@ function getL7Layer(l, sourceInfo) {
19571957
[MSLayerType.heatmap]: 'HeatmapLayer'
19581958
};
19591959
const source = l.source || {};
1960+
// 解决L7结构化数据监听click事件会返回多个features问题
1961+
let promoteId = sourceInfo.promoteId;
1962+
if (!promoteId) {
1963+
promoteId = sourceInfo.tiles && sourceInfo.tiles[0].includes('/structureddata/') ? 'smpid' : undefined;
1964+
}
19601965
const layer = new L7Layer({
19611966
type: typeRule[l.type],
1962-
options: { ...l.options, layerID: (l.options || {}).name, featureId: sourceInfo.promoteId } // 解决L7结构化数据监听click事件会返回多个features问题
1967+
options: {
1968+
...l.options,
1969+
layerID: (l.options || {}).name,
1970+
featureId: promoteId
1971+
}
19631972
});
19641973
// getL7Layer返回原生antv l7 layer的实例
19651974
const l7Layer = layer.getL7Layer();

src/mapboxgl/overlay/L7Layer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export class L7Layer extends CustomOverlayLayer {
5858
this.eventListeners = {};
5959
this.selectedDatas = [];
6060
this.setSelectedDatasFn = this.setSelectedDatas.bind(this);
61+
this.reRenderFn = this.reRender.bind(this);
6162
}
6263
/**
6364
* @function L7Layer.prototype.getL7Layer
@@ -117,7 +118,8 @@ export class L7Layer extends CustomOverlayLayer {
117118
id: this.id,
118119
l7layer: this.l7layer,
119120
scene: this.scene,
120-
setSelectedDatas: this.setSelectedDatasFn
121+
setSelectedDatas: this.setSelectedDatasFn,
122+
reRender: this.reRenderFn
121123
};
122124
delete layerInfo.sourceId;
123125
delete layerInfo.layerID;

test/mapboxgl/mapping/utils/L7LayerUtilSpec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ describe('L7LayerUtil', () => {
77
const mapstudioWebMap_L7LayersRes = JSON.parse(mapstudioWebMap_L7Layers);
88

99
const scene = new mockL7.Scene();
10+
let layerMaplist = {};
1011
const map = {
1112
getL7Scene: () => Promise.resolve(scene),
12-
addLayer: () => {},
13+
addLayer: (layer) => {
14+
layerMaplist[layer.id] = layer;
15+
},
1316
getZoom: () => 3,
1417
getLayer: (layerId) => layerId.includes('-highlight')
1518
};
@@ -37,6 +40,10 @@ describe('L7LayerUtil', () => {
3740
options
3841
};
3942

43+
afterEach(() => {
44+
layerMaplist = {};
45+
});
46+
4047
it('add od layer', (done) => {
4148
spyOn(FetchRequest, 'get').and.callFake((url, _, options) => {
4249
expect(options.withCredentials).toBe(options.withCredentials);
@@ -351,8 +358,11 @@ describe('L7LayerUtil', () => {
351358
const spy1 = spyOn(nextOptions.map, 'addLayer').and.callThrough();
352359
const spy2 = spyOn(nextOptions.options, 'emitterEvent');
353360
addL7Layers(nextOptions).then(() => {
354-
// expect(nextOptions.map.addLayer.calls.count()).toEqual(1);
361+
expect(nextOptions.map.addLayer.calls.count()).toEqual(1);
355362
expect(nextOptions.options.emitterEvent).toHaveBeenCalledTimes(1);
363+
expect(layerMaplist['ms_New_LINE_1716864449916_8']).toBeUndefined();
364+
expect(layerMaplist['ms_label_县级行政区划_1719818803020_5']).toBeTruthy();
365+
expect(layerMaplist['ms_label_县级行政区划_1719818803020_5'].getLayer().featureId).toBe('smpid');
356366
spy1.calls.reset();
357367
spy2.calls.reset();
358368
done();
@@ -461,7 +471,7 @@ describe('L7LayerUtil', () => {
461471
],
462472
bounds: [102.98962307000005, 30.090978575000065, 104.89626180000005, 31.437765225000078],
463473
type: 'vector',
464-
promoteId: 'spmid'
474+
promoteId: 'SmID'
465475
}
466476
};
467477
const nextOptions = {
@@ -477,6 +487,7 @@ describe('L7LayerUtil', () => {
477487
const spy = spyOn(nextOptions.map, 'addLayer').and.callThrough();
478488
addL7Layers(nextOptions).then(() => {
479489
expect(nextOptions.map.addLayer.calls.count()).toEqual(2);
490+
expect(layerMaplist['县级行政区划@link_outline(0_24)'].getLayer().featureId).toBe('SmID');
480491
spy.calls.reset();
481492
done();
482493
});
@@ -539,10 +550,14 @@ describe('L7LayerUtil', () => {
539550
const spy = spyOn(nextOptions.map, 'addLayer').and.callThrough();
540551
const spy1 = spyOn(L7, 'LineLayer').and.callFake(mockL7.PointLayer);
541552
addL7Layers(nextOptions).then(() => {
553+
const iclientL7Layer = layerMaplist['县级行政区划@link_outline(0_24)'];
554+
const spy2 = spyOn(iclientL7Layer, 'reRender').and.callThrough();
542555
setTimeout(() => {
543556
expect(nextOptions.map.addLayer.calls.count()).toEqual(1);
557+
expect(iclientL7Layer.reRender.calls.count()).toEqual(1);
544558
spy.calls.reset();
545559
spy1.calls.reset();
560+
spy2.calls.reset();
546561
done();
547562
}, 1100);
548563
});

test/mapboxgl/overlay/L7LayerSpec.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,15 @@ describe('mapboxgl L7Layer', () => {
395395
expect(layerSource.type).toBe('vector');
396396
let features;
397397
const result = {
398-
cb: function(data) { features = data; }
398+
cb: function (data) {
399+
features = data;
400+
}
399401
};
400402
spyOn(result, 'cb').and.callThrough();
401403
layer.queryRenderedFeatures([0, 0], {}, result.cb);
402404
expect(result.cb.calls.count()).toBe(1);
403405
expect(features).not.toBeUndefined();
404-
expect(layer.querySourceFeatures().length).toBeGreaterThan(0)
406+
expect(layer.querySourceFeatures().length).toBeGreaterThan(0);
405407

406408
layer = new L7Layer({ type: 'PointLayer', options: { layerID: 'empty-test' } });
407409
l7Layer = layer.getL7Layer();
@@ -467,6 +469,13 @@ describe('mapboxgl L7Layer', () => {
467469
expect(layerOnMap.paint).toEqual(options.paint);
468470
expect(layerOnMap.layout.visibility).toBeTruthy();
469471
expect(layerOnMap.filter).toEqual(filter);
472+
spyOn(map, 'triggerRepaint');
473+
layerOnMap.reRender();
474+
expect(map.triggerRepaint).toHaveBeenCalled();
475+
const activeFeature = { properties: { name: 'test' } };
476+
layerOnMap.setSelectedDatas(activeFeature);
477+
expect(layer.selectedDatas).toEqual([activeFeature]);
478+
layer.setSelectedDatas([]);
470479
expect(layer.getPaintProperty('point-extrusion-width')).toBe(paint['point-extrusion-width']);
471480
expect(layer.getLayoutProperty('point-extrusion-shape')).toBe(layout['point-extrusion-shape']);
472481
const layerFilter = layer.getFilter();
@@ -499,7 +508,7 @@ describe('mapboxgl L7Layer', () => {
499508
spyOn(l7Layer, 'on');
500509
spyOn(l7Layer, 'once');
501510
spyOn(l7Layer, 'off');
502-
const cb = () => {}
511+
const cb = () => {};
503512
layer.on('mouseover', cb);
504513
layer.once('mouseover', cb);
505514
layer.off('mouseover', cb);

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