]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.query.js
Update bundle
[rails.git] / app / assets / javascripts / leaflet.query.js
index 3eab9054d409f8721c45d63a77f52f8fe44d59c6..00292b74dbfbb3ef6262dd50e949ad50bbc63d32 100644 (file)
@@ -2,16 +2,35 @@ L.OSM.query = function (options) {
   var control = L.control(options);
 
   control.onAdd = function (map) {
-    var $container = $('<div>')
-      .attr('class', 'control-query');
-
-    var link = $('<a>')
-      .attr('class', 'control-button')
-      .attr('href', '#')
-      .attr('data-original-title', I18n.t('javascripts.site.queryfeature_tooltip'))
-      .html('<span class="icon query"></span>')
+    var $container = $("<div>")
+      .attr("class", "control-query");
+
+    var link = $("<a>")
+      .attr("class", "control-button")
+      .attr("href", "#")
+      .html("<span class=\"icon query\"></span>")
       .appendTo($container);
 
+    map.on("zoomend", update);
+
+    update();
+
+    function update() {
+      var wasDisabled = link.hasClass("disabled"),
+          isDisabled = map.getZoom() < 14;
+      link
+        .toggleClass("disabled", isDisabled)
+        .attr("data-bs-original-title", I18n.t(isDisabled ?
+          "javascripts.site.queryfeature_disabled_tooltip" :
+          "javascripts.site.queryfeature_tooltip"));
+
+      if (isDisabled && !wasDisabled) {
+        link.trigger("disabled");
+      } else if (wasDisabled && !isDisabled) {
+        link.trigger("enabled");
+      }
+    }
+
     return $container[0];
   };