From: John Firebaugh Date: Mon, 10 Jun 2013 21:26:55 +0000 (-0700) Subject: Rename to L.OSM.Layers and continue implementation X-Git-Tag: live~5463^2~47 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/33aa0a6e454fb2d43b8ccc07395abf0864d47b66?hp=7bcea3839da07f01258157ad204cd5b1fd4c76d8 Rename to L.OSM.Layers and continue implementation --- diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a984a23f9..ee9b16ff1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -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 diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index 48207c43d..f95510f6c 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -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 Andy Allan", + }), + keyid: "cyclemap", + layerCode: "C", + name: I18n.t("javascripts.map.base.cycle_map") + }, { + layer: new L.OSM.TransportMap({ + attribution: "Tiles courtesy of Andy Allan", + }), + keyid: "transportmap", + layerCode: "T", + name: I18n.t("javascripts.map.base.transport_map") + }, { + layer: new L.OSM.MapQuestOpen({ + attribution: "Tiles courtesy of MapQuest ", + }), + 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 index 51f00f325..000000000 --- a/app/assets/javascripts/index/map_ui.js +++ /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 = ""; - 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 index 000000000..6c83f0c2f --- /dev/null +++ b/app/assets/javascripts/leaflet.layers.js @@ -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); +}; diff --git a/app/assets/javascripts/map.js.erb b/app/assets/javascripts/map.js.erb index 1882fe4f4..70801306b 100644 --- a/app/assets/javascripts/map.js.erb +++ b/app/assets/javascripts/map.js.erb @@ -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 Andy Allan", - }), - keyid: "cyclemap", - layerCode: "C", - name: I18n.t("javascripts.map.base.cycle_map") - }, { - layer: new L.OSM.TransportMap({ - attribution: "Tiles courtesy of Andy Allan", - }), - keyid: "transportmap", - layerCode: "T", - name: I18n.t("javascripts.map.base.transport_map") - }, { - layer: new L.OSM.MapQuestOpen({ - attribution: "Tiles courtesy of MapQuest ", - }), - 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 %>, diff --git a/app/assets/javascripts/templates/map/layers.jst.ejs b/app/assets/javascripts/templates/map/layers.jst.ejs index 4945b9743..66fa1f7ed 100644 --- a/app/assets/javascripts/templates/map/layers.jst.ejs +++ b/app/assets/javascripts/templates/map/layers.jst.ejs @@ -6,4 +6,9 @@

<%= I18n.t('javascripts.map.layers.base') %>

+