X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9d33721630e02ab9bed1d7853be4fcb5960d7b4f..5e9ab5bc5edb63b7ab7719fa989a18f52e3637a2:/app/assets/javascripts/leaflet.layers.js 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; + + this.$container = $('
') + .attr('class', 'control-layers'); + + var link = $('') + .attr('class', 'control-button') + .attr('href', '#') + .attr('title', 'Layers') + .html('') + .appendTo(this.$container); + + if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { + this.$ui = $('
') + .attr('class', 'layers-ui') + .appendTo(this.options.uiPane); + + $('

') + .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 link = L.DomUtil.create('a', 'control-button', container); - link.innerHTML = ""; - link.href = '#'; - link.title = 'Layers'; + var list = $('

    ') + .appendTo(overlaySection); - this._ui = $(L.DomUtil.create('div', 'layers-ui', this.options.uiPane)) - .html(JST["templates/map/layers"]()); + function addOverlay(layer, name) { + var item = $('
  • ') + .appendTo(list); - var list = this._ui.find('.base-layers ul'); + var label = $('
  • ') + var input = $('') + .attr('type', 'checkbox') + .prop('checked', map.hasLayer(layer)) + .appendTo(label); + + label.append(name); + + input.on('change', function() { + if (input.is(':checked')) { + map.addLayer(layer); + } else { + map.removeLayer(layer); + } + }); + + map.on('layeradd layerremove', function() { + input.prop('checked', map.hasLayer(layer)); + }); + } + + addOverlay(map.noteLayer, I18n.t('javascripts.map.layers.notes')); + addOverlay(map.dataLayer, I18n.t('javascripts.map.layers.data')); + } + + var baseSection = $('
    ') + .addClass('base-layers') + .appendTo(this.$ui); + + $('

    ') + .text(I18n.t('javascripts.map.layers.base')) + .appendTo(baseSection); + + list = $('

      ') + .appendTo(baseSection); + + layers.forEach(function(layer) { + var item = $('
    • ') .appendTo(list); - if (this._map.hasLayer(layer)) { + if (map.hasLayer(layer)) { item.addClass('active'); } - var div = $('
      ') + var div = $('
      ') .appendTo(item); - this._map.whenReady(function() { - var map = L.map(div[0], {attributionControl: false, zoomControl: false}) - .setView(this._map.getCenter(), Math.max(this._map.getZoom() - 2, 0)) + map.whenReady(function() { + var miniMap = L.map(div[0], {attributionControl: false, zoomControl: false}) + .setView(map.getCenter(), Math.max(map.getZoom() - 2, 0)) .addLayer(new layer.constructor); - map.dragging.disable(); - map.touchZoom.disable(); - map.doubleClickZoom.disable(); - map.scrollWheelZoom.disable(); - }, this); + miniMap.dragging.disable(); + miniMap.touchZoom.disable(); + miniMap.doubleClickZoom.disable(); + miniMap.scrollWheelZoom.disable(); - var label = $('') + map.on('moveend', function() { + miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0)); + }); + + div.data('map', miniMap); + }); + + var label = $('