Skip to content

Commit fded5c0

Browse files
[fix]合并冲突 AI-GEN:
2 parents a0195f0 + c1c19cc commit fded5c0

22 files changed

Lines changed: 10484 additions & 29 deletions

src/common/commontypes/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ const Util = {
11291129
* @param {string} url - 验证地址。
11301130
* @returns {boolean} 是否是绝对地址。
11311131
*/
1132-
isAbsoluteURL(url) {
1132+
isAbsoluteURL(url) {
11331133
try {
11341134
const res = new URL(url);
11351135
return !!res;

src/common/mapping/MapBase.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export function createMapClassExtending(SuperClass = class {}) {
2626
return this._legendList;
2727
}
2828

29+
setLegends(legendList) {
30+
this._legendList = legendList || [];
31+
}
32+
2933
getSelfAppreciableLayers() {
3034
return (this._sourceListModel && this._sourceListModel.getSelfLayers(...arguments)) || [];
3135
}
@@ -84,7 +88,9 @@ export function createMapClassExtending(SuperClass = class {}) {
8488
}
8589
}
8690
Array.from(new Set(sourceList)).forEach((sourceId) => {
87-
this.map.removeSource(sourceId);
91+
if (this.map.getSource(sourceId)) {
92+
this.map.removeSource(sourceId);
93+
}
8894
});
8995
}
9096
};

src/common/mapping/WebMapBase.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,26 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
358358
pitch && this.setPitch(pitch);
359359
}
360360

361+
/**
362+
* @version 12.0.2
363+
* @function WebMapBase.prototype.getPopupInfos
364+
* @description 获取地图上所有图层的弹窗信息。
365+
* @returns {Array} 弹窗信息数组。
366+
*/
367+
getPopupInfos() {
368+
return (this._handler && this._handler._getPopupInfos()) || [];
369+
}
370+
371+
/**
372+
* @version 11.3.0
373+
* @function WebMapBase.prototype.getLegendInfos
374+
* @description 获取地图本身所有图层的legend状态。
375+
* @returns {Array} 图例信息数组,包含 showLegend、id、title 三个属性。
376+
*/
377+
getLegendInfos() {
378+
return (this._handler && this._handler._getLegendInfos()) || [];
379+
}
380+
361381
/**
362382
* @version 11.2.1
363383
* @function WebMapBase.prototype.getLayers
@@ -475,16 +495,23 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
475495
* @version 11.2.1
476496
* @function WebMapBase.prototype.cleanLayers
477497
* @description 删除追加的图层和事件。当设置 `map` 时有效
498+
* @param {Array<Object>} [layersToClean] - 要删除的图层数组,默认为所有可删除的缓存图层(非 reused)。每个图层对象包含 id 属性
499+
* @param {boolean} [isClean=true] - 是否调用 clean(false) 销毁内部资源。为 false 时只删除指定图层并同步清理 legends
478500
*/
479-
cleanLayers() {
501+
cleanLayers(layersToClean = this._cacheCleanLayers.filter(item => !item.reused), isClean = true) {
480502
// 清空追加的地图图层以及对应的事件
481503
if (!this.map) {
482504
return;
483505
}
484-
const layersToClean = this._cacheCleanLayers.filter((item) => !item.reused);
506+
const cacheLayers = this._cacheCleanLayers.filter((item) => !item.reused);
485507
this._handler && this._handler.cleanLayers(layersToClean);
486-
this._cacheCleanLayers = [];
487-
this.clean(false);
508+
this._cacheCleanLayers = cacheLayers.filter(item => !layersToClean.some((item1=> item1.id === item.id)));
509+
if (isClean) {
510+
this.clean(false);
511+
} else {
512+
const legends = this.getLegends();
513+
this._handler.setLegends(legends.filter(item => !layersToClean.some((item1=> item1.id === item.layerId))));
514+
}
488515
}
489516

490517
/**

src/common/mapping/WebMapV2.js

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* This program are made available under the terms of the Apache License, Version 2.0
33
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html. */
44
import cloneDeep from 'lodash.clonedeep';
5-
import { getProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define';
6-
import { ColorsPickerUtil } from '../util/ColorsPickerUtil';
75
import { Util } from '../commontypes/Util';
86
import { ArrayStatistic } from '../util/ArrayStatistic';
7+
import { ColorsPickerUtil } from '../util/ColorsPickerUtil';
98
import { FetchRequest } from '../util/FetchRequest';
9+
import { getProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define';
1010
import { SourceListModelV2 } from './utils/SourceListModelV2';
1111
import { isSameRasterLayer, mergeFeatures } from './utils/util';
1212

@@ -60,6 +60,10 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
6060
}
6161
this._appendLayers = true;
6262
this.map = map;
63+
if (this.map.addLocalIdeographFontFamily) {
64+
const fontFamilys = this._getLabelFontFamily(mapInfo);
65+
this.map.addLocalIdeographFontFamily(fontFamilys);
66+
}
6367
}
6468
this._mapInfo = mapInfo;
6569
this._loadLayers(mapInfo, this._taskID);
@@ -181,6 +185,45 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
181185
crsManager.registerCRS(crs);
182186
return epsgCode;
183187
}
188+
_getPopupInfos() {
189+
const { layers = [] } = this._mapInfo;
190+
return layers.map((layer) => {
191+
const { popupInfo, enableFields, name, layerID: layerId, captions: fieldCaptions } = layer;
192+
if (popupInfo){
193+
let elements = popupInfo.elements || [];
194+
if (fieldCaptions) {
195+
elements = (popupInfo.elements || []).map(item => {
196+
if (item.type === 'FIELD') {
197+
item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName;
198+
}
199+
return item;
200+
});
201+
}
202+
return { ...popupInfo, layerId: [layerId], elements, title: name };
203+
}
204+
if (enableFields) {
205+
const elements = enableFields.map((fieldName) => ({
206+
type: 'FIELD',
207+
fieldName,
208+
fieldCaption: fieldCaptions ? (fieldCaptions[fieldName] || fieldName) : fieldName
209+
}));
210+
return { elements, layerId: [layerId], title: name };
211+
}
212+
return null;
213+
}).filter(item => item !== null);
214+
}
215+
216+
_getLegendInfos() {
217+
const { layers = [] } = this._mapInfo;
218+
return layers.map((layer) => {
219+
const { legendSetting, name, layerID: layerId } = layer;
220+
return {
221+
showLegend: legendSetting ? legendSetting?.isShow !== false : false,
222+
id: layerId,
223+
title: name
224+
};
225+
});
226+
}
184227

185228
_handleLayerInfo(mapInfo, _taskID) {
186229
mapInfo = this._setLayerID(mapInfo);
@@ -812,6 +855,9 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
812855
bounds = this._getBoundList(res);
813856
}
814857
}
858+
if (bounds && !this._isValidBounds(bounds)) {
859+
bounds = null;
860+
}
815861
}
816862
this._addBaselayer({
817863
url: [url],
@@ -2764,6 +2810,35 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
27642810
return coor;
27652811
}
27662812

2813+
// 校验 bounds 是否为合法的经纬度范围(EPSG:4326)
2814+
// 不合法返回 false:值非数字/无穷、左>=右、下>=上、四个坐标都在 ±0.5 度内(认为退化为原点附近)、超出经纬度范围
2815+
_isValidBounds(bounds) {
2816+
if (!Array.isArray(bounds) || bounds.length !== 4) {
2817+
return false;
2818+
}
2819+
const [left, bottom, right, top] = bounds;
2820+
if (![left, bottom, right, top].every((v) => typeof v === 'number' && Number.isFinite(v))) {
2821+
return false;
2822+
}
2823+
if (left >= right || bottom >= top) {
2824+
return false;
2825+
}
2826+
// 容差,吸收浮点计算误差(如 180.00000000000006)
2827+
const tolerance = 1e-6;
2828+
if (
2829+
Math.abs(left) > 180 + tolerance ||
2830+
Math.abs(right) > 180 + tolerance ||
2831+
Math.abs(bottom) > 90 + tolerance ||
2832+
Math.abs(top) > 90 + tolerance
2833+
) {
2834+
return false;
2835+
}
2836+
if (Math.abs(left) < 0.5 && Math.abs(right) < 0.5 && Math.abs(bottom) < 0.5 && Math.abs(top) < 0.5) {
2837+
return false;
2838+
}
2839+
return true;
2840+
}
2841+
27672842
_getMapCenter(mapInfo) {
27682843
// center
27692844
let center = mapInfo.center && [mapInfo.center.x, mapInfo.center.y];

src/common/mapping/WebMapV3.js

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { FetchRequest } from '../util/FetchRequest';
55
import { getLayerCatalogRenderLayers, getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util';
66
import { SourceListModelV3 } from './utils/SourceListModelV3';
7+
import cloneDeep from 'lodash.clonedeep';
78

89
const LEGEND_RENDER_TYPE = {
910
TEXT: 'TEXT',
@@ -191,6 +192,10 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
191192
sprite
192193
});
193194
}
195+
if (this.map.addLocalIdeographFontFamily) {
196+
const fontFamilys = this._getLabelFontFamily(mapInfo);
197+
this.map.addLocalIdeographFontFamily(fontFamilys);
198+
}
194199
this._initLayers();
195200
return;
196201
}
@@ -336,6 +341,86 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
336341
return epsgCode;
337342
}
338343

344+
_getFieldCaption(msDatasetId) {
345+
const { datas = [] } = this._mapResourceInfo;
346+
let fieldCaptions = null;
347+
datas.forEach(data => {
348+
if (data.datasets) {
349+
const index = data.datasets.findIndex(dataset => dataset.msDatasetId === msDatasetId);
350+
if (index !== -1) {
351+
fieldCaptions = data.datasets[index].fieldsCaptions;
352+
}
353+
}
354+
});
355+
return fieldCaptions;
356+
}
357+
358+
_getPopupInfoContent(data, msDatasetId) {
359+
const popupInfo = cloneDeep(data);
360+
const fieldCaptions = this._getFieldCaption(msDatasetId);
361+
if (fieldCaptions) {
362+
popupInfo.elements = popupInfo.elements ? popupInfo.elements.map(item => {
363+
if (item.type === 'FIELD') {
364+
item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName;
365+
}
366+
return item;
367+
}) : [];
368+
}
369+
return popupInfo;
370+
}
371+
372+
_getPopupInfoByCatalog(catalog, res = []) {
373+
const { catalogType, children } = catalog;
374+
if(catalogType === 'group' && children) {
375+
children.forEach(child => {
376+
this._getPopupInfoByCatalog(child, res);
377+
})
378+
}
379+
if (catalogType === 'layer') {
380+
const { popupInfo, msDatasetId, title, layersContent } = catalog;
381+
if (popupInfo) {
382+
const popupInfoVal = this._getPopupInfoContent(popupInfo, msDatasetId);
383+
if (popupInfoVal) {
384+
res.push({...popupInfoVal, layerId: layersContent, title});
385+
}
386+
}
387+
}
388+
}
389+
390+
_getPopupInfos(_mapResourceInfo = this._mapResourceInfo) {
391+
const { catalogs = [] } = _mapResourceInfo;
392+
const res = [];
393+
catalogs.forEach((item) => {
394+
this._getPopupInfoByCatalog(item, res);
395+
})
396+
return res;
397+
}
398+
399+
_getLegendInfoByCatalog(catalog, res = []) {
400+
const { catalogType, children, showLegend, title, id } = catalog;
401+
if (catalogType === 'group' && children) {
402+
children.forEach(child => {
403+
this._getLegendInfoByCatalog(child, res);
404+
});
405+
}
406+
if (catalogType === 'layer') {
407+
res.push({
408+
showLegend: showLegend !== false,
409+
id: id,
410+
title: title
411+
});
412+
}
413+
}
414+
415+
_getLegendInfos(_mapResourceInfo = this._mapResourceInfo) {
416+
const { catalogs = [] } = _mapResourceInfo;
417+
const res = [];
418+
catalogs.forEach((item) => {
419+
this._getLegendInfoByCatalog(item, res);
420+
});
421+
return res;
422+
}
423+
339424
/**
340425
* @private
341426
* @function WebMapV3.prototype._initLayers
@@ -644,9 +729,9 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
644729
* @function WebMapV3.prototype._getLabelFontFamily
645730
* @description 获取图层字体类型。
646731
*/
647-
_getLabelFontFamily() {
732+
_getLabelFontFamily(mapInfo = this._mapInfo) {
648733
const fonts = ['sans-serif'];
649-
const layers = this._mapInfo.layers;
734+
const layers = mapInfo.layers;
650735
if (layers && layers.length > 0) {
651736
layers.forEach((layer) => {
652737
const textFont = (layer.layout && layer.layout['text-font']) || [];

src/common/mapping/utils/AppreciableLayerBase.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ export class AppreciableLayerBase extends Events {
9898
}
9999
}
100100

101-
setLayersVisible(layers, visibility) {
101+
setLayersVisible(layers, visibility, isSetVisible = true) {
102102
layers.forEach((layer) => {
103103
const visbleId = this._getLayerVisibleId(layer);
104-
this.layersVisibleMap.set(visbleId, visibility === 'visible');
104+
if (isSetVisible) {
105+
this.layersVisibleMap.set(visbleId, visibility === 'visible');
106+
}
105107
if (layer.CLASS_INSTANCE && layer.CLASS_INSTANCE.show && layer.CLASS_INSTANCE.hide) {
106108
visibility === 'visible' ? layer.CLASS_INSTANCE.show() : layer.CLASS_INSTANCE.hide();
107109
this.map.style.fire('data', { dataType: 'style' });

src/common/mapping/utils/SourceListModelV3.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class SourceListModelV3 extends AppreciableLayerBase {
133133
reused: layer.metadata && layer.metadata.reused
134134
};
135135
const matchProjectCatalog = projectCataglogs.find((item) => item.id === layerCatalog.id) || {};
136-
const { msDatasetId, relationMsDatasetId } = matchProjectCatalog;
136+
const { msDatasetId, relationMsDatasetId, serviceLayerId } = matchProjectCatalog;
137137
let dataSource = {};
138138
if (msDatasetId) {
139139
for (const data of datas) {
@@ -174,16 +174,33 @@ export class SourceListModelV3 extends AppreciableLayerBase {
174174
const sourceOnMap = this.map.getSource(layer.source);
175175
if (!Object.keys(dataSource).length && sourceOnMap && sourceOnMap.type === 'vector') {
176176
const matchSource = this._mapInfo.sources[layer.source] || sourceOnMap;
177-
if (matchSource.tiles && matchSource.tiles[0].includes('/rest/maps/')) {
177+
if (matchSource.tiles && matchSource.tiles.length > 0) {
178178
const tileUrl = matchSource.tiles[0];
179-
const [serverUrl, leftParts] = tileUrl.split('/rest/maps/');
180-
const [mapName] = leftParts.split('/tileFeature');
181-
dataSource.url = `${serverUrl}/rest/maps`;
182-
dataSource.mapName = mapName;
183-
dataSource.type = 'REST_MAP';
179+
switch (true) {
180+
case tileUrl.includes('/rest/maps/'): {
181+
const [serverUrl, leftParts] = tileUrl.split('/rest/maps/');
182+
const [mapName] = leftParts.split('/tileFeature');
183+
dataSource.url = `${serverUrl}/rest/maps`;
184+
dataSource.mapName = mapName;
185+
dataSource.type = 'REST_MAP';
186+
break;
187+
}
188+
case tileUrl.includes('/restjsr/v1/'): {
189+
const [serverUrl, leftParts] = tileUrl.split('/restjsr/v1/');
190+
const [mapName] = leftParts.split('/tiles/');
191+
dataSource.url = `${serverUrl}/restjsr/v1/vectortile/maps`;
192+
dataSource.mapName = mapName;
193+
dataSource.type = 'RESTJSR';
194+
break;
195+
}
196+
default: {
197+
dataSource.url = tileUrl;
198+
dataSource.type = 'VECTOR_OTHER';
199+
}
200+
}
184201
}
185202
}
186-
layerInfo.dataSource = dataSource;
203+
layerInfo.dataSource = Object.assign(dataSource, { serviceLayerId });
187204
if (this._l7LayerUtil.isL7Layer(layer)) {
188205
layerInfo.CLASS_NAME = 'L7Layer';
189206
}

src/common/util/MapExtend.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ export function createMapExtendExtending(product) {
101101
}
102102
return this;
103103
}
104-
this.style.setLayoutProperty(layerID, name, value);
105-
this._update(true);
104+
if (this.getLayer(layerID)) {
105+
this.style.setLayoutProperty(layerID, name, value);
106+
this._update(true);
107+
}
106108
return this;
107109
}
108110

0 commit comments

Comments
 (0)