]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.share.js
Ignore clicks on the add note button when it is disabled
[rails.git] / app / assets / javascripts / leaflet.share.js
index d43bc8ad26665dd64ead12a4962f5655a1324f12..441acfd7463929ff65bfb9aa4e3753169f96f2af 100644 (file)
@@ -206,8 +206,9 @@ L.OSM.share = function (options) {
       .on('change', update)
       .addTo(map);
 
+    marker.on('dragend', movedMarker);
+    map.on('move', movedMap);
     map.on('moveend layeradd layerremove', update);
-    marker.on('dragend', update);
 
     options.sidebar.addPane($ui);
 
@@ -216,6 +217,7 @@ L.OSM.share = function (options) {
 
     function hidden() {
       map.removeLayer(marker);
+      map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
       locationFilter.disable();
       update();
     }
@@ -235,18 +237,17 @@ L.OSM.share = function (options) {
       if ($(this).is(':checked')) {
         marker.setLatLng(map.getCenter());
         map.addLayer(marker);
+        map.options.scrollWheelZoom = map.options.doubleClickZoom = 'center';
       } else {
         map.removeLayer(marker);
+        map.options.scrollWheelZoom = map.options.doubleClickZoom = true;
       }
       update();
     }
 
     function toggleFilter() {
       if ($(this).is(':checked')) {
-        if (!locationFilter.getBounds().isValid()) {
-          locationFilter.setBounds(map.getBounds().pad(-0.2));
-        }
-
+        locationFilter.setBounds(map.getBounds().pad(-0.2));
         locationFilter.enable();
       } else {
         locationFilter.disable();
@@ -254,11 +255,26 @@ L.OSM.share = function (options) {
       update();
     }
 
-    function update() {
+    function movedMap() {
+      marker.setLatLng(map.getCenter());
+      update();
+    }
+
+    function movedMarker() {
       if (map.hasLayer(marker)) {
+        map.off('move', movedMap);
+        map.on('moveend', updateOnce);
         map.panTo(marker.getLatLng());
       }
+    }
 
+    function updateOnce() {
+      map.off('moveend', updateOnce);
+      map.on('move', movedMap);
+      update();
+    }
+
+    function update() {
       var bounds = map.getBounds();
 
       $('#link_marker')