]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/note.js.erb
Add zoom to note
[rails.git] / app / assets / javascripts / index / note.js.erb
index 9e92c9a1fb7c968e0790db391d3d1a103a41d931..9afe3b5f887bf54e58d0299ae1f3e406c8dea592 100644 (file)
@@ -1,7 +1,8 @@
 OSM.Note = function(map) {
     var noteLayer = map.noteLayer,
         content = $('#sidebar_content'),
-        page = {};
+        page = {},
+        marker;
 
     var noteIcons = {
         "new": L.icon({
@@ -67,14 +68,34 @@ OSM.Note = function(map) {
         page.load();
     };
 
-    page.load = function() {
+    page.load = function(path, id) {
+        var loadTimer = setTimeout(setLoading, 250);
         $('#sidebar_content').load(window.location.pathname + "?xhr=1", function(a, b, xhr) {
             if (xhr.getResponseHeader('X-Page-Title')) {
                 document.title = xhr.getResponseHeader('X-Page-Title');
             }
             bind();
+            clearTimeout(loadTimer);
+            clearLoading();
+
+            if (!map.hasLayer(noteLayer)) map.addLayer(noteLayer);
+            if (window.location.hash == "") map.panTo($('.details').data().coordinates.split(','));
         });
     };
 
+    page.unload = function() {
+        if (marker) map.removeLayer(marker);
+    };
+
+    function setLoading() {
+      if($('#browse_status').is(':empty')) {
+        $('#browse_status').append($('<p></p>').text(I18n.t('browse.start_rjs.loading')));
+      }
+    }
+
+    function clearLoading() {
+      $('#browse_status').empty();
+    }
+
     return page;
 };