]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.query.js
Merge pull request #3581 from harry-wood/discourage-note-report
[rails.git] / app / assets / javascripts / leaflet.query.js
1 L.OSM.query = function (options) {
2   var control = L.control(options);
3
4   control.onAdd = function (map) {
5     var $container = $("<div>")
6       .attr("class", "control-query");
7
8     var link = $("<a>")
9       .attr("class", "control-button")
10       .attr("href", "#")
11       .html("<span class=\"icon query\"></span>")
12       .appendTo($container);
13
14     map.on("zoomend", update);
15
16     update();
17
18     function update() {
19       var wasDisabled = link.hasClass("disabled"),
20           isDisabled = map.getZoom() < 14;
21       link
22         .toggleClass("disabled", isDisabled)
23         .attr("data-bs-original-title", I18n.t(isDisabled ?
24           "javascripts.site.queryfeature_disabled_tooltip" :
25           "javascripts.site.queryfeature_tooltip"));
26
27       if (isDisabled && !wasDisabled) {
28         link.trigger("disabled");
29       } else if (wasDisabled && !isDisabled) {
30         link.trigger("enabled");
31       }
32     }
33
34     return $container[0];
35   };
36
37   return control;
38 };