| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b7168c7 commit 1515af9
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,7 +2,7 @@ | |||
| 2 | 2 | * This program are made available under the terms of the Apache License, Version 2.0 | |
| 3 | 3 | * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/ | |
| 4 | 4 | import { FetchRequest } from '../util/FetchRequest'; | |
| 5 | - import { getLayerInfosFromCatalogs, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util'; | ||
| 5 | + import { getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util'; | ||
| 6 | 6 | import { SourceListModelV3 } from './utils/SourceListModelV3'; | |
| 7 | 7 | ||
| 8 | 8 | const LEGEND_RENDER_TYPE = { | |
@@ -710,9 +710,7 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe | |||
| 710 | 710 | if (!renderer) { | |
| 711 | 711 | continue; | |
| 712 | 712 | } | |
| 713 | - const layerFromMapInfo = this._mapInfo.layers.find((item) => { | ||
| 714 | - return item.id === layer.id; | ||
| 715 | - }); | ||
| 713 | + const layerFromMapInfo = getMainLayerFromCatalog(layer.layersContent, layer.id, this._mapInfo.layers); | ||
| 716 | 714 | let themeField; | |
| 717 | 715 | const sourceInfo = this._mapInfo.sources[layerFromMapInfo.source]; | |
| 718 | 716 | if ('clusterField' in sourceInfo) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | ||
| 2 | 2 | import { AppreciableLayerBase } from './AppreciableLayerBase'; | |
| 3 | - import { getLayerInfosFromCatalogs } from './util'; | ||
| 3 | + import { getLayerCatalogRenderLayers, getLayerInfosFromCatalogs, getMainLayerFromCatalog } from './util'; | ||
| 4 | 4 | ||
| 5 | 5 | export class SourceListModelV3 extends AppreciableLayerBase { | |
| 6 | 6 | constructor(options = {}) { | |
@@ -50,7 +50,7 @@ export class SourceListModelV3 extends AppreciableLayerBase { | |||
| 50 | 50 | _createSourceCatalogs(catalogs, appreciableLayers) { | |
| 51 | 51 | const formatCatalogs = catalogs.map((catalog) => { | |
| 52 | 52 | let formatItem; | |
| 53 | - const { id, title = id, type, visible, children } = catalog; | ||
| 53 | + const { id, title = id, type, visible, children, parts } = catalog; | ||
| 54 | 54 | if (type === 'group') { | |
| 55 | 55 | formatItem = { | |
| 56 | 56 | children: this._createSourceCatalogs(children, appreciableLayers), | |
@@ -60,7 +60,8 @@ export class SourceListModelV3 extends AppreciableLayerBase { | |||
| 60 | 60 | visible | |
| 61 | 61 | }; | |
| 62 | 62 | } else { | |
| 63 | - const matchLayer = appreciableLayers.find((layer) => layer.id === id); | ||
| 63 | + const renderLayers = getLayerCatalogRenderLayers(parts, id, this._mapInfo.layers); | ||
| 64 | + const matchLayer = appreciableLayers.find((layer) => layer.id === renderLayers[0]); | ||
| 64 | 65 | this.removeLayerExtralFields([matchLayer]); | |
| 65 | 66 | formatItem = Object.assign({}, matchLayer); | |
| 66 | 67 | } | |
@@ -75,8 +76,9 @@ export class SourceListModelV3 extends AppreciableLayerBase { | |||
| 75 | 76 | const metadataCatalogs = getLayerInfosFromCatalogs(this._mapInfo.metadata.layerCatalog); | |
| 76 | 77 | const l7MarkerLayers = this._l7LayerUtil.getL7MarkerLayers(); | |
| 77 | 78 | const layerDatas = metadataCatalogs.map(layerCatalog => { | |
| 78 | - const layer = this._mapInfo.layers.find(item => item.id === layerCatalog.id) || {}; | ||
| 79 | - const layerInfo = { id: layer.id, title: layerCatalog.title, renderLayers: this._getRenderLayers(layerCatalog.parts, layerCatalog.id), reused: layer.metadata && layer.metadata.reused }; | ||
| 79 | + const renderLayers = getLayerCatalogRenderLayers(layerCatalog.parts, layerCatalog.id, this._mapInfo.layers); | ||
| 80 | + const layer = getMainLayerFromCatalog(layerCatalog.parts, layerCatalog.id, this._mapInfo.layers); | ||
| 81 | + const layerInfo = { id: layer.id, title: layerCatalog.title, renderLayers, reused: layer.metadata && layer.metadata.reused }; | ||
| 80 | 82 | const matchProjectCatalog = projectCataglogs.find((item) => item.id === layerCatalog.id) || {}; | |
| 81 | 83 | const { msDatasetId } = matchProjectCatalog; | |
| 82 | 84 | let dataSource = {}; | |
@@ -133,16 +135,4 @@ export class SourceListModelV3 extends AppreciableLayerBase { | |||
| 133 | 135 | layerDatas.reverse(); | |
| 134 | 136 | return layerDatas; | |
| 135 | 137 | } | |
| 136 | - | ||
| 137 | - _getRenderLayers(layerIds, layerId) { | ||
| 138 | - if (layerIds) { | ||
| 139 | - if (layerIds.includes(layerId)) { | ||
| 140 | - return layerIds; | ||
| 141 | - } else { | ||
| 142 | - return [layerId, ...layerIds]; | ||
| 143 | - } | ||
| 144 | - } else { | ||
| 145 | - return [layerId]; | ||
| 146 | - } | ||
| 147 | - } | ||
| 148 | 138 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,4 +185,18 @@ export function createAppreciableLayerId(layer) { | |||
| 185 | 185 | // 针对 MapboxStyle 或者其它额外的 layer | |
| 186 | 186 | // type: background 和某些 overlaymanager layers 只有 id | |
| 187 | 187 | return layer.sourceLayer || layer.source || layer.id; | |
| 188 | + } | ||
| 189 | + | ||
| 190 | + export function getLayerCatalogRenderLayers(parts, catalogId, layersOnMap) { | ||
| 191 | + // ms 3.0.5以下的版本 layerCatalogs layersContent/parts 不包括自身的上图layerid 只包含复合图层的id | ||
| 192 | + const renderLayers = layersOnMap.some(item => item.id === catalogId) ? [catalogId] : []; | ||
| 193 | + if (parts) { | ||
| 194 | + renderLayers.push(...parts); | ||
| 195 | + } | ||
| 196 | + return Array.from(new Set(renderLayers)).filter(item => !!item); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + export function getMainLayerFromCatalog(layerParts, catalogId, layersOnMap) { | ||
| 200 | + const renderLayers = getLayerCatalogRenderLayers(layerParts, catalogId, layersOnMap); | ||
| 201 | + return layersOnMap.find(item => item.id === renderLayers[0]); | ||
| 188 | 202 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -271,6 +271,66 @@ describe('SourceListV3', () => { | |||
| 271 | 271 | done(); | |
| 272 | 272 | }); | |
| 273 | 273 | ||
| 274 | + it('layerCatalog parts not include self layer and ui id is layerId on Map', (done) => { | ||
| 275 | + const mapInfo = JSON.parse(mapstudioWebMap_symbol); | ||
| 276 | + const sourceListModel = new SourceListModelV3({ | ||
| 277 | + map, | ||
| 278 | + mapInfo, | ||
| 279 | + mapResourceInfo: {}, | ||
| 280 | + legendList: [], | ||
| 281 | + l7LayerUtil: { | ||
| 282 | + isL7Layer, | ||
| 283 | + getL7MarkerLayers: () => ({}) | ||
| 284 | + } | ||
| 285 | + }); | ||
| 286 | + const layerList = sourceListModel.getLayerCatalog(); | ||
| 287 | + expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 4); | ||
| 288 | + const selfIds = mapInfo.metadata.layerCatalog.map(item => item.id); | ||
| 289 | + const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id)); | ||
| 290 | + expect(selfLayerCatalogs.some(layer => !layer.renderLayers.includes(layer.id))).toBe(false); | ||
| 291 | + done(); | ||
| 292 | + }); | ||
| 293 | + | ||
| 294 | + it('layerCatalog parts include self layer', (done) => { | ||
| 295 | + const mapInfo = JSON.parse(mapstudioWebMap_labelLegend); | ||
| 296 | + const sourceListModel = new SourceListModelV3({ | ||
| 297 | + map, | ||
| 298 | + mapInfo, | ||
| 299 | + mapResourceInfo: {}, | ||
| 300 | + legendList: [], | ||
| 301 | + l7LayerUtil: { | ||
| 302 | + isL7Layer, | ||
| 303 | + getL7MarkerLayers: () => ({}) | ||
| 304 | + } | ||
| 305 | + }); | ||
| 306 | + const layerList = sourceListModel.getLayerCatalog(); | ||
| 307 | + expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 3); | ||
| 308 | + const selfIds = mapInfo.metadata.layerCatalog.map(item => item.id); | ||
| 309 | + const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id)); | ||
| 310 | + expect(selfLayerCatalogs.some(layer => !layer.renderLayers.includes(layer.id))).toBe(false); | ||
| 311 | + done(); | ||
| 312 | + }); | ||
| 313 | + | ||
| 314 | + it('layerCatalog parts not include self layer and ui id is not layerId on Map', (done) => { | ||
| 315 | + const mapInfo = JSON.parse(mapstudioWebMap_separate_layerCatalogId); | ||
| 316 | + const sourceListModel = new SourceListModelV3({ | ||
| 317 | + map, | ||
| 318 | + mapInfo, | ||
| 319 | + mapResourceInfo: {}, | ||
| 320 | + legendList: [], | ||
| 321 | + l7LayerUtil: { | ||
| 322 | + isL7Layer, | ||
| 323 | + getL7MarkerLayers: () => ({}) | ||
| 324 | + } | ||
| 325 | + }); | ||
| 326 | + const layerList = sourceListModel.getLayerCatalog(); | ||
| 327 | + expect(layerList.length).toBe(mapInfo.metadata.layerCatalog.length + 4); | ||
| 328 | + const selfIds = mapInfo.metadata.layerCatalog.filter(item => item.parts).map(item => item.id); | ||
| 329 | + const selfLayerCatalogs = layerList.filter(layer => selfIds.includes(layer.id)); | ||
| 330 | + expect(selfLayerCatalogs.some(layer => layer.renderLayers.includes(layer.id))).toBe(false); | ||
| 331 | + done(); | ||
| 332 | + }); | ||
| 333 | + | ||
| 274 | 334 | it('destroy', (done) => { | |
| 275 | 335 | const mapInfo = JSON.parse(mapstudioWebMap_chart); | |
| 276 | 336 | const sourceListModel = new SourceListModelV3({ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1370,4 +1370,42 @@ describe('mapboxgl-webmap3.0', () => { | |||
| 1370 | 1370 | mapstudioWebmap.setLayersVisible([layers[0]], 'visible'); | |
| 1371 | 1371 | }); | |
| 1372 | 1372 | }); | |
| 1373 | + | ||
| 1374 | + it('layerCatalog separate ui id and render id', (done) => { | ||
| 1375 | + spyOn(MapManagerUtil, 'default').and.callFake(mbglmap); | ||
| 1376 | + spyOn(FetchRequest, 'get').and.callFake((url) => { | ||
| 1377 | + if (url.indexOf('web/config/portal.json') > -1) { | ||
| 1378 | + return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy))); | ||
| 1379 | + } | ||
| 1380 | + if (url.indexOf('map.json') > -1) { | ||
| 1381 | + return Promise.resolve(new Response(mapstudioWebMap_separate_layerCatalogId)); | ||
| 1382 | + } | ||
| 1383 | + if (url.indexOf('617580084.json') > -1) { | ||
| 1384 | + return Promise.resolve(new Response(msProjectINfo_separate_layerCatalogId)); | ||
| 1385 | + } | ||
| 1386 | + if (url.indexOf('/sprite') > -1) { | ||
| 1387 | + return Promise.resolve(new Response(msSpriteInfo)); | ||
| 1388 | + } | ||
| 1389 | + return Promise.resolve(); | ||
| 1390 | + }); | ||
| 1391 | + mapstudioWebmap = new WebMap(id, { | ||
| 1392 | + server: server | ||
| 1393 | + }); | ||
| 1394 | + | ||
| 1395 | + mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => { | ||
| 1396 | + expect(map).not.toBeUndefined(); | ||
| 1397 | + expect(mapstudioWebmap.map).toEqual(map); | ||
| 1398 | + const style = map.getStyle(); | ||
| 1399 | + const webMapV3 = mapstudioWebmap._getWebMapInstance(); | ||
| 1400 | + const mapInfo = JSON.parse(mapstudioWebMap_separate_layerCatalogId); | ||
| 1401 | + expect(style.layers.length).toBe(mapInfo.layers.length); | ||
| 1402 | + expect(webMapV3.getLegends().length).not.toBe(0); | ||
| 1403 | + const layerCatalogs = webMapV3.getLayerCatalog(); | ||
| 1404 | + expect(layerCatalogs.length).not.toBe(0); | ||
| 1405 | + expect(layerCatalogs.length).toBe(mapInfo.metadata.layerCatalog.length); | ||
| 1406 | + const appreciableLayers = webMapV3.getLayers(); | ||
| 1407 | + expect(layerCatalogs.length).toBe(appreciableLayers.length); | ||
| 1408 | + done(); | ||
| 1409 | + }); | ||
| 1410 | + }); | ||
| 1373 | 1411 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1323,4 +1323,42 @@ describe('maplibregl-webmap3.0', () => { | |||
| 1323 | 1323 | mapstudioWebmap.setLayersVisible([layers[0]], 'visible'); | |
| 1324 | 1324 | }); | |
| 1325 | 1325 | }); | |
| 1326 | + | ||
| 1327 | + it('layerCatalog separate ui id and render id', (done) => { | ||
| 1328 | + spyOn(MapManagerUtil, 'default').and.callFake(mbglmap); | ||
| 1329 | + spyOn(FetchRequest, 'get').and.callFake((url) => { | ||
| 1330 | + if (url.indexOf('web/config/portal.json') > -1) { | ||
| 1331 | + return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy))); | ||
| 1332 | + } | ||
| 1333 | + if (url.indexOf('map.json') > -1) { | ||
| 1334 | + return Promise.resolve(new Response(mapstudioWebMap_separate_layerCatalogId)); | ||
| 1335 | + } | ||
| 1336 | + if (url.indexOf('617580084.json') > -1) { | ||
| 1337 | + return Promise.resolve(new Response(msProjectINfo_separate_layerCatalogId)); | ||
| 1338 | + } | ||
| 1339 | + if (url.indexOf('/sprite') > -1) { | ||
| 1340 | + return Promise.resolve(new Response(msSpriteInfo)); | ||
| 1341 | + } | ||
| 1342 | + return Promise.resolve(); | ||
| 1343 | + }); | ||
| 1344 | + mapstudioWebmap = new WebMap(id, { | ||
| 1345 | + server: server | ||
| 1346 | + }); | ||
| 1347 | + | ||
| 1348 | + mapstudioWebmap.on('mapcreatesucceeded', ({ map }) => { | ||
| 1349 | + expect(map).not.toBeUndefined(); | ||
| 1350 | + expect(mapstudioWebmap.map).toEqual(map); | ||
| 1351 | + const style = map.getStyle(); | ||
| 1352 | + const webMapV3 = mapstudioWebmap._getWebMapInstance(); | ||
| 1353 | + const mapInfo = JSON.parse(mapstudioWebMap_separate_layerCatalogId); | ||
| 1354 | + expect(style.layers.length).toBe(mapInfo.layers.length); | ||
| 1355 | + expect(webMapV3.getLegends().length).not.toBe(0); | ||
| 1356 | + const layerCatalogs = webMapV3.getLayerCatalog(); | ||
| 1357 | + expect(layerCatalogs.length).not.toBe(0); | ||
| 1358 | + expect(layerCatalogs.length).toBe(mapInfo.metadata.layerCatalog.length); | ||
| 1359 | + const appreciableLayers = webMapV3.getLayers(); | ||
| 1360 | + expect(layerCatalogs.length).toBe(appreciableLayers.length); | ||
| 1361 | + done(); | ||
| 1362 | + }); | ||
| 1363 | + }); | ||
| 1326 | 1364 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments