MCPcopy Create free account
hub / github.com/Maps4HTML/MapML.js / _createTemplatedLink

Method _createTemplatedLink

src/map-link.js:485–584  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

483 }
484
485 async _createTemplatedLink() {
486 // conditions check
487 // the tms and type attributes are optional, may need to be checked in future
488 this.parentExtent =
489 this.parentNode.nodeName.toUpperCase() === 'MAP-EXTENT'
490 ? this.parentNode
491 : this.parentNode.host;
492 if (this.disabled || !this.tref || !this.parentExtent) return;
493 try {
494 await this.parentExtent.whenReady();
495 await this._templateVars.inputsReady;
496 } catch (error) {
497 console.log('Error while creating templated link: ' + error);
498 return;
499 }
500 this.mapEl = this.getMapEl();
501 // create the layer type appropriate to the rel value
502 this.zIndex = Array.from(
503 this.parentExtent.querySelectorAll(
504 'map-link[rel=image],map-link[rel=tile],map-link[rel=features]'
505 )
506 ).indexOf(this);
507 if (
508 (this.rel === 'tile' && this.type === 'application/pmtiles') ||
509 this.type === 'application/vnd.mapbox-vector-tile'
510 ) {
511 let s =
512 'map-link[rel="stylesheet"][type="application/pmtiles+stylesheet"]:not([disabled])';
513 let pmtilesStylesheetLink = this.getLayerEl().src
514 ? this.closest('map-extent')?.querySelector(s) ??
515 this.getRootNode().querySelector(':host > ' + s)
516 : Util.getClosest(
517 this,
518 'map-extent:has(' +
519 s +
520 '),map-layer:has(' +
521 s +
522 '),layer-:has(' +
523 s +
524 ')'
525 )?.querySelector(s);
526 if (pmtilesStylesheetLink) {
527 await pmtilesStylesheetLink.whenReady();
528 let options = {
529 zoomBounds: this.getZoomBounds(),
530 extentBounds: this.getBounds(),
531 crs: M[this.parentExtent.units],
532 zIndex: this.zIndex,
533 pane: this.parentExtent._extentLayer.getContainer(),
534 linkEl: this,
535 pmtilesRules: pmtilesStylesheetLink?._pmtilesRules
536 };
537 this._templatedLayer = templatedPMTilesLayer(
538 this._templateVars,
539 options
540 ).addTo(this.parentExtent._extentLayer);
541 } else {
542 console.warn('Stylesheet not found for ' + this._templateVars.template);

Callers 2

connectedCallbackMethod · 0.95
_enableLinkMethod · 0.95

Calls 10

getMapElMethod · 0.95
getLayerElMethod · 0.95
getZoomBoundsMethod · 0.95
getBoundsMethod · 0.95
_setupQueryVarsMethod · 0.95
templatedPMTilesLayerFunction · 0.90
templatedTileLayerFunction · 0.90
templatedImageLayerFunction · 0.90
whenReadyMethod · 0.45

Tested by

no test coverage detected