X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/078059b76b8304368fd7ddac2dd563470e83472e..979528786c2d14d16bb1ffe37843e6c674d49fb4:/app/assets/javascripts/leaflet.query.js diff --git a/app/assets/javascripts/leaflet.query.js b/app/assets/javascripts/leaflet.query.js index 3eab9054d..5f449c214 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-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]; };