From 42a5f7dbc3707c351a8c11b4a348fca9fe976d55 Mon Sep 17 00:00:00 2001 From: Peter Rushforth Date: Wed, 20 Sep 2023 17:18:40 -0400 Subject: [PATCH] Work in progress - BNG and Feature Links (BC link) seem to have mutually exclusive solutions - zoomTo after changing projection on map is necessary to inform Leaflet of the changed CRS (scale difference) but the history gets messed up and the BC link doesn't quite render (you have to generate a moveend on the map, then it'll draw). Removed a section of code from _handleLink that sets the map viewer projection when there is a single map layer and it has a different projection from that of the map BECAUSE this is handled by the MapMLLayer in selectAlternateProjection and we don't want to trigger the promise involved in disconnecting / reconnecting all map layers (happens when mapml-viewer projection attribute changed callback happens). --- src/layer.js | 29 ++++++++++++++--------------- src/mapml-viewer.js | 6 +++++- src/mapml/utils/Util.js | 6 ------ 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/layer.js b/src/layer.js index fffbac13e..7eb249ec4 100644 --- a/src/layer.js +++ b/src/layer.js @@ -158,6 +158,8 @@ export class MapLayer extends HTMLElement { opacity: this.opacity } ); + this._attachedToMap(); + this._validateDisabled(); resolve(); }) .catch((error) => { @@ -171,23 +173,20 @@ export class MapLayer extends HTMLElement { mapprojection: this.parentElement.projection, opacity: this.opacity }); - resolve(); - } - }) - .then(() => { this._attachedToMap(); this._validateDisabled(); - }) - .catch((e) => { - if (e.type === 'changeprojection') { - this.src = e.detail.href; - } else { - console.log(e); - this.dispatchEvent( - new CustomEvent('error', { detail: { target: this } }) - ); - } - }); + resolve(); + } + }).catch((e) => { + if (e.type === 'changeprojection') { + this.src = e.detail.href; + } else { + console.log(e); + this.dispatchEvent( + new CustomEvent('error', { detail: { target: this } }) + ); + } + }); } _attachedToMap() { // set i to the position of this layer element in the set of layers diff --git a/src/mapml-viewer.js b/src/mapml-viewer.js index 0b06d337a..ef983d50b 100644 --- a/src/mapml-viewer.js +++ b/src/mapml-viewer.js @@ -360,8 +360,12 @@ export class MapViewer extends HTMLElement { layersReady.push(reAttach.whenReady()); } Promise.allSettled(layersReady).then(() => { - this.zoomTo(lat, lon, zoom); + // if don't do a zoomTo, the BNG experiment ends up at zoom=5 (incorrectly) + // BUT the feature link from Canada/BC to BCTILE layer works + // can have one but not both tbd + // this._resetHistory(); + this.zoomTo(lat, lon, zoom); this._map.announceMovement.enable(); }); } diff --git a/src/mapml/utils/Util.js b/src/mapml/utils/Util.js index dbc39190d..41f68ab51 100644 --- a/src/mapml/utils/Util.js +++ b/src/mapml/utils/Util.js @@ -527,12 +527,6 @@ export var Util = { } if (!link.inPlace && newLayer) layer.whenReady().then(() => { - if ( - newLayer && - ['_parent', '_self'].includes(link.target) && - layer.parentElement.querySelectorAll('layer-').length === 1 - ) - layer.parentElement.projection = layer._layer.getProjection(); if (!layer.extent) { layer._layer._setLayerElExtent(); }