X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/078059b76b8304368fd7ddac2dd563470e83472e..8919c8c40416a70e1a5516f03e2628c5dd380d40:/app/assets/javascripts/leaflet.query.js diff --git a/app/assets/javascripts/leaflet.query.js b/app/assets/javascripts/leaflet.query.js index 3eab9054d..00292b74d 100644 --- a/app/assets/javascripts/leaflet.query.js +++ b/app/assets/javascripts/leaflet.query.js @@ -2,16 +2,35 @@ L.OSM.query = function (options) { var control = L.control(options); control.onAdd = function (map) { - var $container = $('
') - .attr('class', 'control-query'); - - var link = $('') - .attr('class', 'control-button') - .attr('href', '#') - .attr('data-original-title', I18n.t('javascripts.site.queryfeature_tooltip')) - .html('') + var $container = $("
") + .attr("class", "control-query"); + + var link = $("") + .attr("class", "control-button") + .attr("href", "#") + .html("") .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]; };