* @private * @function WebMapV3.prototype._setUniqueId * @description 返回唯一 id 的 sources 和 layers。 * @param {Object} mapInfo - map 信息。
(style, projectInfo)
| 538 | * @param {Object} mapInfo - map 信息。 |
| 539 | */ |
| 540 | _setUniqueId(style, projectInfo) { |
| 541 | const unspportedLayers = this._handleUnSupportedLayers(style); |
| 542 | const layersToMap = JSON.parse(JSON.stringify(style.layers)).filter((layer) => { |
| 543 | return !unspportedLayers.includes(layer.id); |
| 544 | }); |
| 545 | const nextSources = {}; |
| 546 | const sourcesIdChangedMap = {}; |
| 547 | const layerIdToChange = []; |
| 548 | const timestamp = `_${+new Date()}`; |
| 549 | for (const sourceId in style.sources) { |
| 550 | let nextSourceId = sourceId; |
| 551 | if (this.map.getSource(sourceId)) { |
| 552 | nextSourceId = sourceId + timestamp; |
| 553 | } |
| 554 | sourcesIdChangedMap[nextSourceId] = sourceId; |
| 555 | nextSources[nextSourceId] = style.sources[sourceId]; |
| 556 | for (const layer of layersToMap) { |
| 557 | if (layer.source === sourceId) { |
| 558 | layer.source = nextSourceId; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | for (const layer of layersToMap) { |
| 563 | const originId = layer.id; |
| 564 | const existLayer = this._getLayerOnMap(layer.id); |
| 565 | if (existLayer) { |
| 566 | if ( |
| 567 | this.options.checkSameLayer && |
| 568 | isSameRasterLayer(nextSources[layer.source], this.map.getSource(existLayer.source)) |
| 569 | ) { |
| 570 | layer.metadata = layer.metadata || {}; |
| 571 | layer.metadata.reused = true; |
| 572 | layer.source = sourcesIdChangedMap[layer.source]; |
| 573 | } else { |
| 574 | const layerId = layer.id + timestamp; |
| 575 | layer.id = layerId; |
| 576 | } |
| 577 | } |
| 578 | layerIdToChange.push({ originId: originId, renderId: layer.id, id: originId }); |
| 579 | } |
| 580 | const layerCatalogFromMapJson = JSON.parse(JSON.stringify(style.metadata.layerCatalog), 'parts'); |
| 581 | this._updateLayerCatalogsId({ |
| 582 | loopData: JSON.parse(JSON.stringify(layerCatalogFromMapJson)), |
| 583 | catalogs: layerCatalogFromMapJson, |
| 584 | layerIdMapList: layerIdToChange, |
| 585 | unspportedLayers |
| 586 | }); |
| 587 | const catalogsFromProjectInfo = JSON.parse(JSON.stringify(projectInfo.catalogs || [])); |
| 588 | this._updateLayerCatalogsId({ |
| 589 | loopData: JSON.parse(JSON.stringify(catalogsFromProjectInfo)), |
| 590 | catalogs: catalogsFromProjectInfo, |
| 591 | layerIdMapList: layerIdToChange, |
| 592 | catalogTypeField: 'catalogType', |
| 593 | layerIdsField: 'layersContent', |
| 594 | unspportedLayers |
| 595 | }); |
| 596 | return { |
| 597 | sources: nextSources, |
no test coverage detected