fix map panning to objects when url hash is not empty but has no map location, fixes #865

This commit is contained in:
Martin Raifer 2025-02-15 16:54:24 +01:00
parent 8ecbe9b07d
commit b14965e4b2
No known key found for this signature in database
GPG key ID: 3CD561F7B1C461BD
3 changed files with 17 additions and 17 deletions

View file

@ -309,8 +309,9 @@ $(document).ready(function () {
}; };
function addObject(type, id, center) { function addObject(type, id, center) {
var hashParams = OSM.parseHash(window.location.hash);
map.addObject({ type: type, id: parseInt(id, 10) }, function (bounds) { map.addObject({ type: type, id: parseInt(id, 10) }, function (bounds) {
if (!window.location.hash && bounds.isValid() && if (!hashParams.center && bounds.isValid() &&
(center || !map.getBounds().contains(bounds))) { (center || !map.getBounds().contains(bounds))) {
OSM.router.withoutMoveListener(function () { OSM.router.withoutMoveListener(function () {
map.fitBounds(bounds); map.fitBounds(bounds);

View file

@ -12,9 +12,10 @@ OSM.Changeset = function (map) {
const changesetData = content.find("[data-changeset]").data("changeset"); const changesetData = content.find("[data-changeset]").data("changeset");
changesetData.type = "changeset"; changesetData.type = "changeset";
var hashParams = OSM.parseHash(window.location.hash);
initialize(); initialize();
map.addObject(changesetData, function (bounds) { map.addObject(changesetData, function (bounds) {
if (!window.location.hash && bounds.isValid()) { if (!hashParams.center && bounds.isValid()) {
OSM.router.withoutMoveListener(function () { OSM.router.withoutMoveListener(function () {
map.fitBounds(bounds); map.fitBounds(bounds);
}); });

View file

@ -27,13 +27,16 @@ OSM.Note = function (map) {
var data = $(".details").data(); var data = $(".details").data();
if (!data) return; if (!data) return;
var latLng = L.latLng(data.coordinates.split(",")); var latLng = L.latLng(data.coordinates.split(","));
if (!map.getBounds().contains(latLng)) moveToNote(); if (!map.getBounds().contains(latLng)) {
OSM.router.withoutMoveListener(function () {
map.setView(latLng, 15, { reset: true });
});
}
}); });
}; };
page.load = function (path, id) { page.load = function (path, id) {
initialize(path, id); initialize(path, id);
moveToNote();
}; };
function initialize(path, id) { function initialize(path, id) {
@ -48,7 +51,6 @@ OSM.Note = function (map) {
success: () => { success: () => {
OSM.loadSidebarContent(path, () => { OSM.loadSidebarContent(path, () => {
initialize(path, id); initialize(path, id);
moveToNote();
}); });
}, },
error: (xhr) => { error: (xhr) => {
@ -77,11 +79,19 @@ OSM.Note = function (map) {
var data = $(".details").data(); var data = $(".details").data();
if (data) { if (data) {
var hashParams = OSM.parseHash(window.location.hash);
map.addObject({ map.addObject({
type: "note", type: "note",
id: parseInt(id, 10), id: parseInt(id, 10),
latLng: L.latLng(data.coordinates.split(",")), latLng: L.latLng(data.coordinates.split(",")),
icon: noteIcons[data.status] icon: noteIcons[data.status]
}, function () {
if (!hashParams.center) {
var latLng = L.latLng(data.coordinates.split(","));
OSM.router.withoutMoveListener(function () {
map.setView(latLng, 15, { reset: true });
});
}
}); });
} }
} }
@ -99,18 +109,6 @@ OSM.Note = function (map) {
} }
} }
function moveToNote() {
var data = $(".details").data();
if (!data) return;
var latLng = L.latLng(data.coordinates.split(","));
if (!window.location.hash || window.location.hash.match(/^#?c[0-9]+$/)) {
OSM.router.withoutMoveListener(function () {
map.setView(latLng, 15, { reset: true });
});
}
}
page.unload = function () { page.unload = function () {
map.removeObject(); map.removeObject();
}; };