]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.layers.js
Restore the duplicate search form in the header
[rails.git] / app / assets / javascripts / leaflet.layers.js
index 7703529b8799e35d94b06ddefc1fb9d4e60705d1..bb00f716c8c28d969c3f90c05db97970b4f1aabb 100644 (file)
@@ -132,15 +132,18 @@ L.OSM.layers = function(options) {
         var label = $('<label>')
           .appendTo(item);
 
+        var checked = map.hasLayer(layer);
+
         var input = $('<input>')
           .attr('type', 'checkbox')
-          .prop('checked', map.hasLayer(layer))
+          .prop('checked', checked)
           .appendTo(label);
 
         label.append(name);
 
         input.on('change', function() {
-          if (input.is(':checked')) {
+          checked = input.is(':checked');
+          if (checked) {
             map.addLayer(layer);
           } else {
             map.removeLayer(layer);
@@ -155,6 +158,16 @@ L.OSM.layers = function(options) {
         map.on('zoomend', function() {
           var disabled = map.getBounds().getSize() >= maxArea;
           $(input).prop('disabled', disabled);
+
+          if (disabled && $(input).is(':checked')) {
+            $(input).prop('checked', false)
+              .trigger('change');
+            checked = true;
+          } else if (!disabled && !$(input).is(':checked') && checked) {
+            $(input).prop('checked', true)
+              .trigger('change');
+          }
+
           $(item).attr('class', disabled ? 'disabled' : '');
           item.attr('data-original-title', disabled ?
             I18n.t('javascripts.site.' + refName + '_zoom_in_tooltip') : '');