X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/8f7f02b025f59db466fdb22ea3686cb6c5adc400..a5ee93b30110e2c89879e0a67ab2b1c18158faf2:/app/assets/javascripts/index/note.js diff --git a/app/assets/javascripts/index/note.js b/app/assets/javascripts/index/note.js index e9c51f9bf..4fb512bdd 100644 --- a/app/assets/javascripts/index/note.js +++ b/app/assets/javascripts/index/note.js @@ -22,21 +22,18 @@ OSM.Note = function (map) { page.pushstate = page.popstate = function (path, id) { OSM.loadSidebarContent(path, function () { - initialize(path, id); - var data = $(".details").data(); if (!data) return; var latLng = L.latLng(data.coordinates.split(",")); - if (!map.getBounds().contains(latLng)) moveToNote(); + initialize(path, id, map.getBounds().contains(latLng)); }); }; page.load = function (path, id) { initialize(path, id); - moveToNote(); }; - function initialize(path, id) { + function initialize(path, id, skipMoveToNote) { content.find("button[name]").on("click", function (e) { e.preventDefault(); var data = $(e.target).data(); @@ -47,8 +44,7 @@ OSM.Note = function (map) { oauth: true, success: () => { OSM.loadSidebarContent(path, () => { - initialize(path, id); - moveToNote(); + initialize(path, id, false); }); }, error: (xhr) => { @@ -77,11 +73,19 @@ OSM.Note = function (map) { var data = $(".details").data(); if (data) { + var hashParams = OSM.parseHash(window.location.hash); map.addObject({ type: "note", id: parseInt(id, 10), latLng: L.latLng(data.coordinates.split(",")), icon: noteIcons[data.status] + }, function () { + if (!hashParams.center && !skipMoveToNote) { + var latLng = L.latLng(data.coordinates.split(",")); + OSM.router.withoutMoveListener(function () { + map.setView(latLng, 15, { reset: true }); + }); + } }); } } @@ -99,18 +103,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 () { map.removeObject(); };