Skip to content

Commit 0bc4476

Browse files
committed
[fix]修改拉伸面文本标签图例报错
1 parent f893e0f commit 0bc4476

File tree

3 files changed

+264
-104
lines changed

3 files changed

+264
-104
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ export class WebMap extends mapboxgl.Evented {
10141014
// 线面文本标签
10151015
if (label) {
10161016
styleSettings.push({...label, type: 'text'});
1017-
if (label.symbolsContent.value.symbolId) {
1017+
if (label.symbolsContent && label.symbolsContent.value.symbolId) {
10181018
styleSettings.push({...label, type: 'symbol'});
10191019
}
10201020
}
@@ -1268,7 +1268,7 @@ export class WebMap extends mapboxgl.Evented {
12681268
dataKeys = dataKeys.filter((key) => key !== 'color')
12691269
}
12701270
}
1271-
const isLinearColor = styleSetting.color.interpolateInfo && styleSetting.color.interpolateInfo.type === 'linear';
1271+
const isLinearColor = styleSetting.color && styleSetting.color.interpolateInfo && styleSetting.color.interpolateInfo.type === 'linear';
12721272
const isShowSingleItem = this._isShowLegendSingleItem(dataKeys, isLinearColor);
12731273
const resultList = [];
12741274
if (isShowSingleItem) {

test/mapboxgl/mapping/WebMapV3Spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,13 @@ describe('mapboxgl-webmap3.0', () => {
949949
});
950950

951951
it('label legend', (done) => {
952+
const mapInfo = JSON.parse(mapstudioWebMap_labelLegend);
953+
spyOn(L7, 'PointLayer').and.callFake(mockL7.PointLayer);
954+
spyOn(L7, 'LineLayer').and.callFake(mockL7.PointLayer);
955+
spyOn(L7, 'PolygonLayer').and.callFake(mockL7.PointLayer);
956+
spyOn(L7, 'HeatmapLayer').and.callFake(mockL7.PointLayer);
957+
spyOn(L7, 'Scene').and.callFake(mockL7.Scene);
958+
spyOn(L7, 'Mapbox').and.callFake(mockL7.Mapbox);
952959
spyOn(FetchRequest, 'get').and.callFake((url) => {
953960
if (url.indexOf('map.json') > -1) {
954961
return Promise.resolve(new Response(mapstudioWebMap_labelLegend));
@@ -959,14 +966,18 @@ describe('mapboxgl-webmap3.0', () => {
959966
}
960967
return Promise.resolve();
961968
});
969+
mapboxgl.Map.prototype.getCRS = function () {
970+
return { epsgCode: 'EPSG:3857', getExtent: () => {} };
971+
};
962972
mapstudioWebmap = new WebMap(id, {
963973
server: server
964974
});
965975

966976
mapstudioWebmap.on('addlayerssucceeded', ({ map }) => {
967977
const webMapV3 = mapstudioWebmap._getWebMapInstance();
968978
expect(map).not.toBeUndefined();
969-
expect(webMapV3.getLegendInfo().length).toBe(6);
979+
expect(webMapV3.getLegendInfo().length).toBe(9);
980+
delete mapboxgl.Map.prototype.getCRS;
970981
done();
971982
});
972983
});

0 commit comments

Comments
 (0)