Skip to content

Commit 1faeec0

Browse files
yhy0217prushforth
authored andcommitted
move the zoomTo logic before new layer is added and the attributeChangedCallback is triggered, avoiding the wrong map lat,lng and zoom information read in attributeChangedCallback closure
1 parent 812ed29 commit 1faeec0

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/mapml/utils/Util.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,25 +505,34 @@ export var Util = {
505505
if (link.type === 'text/html') {
506506
window.open(link.url);
507507
} else {
508-
map.options.mapEl.appendChild(layer);
509508
newLayer = true;
509+
if (!link.inPlace && zoomTo) {
510+
updateMapZoomTo(zoomTo);
511+
}
512+
map.options.mapEl.appendChild(layer);
510513
}
511514
break;
512515
case '_parent':
516+
newLayer = true;
517+
if (!link.inPlace && zoomTo) {
518+
updateMapZoomTo(zoomTo);
519+
}
513520
for (let l of map.options.mapEl.querySelectorAll('layer-'))
514521
if (l._layer !== leafletLayer) map.options.mapEl.removeChild(l);
515522
map.options.mapEl.appendChild(layer);
516523
map.options.mapEl.removeChild(leafletLayer._layerEl);
517-
newLayer = true;
518524
break;
519525
case '_top':
520526
window.location.href = link.url;
521527
break;
522528
default:
529+
newLayer = true;
530+
if (!link.inPlace && zoomTo) {
531+
updateMapZoomTo(zoomTo);
532+
}
523533
opacity = leafletLayer._layerEl.opacity;
524534
leafletLayer._layerEl.insertAdjacentElement('beforebegin', layer);
525535
map.options.mapEl.removeChild(leafletLayer._layerEl);
526-
newLayer = true;
527536
}
528537
if (!link.inPlace && newLayer)
529538
layer.whenReady().then(() => {
@@ -544,6 +553,12 @@ export var Util = {
544553
);
545554
if (opacity) layer.opacity = opacity;
546555
}
556+
557+
function updateMapZoomTo(zoomTo) {
558+
map.options.mapEl.lat = +zoomTo.lat;
559+
map.options.mapEl.lon = +zoomTo.lng;
560+
map.options.mapEl.zoom = +zoomTo.z;
561+
}
547562
},
548563
getBounds: function (mapml) {
549564
if (!mapml) return null;

0 commit comments

Comments
 (0)