(layerInfo, addedCallback)
| 423 | } |
| 424 | |
| 425 | _createMVTBaseLayer(layerInfo, addedCallback) { |
| 426 | let url = layerInfo.dataSource.url; |
| 427 | if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) { |
| 428 | url = Util.urlPathAppend(url, '/style.json'); |
| 429 | } |
| 430 | const withoutFormatSuffix = url.indexOf('/restjsr/') === -1; |
| 431 | this.webMapService |
| 432 | .getMapBoxStyle(url, withoutFormatSuffix) |
| 433 | .then( |
| 434 | (style) => { |
| 435 | const sourceIds = Object.keys(style.sources); |
| 436 | if (sourceIds.some((id) => this.map.getSource(id))) { |
| 437 | this.fire('layerorsourcenameduplicated', {}); |
| 438 | addedCallback && addedCallback(); |
| 439 | return; |
| 440 | } |
| 441 | style.layers.forEach(layer => { |
| 442 | layer.layout && (layer.layout.visibility = this._getVisibility(layerInfo.visible)); |
| 443 | }); |
| 444 | if (layerInfo.dataSource.type === 'ARCGIS_VECTORTILE') { |
| 445 | let paramUrl = url.split('?')[1]; |
| 446 | Object.keys(style.sources).forEach((key) => { |
| 447 | Object.keys(style.sources[key]).forEach((fieldName) => { |
| 448 | if (fieldName === 'url') { |
| 449 | if (typeof style.sources[key][fieldName] === 'string' && !this.isAbsoluteURL(style.sources[key][fieldName])) { |
| 450 | style.sources[key][fieldName] = this.relative2absolute(style.sources[key][fieldName], url); |
| 451 | } |
| 452 | style.sources[key][fieldName] = style.sources[key][fieldName] + (paramUrl ? '?' + paramUrl + '&f=json' : '?f=json'); |
| 453 | } |
| 454 | }); |
| 455 | }); |
| 456 | } |
| 457 | this.map.addStyle(style, undefined, undefined, undefined, url); |
| 458 | const layerIds = []; |
| 459 | style.layers.forEach((item) => { |
| 460 | if (item.type !== 'background') { |
| 461 | layerIds.push(item.id); |
| 462 | } |
| 463 | }); |
| 464 | this._setCacheLayer({ |
| 465 | parentLayerId: layerInfo.layerID || layerInfo.name, |
| 466 | subRenderLayers: layerIds.map((layerId) => ({ layerId })) |
| 467 | }); |
| 468 | addedCallback && addedCallback(); |
| 469 | }, |
| 470 | (error) => { |
| 471 | addedCallback && addedCallback(); |
| 472 | throw new Error(error); |
| 473 | } |
| 474 | ) |
| 475 | .catch((error) => { |
| 476 | this.fire('layercreatefailed', { error, layer: layerInfo, map: this.map }); |
| 477 | }); |
| 478 | } |
| 479 | |
| 480 | _initBaseLayer(mapInfo, addedCallback) { |
| 481 | const layerInfo = mapInfo.baseLayer || mapInfo; |
no test coverage detected