]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.query.js
Avoid highlighting multiple changesets in history sidebar
[rails.git] / app / assets / javascripts / leaflet.query.js
1 L.OSM.query = function (options) {
2   const control = L.control(options);
3
4   control.onAdd = function (map) {
5     const $container = $("<div>")
6       .attr("class", "control-query");
7
8     const link = $("<a>")
9       .attr("class", "control-button")
10       .attr("href", "#")
11       .appendTo($container);
12
13     $(L.SVG.create("svg"))
14       .append($(L.SVG.create("use")).attr("href", "#icon-query"))
15       .attr("class", "h-100 w-100")
16       .appendTo(link);
17
18     map.on("zoomend", update);
19
20     function update() {
21       const wasDisabled = link.hasClass("disabled"),
22             isDisabled = map.getZoom() < 14;
23       link
24         .toggleClass("disabled", isDisabled)
25         .attr("data-bs-original-title", OSM.i18n.t(isDisabled ?
26           "javascripts.site.queryfeature_disabled_tooltip" :
27           "javascripts.site.queryfeature_tooltip"));
28       if (isDisabled === wasDisabled) return;
29       link.trigger(isDisabled ? "disabled" : "enabled");
30     }
31
32     update();
33
34     return $container[0];
35   };
36
37   return control;
38 };