]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.layers.js
Fix embed
[rails.git] / app / assets / javascripts / leaflet.layers.js
index 242f762857180c71046383373f907435d64216aa..edcbfbd4dd9dd94e73879908644b879f768dc51a 100644 (file)
@@ -18,26 +18,23 @@ L.OSM.layers = function(options) {
     var $ui = $('<div>')
       .attr('class', 'layers-ui');
 
-    $('<section>')
-       .appendTo($ui)
-       .append(
-          $('<a>')
-            .html('&raquo;')
-            .attr('class', 'close-button')
-            .attr('href', '#')
-            .bind('click', toggle))
-       .append(
-        $('<h2>')
+    $('<div>')
+      .attr('class', 'sidebar_heading')
+      .appendTo($ui)
+      .append(
+        $('<a>')
+          .text(I18n.t('javascripts.close'))
+          .attr('class', 'sidebar_close')
+          .attr('href', '#')
+          .bind('click', toggle))
+      .append(
+        $('<h4>')
           .text(I18n.t('javascripts.map.layers.header')));
 
-    var baseSection = $('<section>')
-      .addClass('base-layers')
+    var baseSection = $('<div>')
+      .attr('class', 'section base-layers')
       .appendTo($ui);
 
-    $('<p>')
-      .text(I18n.t('javascripts.map.layers.base'))
-      .appendTo(baseSection);
-
     list = $('<ul>')
       .appendTo(baseSection);
 
@@ -67,23 +64,33 @@ L.OSM.layers = function(options) {
 
         function shown() {
           miniMap.invalidateSize();
-          setView();
-          map.on('moveend', setView);
+          setView({animate: false});
+          map.on('moveend', moved);
         }
 
         function hide() {
-          map.off('moveend', setView);
+          map.off('moveend', moved);
+        }
+
+        function moved() {
+          setView();
         }
 
-        function setView() {
-          miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0));
+        function setView(options) {
+          miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0), options);
         }
       });
 
       var label = $('<label>')
-        .text(layer.options.name)
         .appendTo(item);
 
+      var input = $('<input>')
+        .attr('type', 'radio')
+        .prop('checked', map.hasLayer(layer))
+        .appendTo(label);
+
+      label.append(layer.options.name);
+
       item.on('click', function() {
         layers.forEach(function(other) {
           if (other === layer) {
@@ -92,16 +99,18 @@ L.OSM.layers = function(options) {
             map.removeLayer(other);
           }
         });
+        map.fire('baselayerchange', {layer: layer});
       });
 
       map.on('layeradd layerremove', function() {
         item.toggleClass('active', map.hasLayer(layer));
+        input.prop('checked', map.hasLayer(layer));
       });
     });
 
     if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') {
-      var overlaySection = $('<section>')
-        .addClass('overlay-layers')
+      var overlaySection = $('<div>')
+        .attr('class', 'section overlay-layers')
         .appendTo($ui);
 
       $('<p>')