diff --git a/app/assets/javascripts/index.js b/app/assets/javascripts/index.js index c9316ebae..fed4c1d8a 100644 --- a/app/assets/javascripts/index.js +++ b/app/assets/javascripts/index.js @@ -48,6 +48,9 @@ $(document).ready(function () { layers[0].addTo(map); + map.noteLayer = new L.LayerGroup({code: 'N'}); + map.dataLayer = new L.OSM.DataLayer(null); + $("#map").on("resized", function () { map.invalidateSize(); }); diff --git a/app/assets/javascripts/index/browse.js b/app/assets/javascripts/index/browse.js index e98e56b27..e04a864f4 100644 --- a/app/assets/javascripts/index/browse.js +++ b/app/assets/javascripts/index/browse.js @@ -10,20 +10,20 @@ function initializeBrowse(map) { var areasHidden = false; var locationFilter; - var dataLayer = new L.OSM.DataLayer(null, { - styles: { - way: { - weight: 3, - color: "#000000", - opacity: 0.4 - }, - area: { - weight: 3, - color: "#ff0000" - }, - node: { - color: "#00ff00" - } + var dataLayer = map.dataLayer; + + dataLayer.setStyle({ + way: { + weight: 3, + color: "#000000", + opacity: 0.4 + }, + area: { + weight: 3, + color: "#ff0000" + }, + node: { + color: "#00ff00" } }); @@ -35,10 +35,6 @@ function initializeBrowse(map) { onSelect(e.layer); }); - if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { -// map.layersControl.addOverlay(dataLayer, I18n.t("browse.start_rjs.data_layer_name")); - } - map.on('layeradd', function (e) { if (e.layer === dataLayer) { $.ajax({ url: "/browse/start", success: function (sidebarHtml) { diff --git a/app/assets/javascripts/index/notes.js.erb b/app/assets/javascripts/index/notes.js.erb index 1646e8b6d..3a2a15393 100644 --- a/app/assets/javascripts/index/notes.js.erb +++ b/app/assets/javascripts/index/notes.js.erb @@ -3,7 +3,7 @@ function initializeNotes(map) { var params = OSM.mapParams(), - noteLayer = new L.LayerGroup({code: 'N'}), + noteLayer = map.noteLayer, notes = {}, newNote; @@ -25,8 +25,6 @@ function initializeNotes(map) { }) }; - map.noteLayer = noteLayer; - map.on("layeradd", function (e) { if (e.layer == noteLayer) { loadNotes(); diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 15f114a5c..09cf1cf60 100644 --- a/app/assets/javascripts/leaflet.layers.js +++ b/app/assets/javascripts/leaflet.layers.js @@ -1,72 +1,132 @@ -//= require templates/map/layers - L.OSM.Layers = L.Control.extend({ onAdd: function (map) { this._map = map; - this._initLayout(map); - return this._container; + this._initLayout(); + return this.$container[0]; }, _initLayout: function () { - var className = 'leaflet-control-map-ui', - container = this._container = L.DomUtil.create('div', className); + var map = this._map, + layers = this.options.layers; - var link = L.DomUtil.create('a', 'control-button', container); - link.innerHTML = ""; - link.href = '#'; - link.title = 'Layers'; + this.$container = $('
') + .attr('class', 'control-layers'); - this._ui = $(L.DomUtil.create('div', 'layers-ui', this.options.uiPane)) - .html(JST["templates/map/layers"]()); + var link = $('') + .attr('class', 'control-button') + .attr('href', '#') + .attr('title', 'Layers') + .html('') + .appendTo(this.$container); - var list = this._ui.find('.base-layers ul'); + if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { + this.$ui = $('
') + .attr('class', 'layers-ui') + .appendTo(this.options.uiPane); - this.options.layers.forEach(function(layer) { - var item = $('
  • ') + $('

    ') + .text(I18n.t('javascripts.map.layers.header')) + .appendTo(this.$ui); + + var overlaySection = $('
    ') + .addClass('overlay-layers') + .appendTo(this.$ui); + + $('

    ') + .text(I18n.t('javascripts.map.layers.overlays')) + .appendTo(overlaySection); + + var list = $('

      ') + .appendTo(overlaySection); + + function addOverlay(layer, name) { + var item = $('
    • ') + .appendTo(list); + + var label = $('