fix zoom resetting wrongly when switching background mid-transition

see https://github.com/openstreetmap/iD/issues/10700#issuecomment-2832010049
This commit is contained in:
Martin Raifer
2025-04-26 20:47:50 +02:00
parent 8c421b615d
commit fa91fe7c0d
12 changed files with 57 additions and 76 deletions

View File

@@ -109,7 +109,7 @@ export function behaviorHash(context) {
// Update the URL hash without affecting the browser navigation stack,
// though unavoidably creating a browser history entry
window.history.replaceState(null, computedTitle(false /* includeChangeCount */), latestHash);
window.history.replaceState(null, '', latestHash);
// set the title we want displayed for the browser tab/window
updateTitle(true /* includeChangeCount */);

View File

@@ -225,9 +225,7 @@ export function rendererBackground(context) {
delete hash.offset;
}
if (!window.mocha) {
window.location.replace('#' + utilQsString(hash, true));
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
let imageryUsed = [];
let photoOverlaysUsed = [];

View File

@@ -54,17 +54,15 @@ export function rendererFeatures(context) {
function update() {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
var disabled = features.disabled();
if (disabled.length) {
hash.disable_features = disabled.join(',');
} else {
delete hash.disable_features;
}
window.location.replace('#' + utilQsString(hash, true));
prefs('disabled-features', disabled.join(','));
const hash = utilStringQs(window.location.hash);
const disabled = features.disabled();
if (disabled.length) {
hash.disable_features = disabled.join(',');
} else {
delete hash.disable_features;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
prefs('disabled-features', disabled.join(','));
_hidden = features.hidden();
dispatch.call('change');
dispatch.call('redraw');

View File

@@ -18,8 +18,6 @@ export function rendererPhotos(context) {
function photos() {}
function updateStorage() {
if (window.mocha) return;
var hash = utilStringQs(window.location.hash);
var enabled = context.layers().all().filter(function(d) {
return _layerIDs.indexOf(d.id) !== -1 && d.layer && d.layer.supported() && d.layer.enabled();
@@ -31,7 +29,7 @@ export function rendererPhotos(context) {
} else {
delete hash.photo_overlay;
}
window.location.replace('#' + utilQsString(hash, true));
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
}
/**
@@ -150,17 +148,15 @@ export function rendererPhotos(context) {
* @param {string} property Name of the value
*/
function setUrlFilterValue(property, val) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (val) {
if (hash[property] === val) return;
hash[property] = val;
} else {
if (!(property in hash)) return;
delete hash[property];
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (val) {
if (hash[property] === val) return;
hash[property] = val;
} else {
if (!(property in hash)) return;
delete hash[property];
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
}
function showsLayer(id) {

View File

@@ -554,15 +554,13 @@ export default {
updateUrlImage: function(imageKey) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'kartaview/' + imageKey;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'kartaview/' + imageKey;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},

View File

@@ -308,15 +308,13 @@ export default {
},
updateUrlImage: function(imageKey) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'mapilio/' + imageKey;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'mapilio/' + imageKey;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},
initViewer: function () {

View File

@@ -524,15 +524,13 @@ export default {
// Update the URL with current image id
updateUrlImage: function(imageId) {
if (!window.mocha) {
const hash = utilStringQs(window.location.hash);
if (imageId) {
hash.photo = 'mapillary/' + imageId;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (imageId) {
hash.photo = 'mapillary/' + imageId;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},

View File

@@ -419,15 +419,13 @@ export default {
* @param {*} imageKey
*/
updateUrlImage: function(imageKey) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'panoramax/' + imageKey;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'panoramax/' + imageKey;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},
/**

View File

@@ -905,15 +905,13 @@ export default {
updateUrlImage: function(imageKey) {
if (!window.mocha) {
var hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'streetside/' + imageKey;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (imageKey) {
hash.photo = 'streetside/' + imageKey;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},

View File

@@ -584,15 +584,13 @@ export default {
},
updateUrlImage: function (key) {
if (!window.mocha) {
const hash = utilStringQs(window.location.hash);
if (key) {
hash.photo = 'vegbilder/' + key;
} else {
delete hash.photo;
}
window.location.replace('#' + utilQsString(hash, true));
const hash = utilStringQs(window.location.hash);
if (key) {
hash.photo = 'vegbilder/' + key;
} else {
delete hash.photo;
}
window.history.replaceState(null, '', '#' + utilQsString(hash, true));
},
validHere: function(extent) {

View File

@@ -163,7 +163,7 @@ export function uiIntro(context) {
overlays.forEach(d => context.background().toggleOverlayLayer(d));
if (history) { context.history().fromJSON(history, false); }
context.map().centerZoom(center, zoom);
window.location.replace(hash);
window.history.replaceState(null, '', hash);
context.inIntro(false);
});