]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/note.js
Merge pull request #5677 from tomhughes/user-list-enhancements
[rails.git] / app / assets / javascripts / index / note.js
index e9c51f9bf1df571f6814be4999a10517975fd28b..6a0487aaac21a2622386f66257860975357b833d 100644 (file)
@@ -27,13 +27,16 @@ OSM.Note = function (map) {
       var data = $(".details").data();
       if (!data) return;
       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) {
     initialize(path, id);
-    moveToNote();
   };
 
   function initialize(path, id) {
@@ -48,7 +51,6 @@ OSM.Note = function (map) {
         success: () => {
           OSM.loadSidebarContent(path, () => {
             initialize(path, id);
-            moveToNote();
           });
         },
         error: (xhr) => {
@@ -77,11 +79,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) {
+          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 () {
     map.removeObject();
   };