X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/ef73cc1f574124b10cda75188aa542d9f4d802bb..b21d0906c48065e8fdf74df30dd453bba6d4d8f2:/app/assets/javascripts/leaflet.layers.js diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 15f114a5c..2f06ab9c5 100644 --- a/app/assets/javascripts/leaflet.layers.js +++ b/app/assets/javascripts/leaflet.layers.js @@ -1,92 +1,165 @@ -//= require templates/map/layers +L.OSM.layers = function(options) { + var control = L.control(options); + + control.onAdd = function (map) { + var layers = options.layers; + + var $container = $('
') + .attr('class', 'control-layers'); + + var link = $('') + .attr('class', 'control-button') + .attr('href', '#') + .attr('title', 'Layers') + .html('') + .on('click', toggle) + .appendTo($container); + + var $ui = $('
') + .attr('class', 'layers-ui'); + + $('
') + .appendTo($ui) + .append( + $('') + .html('»') + .attr('class', 'close-button') + .attr('href', '#') + .bind('click', toggle)) + .append( + $('

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

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

    ') + .appendTo(baseSection); + + layers.forEach(function(layer) { + var item = $('
  • ') + .appendTo(list); -L.OSM.Layers = L.Control.extend({ - onAdd: function (map) { - this._map = map; - this._initLayout(map); - return this._container; - }, + if (map.hasLayer(layer)) { + item.addClass('active'); + } - _initLayout: function () { - var className = 'leaflet-control-map-ui', - container = this._container = L.DomUtil.create('div', className); + var div = $('
    ') + .appendTo(item); - var link = L.DomUtil.create('a', 'control-button', container); - link.innerHTML = ""; - link.href = '#'; - link.title = 'Layers'; + map.whenReady(function() { + var miniMap = L.map(div[0], {attributionControl: false, zoomControl: false}) + .addLayer(new layer.constructor()); - this._ui = $(L.DomUtil.create('div', 'layers-ui', this.options.uiPane)) - .html(JST["templates/map/layers"]()); + miniMap.dragging.disable(); + miniMap.touchZoom.disable(); + miniMap.doubleClickZoom.disable(); + miniMap.scrollWheelZoom.disable(); - var list = this._ui.find('.base-layers ul'); + $ui + .on('show', shown) + .on('hide', hide); - this.options.layers.forEach(function(layer) { - var item = $('
  • ') - .appendTo(list); + function shown() { + miniMap.invalidateSize(); + setView(); + map.on('moveend', setView); + } - if (this._map.hasLayer(layer)) { - item.addClass('active'); - } + function hide() { + map.off('moveend', setView); + } - var div = $('
    ') - .appendTo(item); + function setView() { + miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0)); + } + }); - 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)) - .addLayer(new layer.constructor); + var label = $('