]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.layers.js
Display the size warning when the data layer is disabled
[rails.git] / app / assets / javascripts / leaflet.layers.js
index 7703529b8799e35d94b06ddefc1fb9d4e60705d1..d6276919c892da8065691009ae6770a41d3d9917 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,18 @@ 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');
+          }
+
+          layer.fire('statechange', {disabled: disabled, checked: checked});
+
           $(item).attr('class', disabled ? 'disabled' : '');
           item.attr('data-original-title', disabled ?
             I18n.t('javascripts.site.' + refName + '_zoom_in_tooltip') : '');