]> git.openstreetmap.org Git - rails.git/commitdiff
Rename to L.OSM.Layers and continue implementation
authorJohn Firebaugh <john.firebaugh@gmail.com>
Mon, 10 Jun 2013 21:26:55 +0000 (14:26 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Thu, 18 Jul 2013 17:37:45 +0000 (10:37 -0700)
app/assets/javascripts/application.js
app/assets/javascripts/index.js
app/assets/javascripts/index/map_ui.js [deleted file]
app/assets/javascripts/leaflet.layers.js [new file with mode: 0644]
app/assets/javascripts/map.js.erb
app/assets/javascripts/templates/map/layers.jst.ejs

index a984a23f97fc7c5e2ede1f183e8d5337325294b3..ee9b16ff1d5391f23cca4062a446d2b52bfa53f7 100644 (file)
@@ -6,8 +6,6 @@
 //= require leaflet
 //= require leaflet.osm
 //= require leaflet.locationfilter
-//= require leaflet.locate
-//= require leaflet.note
 //= require i18n/translations
 //= require oauth
 //= require osm
@@ -15,7 +13,6 @@
 //= require map
 //= require menu
 //= require sidebar
-//= require leaflet.share
 //= require richtext
 //= require resize
 //= require geocoder
index 48207c43dfe78e56ca573bf18bd12a641c14f4b3..f95510f6ce9b96d251cc24090add22e5cfe23438 100644 (file)
@@ -1,9 +1,12 @@
 //= require_self
+//= require leaflet.layers
+//= require leaflet.share
+//= require leaflet.note
+//= require leaflet.locate
 //= require index/browse
 //= require index/export
 //= require index/key
 //= require index/notes
-//= require index/map_ui
 
 var map, layers; // TODO: remove globals
 
@@ -18,7 +21,36 @@ $(document).ready(function () {
 
   map.attributionControl.setPrefix('');
 
-  layers = mapLayers();
+  layers = [{
+    layer: new L.OSM.Mapnik({
+      attribution: ''
+    }),
+    keyid: "mapnik",
+    layerCode: "M",
+    name: I18n.t("javascripts.map.base.standard")
+  }, {
+    layer: new L.OSM.CycleMap( {
+      attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
+    }),
+    keyid: "cyclemap",
+    layerCode: "C",
+    name: I18n.t("javascripts.map.base.cycle_map")
+  }, {
+    layer: new L.OSM.TransportMap({
+      attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
+    }),
+    keyid: "transportmap",
+    layerCode: "T",
+    name: I18n.t("javascripts.map.base.transport_map")
+  }, {
+    layer: new L.OSM.MapQuestOpen({
+      attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
+    }),
+    keyid: "mapquest",
+    layerCode: "Q",
+    name: I18n.t("javascripts.map.base.mapquest")
+  }];
+
   layers[0].layer.addTo(map);
 
   $("#map").on("resized", function () {
@@ -28,7 +60,8 @@ $(document).ready(function () {
   L.control.zoom({position: 'topright'})
     .addTo(map);
 
-  OSM.mapUI().addTo(map);
+  L.OSM.layers({position: 'topright', layers: layers})
+    .addTo(map);
 
   L.control.share({
       getUrl: function(map) {
diff --git a/app/assets/javascripts/index/map_ui.js b/app/assets/javascripts/index/map_ui.js
deleted file mode 100644 (file)
index 51f00f3..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-//= require templates/map/layers
-
-OSM.MapUI = L.Control.extend({
-    onAdd: function(map) {
-        this._initLayout(map);
-        return this._container;
-    },
-
-    _initLayout: function(map) {
-        var className = 'control-layers',
-            container = this._container = L.DomUtil.create('div', className);
-
-        var link = this._layersLink = L.DomUtil.create('a', 'control-button', container);
-        link.innerHTML = "<span class='icon layers'></span>";
-        link.href = '#';
-        link.title = 'Layers';
-
-        this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
-        L.DomEvent
-            .on(this._uiPane, 'click', L.DomEvent.stopPropagation)
-            .on(this._uiPane, 'click', L.DomEvent.preventDefault)
-            .on(this._uiPane, 'dblclick', L.DomEvent.preventDefault);
-
-        $(link).on('click', $.proxy(this.toggleLayers, this));
-    },
-
-    toggleLayers: function(e) {
-        e.stopPropagation();
-        e.preventDefault();
-
-        var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
-
-        if ($(this._uiPane).is(':visible')) {
-            $(this._uiPane).hide();
-            controlContainer.css({paddingRight: '0'});
-        } else {
-            $(this._uiPane)
-                .show()
-                .html(JST["templates/map/layers"]());
-            controlContainer.css({paddingRight: '200px'});
-        }
-    }
-});
-
-OSM.mapUI = function() {
-    return new OSM.MapUI();
-};
diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js
new file mode 100644 (file)
index 0000000..6c83f0c
--- /dev/null
@@ -0,0 +1,47 @@
+//= require templates/map/layers
+
+L.OSM.Layers = L.Control.extend({
+  onAdd: function (map) {
+    this._initLayout(map);
+    return this._container;
+  },
+
+  _initLayout: function (map) {
+    var className = 'leaflet-control-map-ui',
+      container = this._container = L.DomUtil.create('div', className);
+
+    var link = this._layersLink = L.DomUtil.create('a', 'leaflet-map-ui-layers', container);
+    link.href = '#';
+    link.title = 'Layers';
+
+    this._uiPane = L.DomUtil.create('div', 'leaflet-map-ui', map._container);
+
+    L.DomEvent
+      .on(this._uiPane, 'click', L.DomEvent.stopPropagation)
+      .on(this._uiPane, 'click', L.DomEvent.preventDefault)
+      .on(this._uiPane, 'dblclick', L.DomEvent.preventDefault);
+
+    $(link).on('click', $.proxy(this.toggleLayers, this));
+  },
+
+  toggleLayers: function (e) {
+    e.stopPropagation();
+    e.preventDefault();
+
+    var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
+
+    if ($(this._uiPane).is(':visible')) {
+      $(this._uiPane).hide();
+      controlContainer.css({paddingRight: '0'});
+    } else {
+      $(this._uiPane)
+        .show()
+        .html(JST["templates/map/layers"]({layers: this.options.layers}));
+      controlContainer.css({paddingRight: '200px'});
+    }
+  }
+});
+
+L.OSM.layers = function(options) {
+  return new L.OSM.Layers(options);
+};
index 1882fe4f48e1c509cca88c88cc6b01a488fe019a..70801306be7bc43f5f56e1710e74be9c75e93982 100644 (file)
@@ -15,38 +15,6 @@ L.Icon.Default.imagePath = <%= "#{asset_prefix}/images".to_json %>;
 var objectLayer;
 var objectLoader;
 
-function mapLayers() {
-  return [{
-    layer: new L.OSM.Mapnik({
-      attribution: ''
-    }),
-    keyid: "mapnik",
-    layerCode: "M",
-    name: I18n.t("javascripts.map.base.standard")
-  }, {
-    layer: new L.OSM.CycleMap( {
-      attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
-    }),
-    keyid: "cyclemap",
-    layerCode: "C",
-    name: I18n.t("javascripts.map.base.cycle_map")
-  }, {
-    layer: new L.OSM.TransportMap({
-      attribution: "Tiles courtesy of <a href='http://www.opencyclemap.org/' target='_blank'>Andy Allan</a>",
-    }),
-    keyid: "transportmap",
-    layerCode: "T",
-    name: I18n.t("javascripts.map.base.transport_map")
-  }, {
-    layer: new L.OSM.MapQuestOpen({
-      attribution: "Tiles courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a> <img src='http://developer.mapquest.com/content/osm/mq_logo.png'>",
-    }),
-    keyid: "mapquest",
-    layerCode: "Q",
-    name: I18n.t("javascripts.map.base.mapquest")
-  }]
-}
-
 function getUserIcon(url) {
   return L.icon({
     iconUrl: url || <%= asset_path('marker-red.png').to_json %>,
index 4945b9743c8b2f143662a785e3170e9c971859b7..66fa1f7ed9ce47c7677bea1d33d84c42c658f505 100644 (file)
@@ -6,4 +6,9 @@
 </div>
 <div class='base-layers'>
     <p><%= I18n.t('javascripts.map.layers.base') %></p>
+    <ul>
+        <% for (var i = 0; i < layers.length; i++) { %>
+        <label><input type='radio'><%= layers[i].name %></label>
+        <% } %>
+    </ul>
 </div>