MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / _createMVTBaseLayer

Method _createMVTBaseLayer

src/common/mapping/WebMapV2.js:425–478  ·  view source on GitHub ↗
(layerInfo, addedCallback)

Source from the content-addressed store, hash-verified

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;

Callers 1

_initBaseLayerMethod · 0.95

Calls 11

_getVisibilityMethod · 0.95
isAbsoluteURLMethod · 0.95
relative2absoluteMethod · 0.95
_setCacheLayerMethod · 0.95
indexOfMethod · 0.80
getMapBoxStyleMethod · 0.80
forEachMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
getSourceMethod · 0.45
fireMethod · 0.45

Tested by

no test coverage detected