* @private * @function WebMapV3.prototype._addLayersToMap * @description emit 图层加载成功事件。
()
| 477 | * @description emit 图层加载成功事件。 |
| 478 | */ |
| 479 | async _addLayersToMap() { |
| 480 | try { |
| 481 | const { sources, layers, layerCatalog, catalogs } = this._setUniqueId(this._mapInfo, this._mapResourceInfo); |
| 482 | Object.assign(this._mapInfo, { |
| 483 | sources, |
| 484 | layers, |
| 485 | metadata: Object.assign(this._mapInfo.metadata, { layerCatalog }) |
| 486 | }); |
| 487 | Object.assign(this._mapResourceInfo, { catalogs }); |
| 488 | const mapboxglLayers = layers.filter((layer) => !l7LayerUtil.isL7Layer(layer)); |
| 489 | const mapboxSourceIds = mapboxglLayers.map((layer) => layer.source); |
| 490 | for(const sourceId of mapboxSourceIds) { |
| 491 | const source = sources[sourceId]; |
| 492 | if(source && source.type === 'geojson' && source.data && source.data.type === 'supermap-rest-data') { |
| 493 | source.data = await l7LayerUtil.getRestDataGeojsonByWebMap(source.data, {iportalServiceProxyUrlPrefix: this.options.server, withoutFormatSuffix: true}); |
| 494 | } |
| 495 | } |
| 496 | mapboxglLayers.forEach((layer) => { |
| 497 | if (layer.metadata && layer.metadata.reused) { |
| 498 | return; |
| 499 | } |
| 500 | layer.source && !this.map.getSource(layer.source) && this.map.addSource(layer.source, sources[layer.source]); |
| 501 | // L7才会用到此属性 |
| 502 | if (layer.type === 'symbol' && layer.layout['text-z-offset'] === 0) { |
| 503 | delete layer.layout['text-z-offset']; |
| 504 | } |
| 505 | this.map.addLayer(layer); |
| 506 | }); |
| 507 | const l7Layers = layers.filter((layer) => l7LayerUtil.isL7Layer(layer)); |
| 508 | if (l7Layers.length > 0) { |
| 509 | const params = this._getAddL7LayersParams(layers, sources, l7Layers); |
| 510 | await l7LayerUtil.addL7Layers(params); |
| 511 | } |
| 512 | this._createLegendInfo(); |
| 513 | this._sendMapToUser(); |
| 514 | } catch (error) { |
| 515 | this.fire('mapcreatefailed', { error, map: this.map }); |
| 516 | console.error(error); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | _getAddL7LayersParams(layers, sources, l7Layers) { |
| 521 | return { |
no test coverage detected