X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5e9ab5bc5edb63b7ab7719fa989a18f52e3637a2..e96a64ca9c2ea068dd9167e074ee26c8d28744b4:/app/assets/javascripts/leaflet.layers.js diff --git a/app/assets/javascripts/leaflet.layers.js b/app/assets/javascripts/leaflet.layers.js index 09cf1cf60..80613a5d9 100644 --- a/app/assets/javascripts/leaflet.layers.js +++ b/app/assets/javascripts/leaflet.layers.js @@ -1,15 +1,10 @@ -L.OSM.Layers = L.Control.extend({ - onAdd: function (map) { - this._map = map; - this._initLayout(); - return this.$container[0]; - }, - - _initLayout: function () { - var map = this._map, - layers = this.options.layers; - - this.$container = $('
') +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 = $('') @@ -17,20 +12,22 @@ L.OSM.Layers = L.Control.extend({ .attr('href', '#') .attr('title', 'Layers') .html('') - .appendTo(this.$container); + .on('click', toggle) + .appendTo($container); - if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { - this.$ui = $('
') - .attr('class', 'layers-ui') - .appendTo(this.options.uiPane); + var $ui = $('
') + .attr('class', 'layers-ui'); - $('

') - .text(I18n.t('javascripts.map.layers.header')) - .appendTo(this.$ui); + $('
') + .appendTo($ui) + .append( + $('

') + .text(I18n.t('javascripts.map.layers.header'))); + if (OSM.STATUS != 'api_offline' && OSM.STATUS != 'database_offline') { var overlaySection = $('
') .addClass('overlay-layers') - .appendTo(this.$ui); + .appendTo($ui); $('

') .text(I18n.t('javascripts.map.layers.overlays')) @@ -72,7 +69,7 @@ L.OSM.Layers = L.Control.extend({ var baseSection = $('

') .addClass('base-layers') - .appendTo(this.$ui); + .appendTo($ui); $('

') .text(I18n.t('javascripts.map.layers.base')) @@ -94,19 +91,30 @@ L.OSM.Layers = L.Control.extend({ 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); + .addLayer(new layer.constructor()); miniMap.dragging.disable(); miniMap.touchZoom.disable(); miniMap.doubleClickZoom.disable(); miniMap.scrollWheelZoom.disable(); - map.on('moveend', function() { - miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0)); - }); + $ui + .on('show', shown) + .on('hide', hide); - div.data('map', miniMap); + function shown() { + miniMap.invalidateSize(); + setView(); + map.on('moveend', setView); + } + + function hide() { + map.off('moveend', setView); + } + + function setView() { + miniMap.setView(map.getCenter(), Math.max(map.getZoom() - 2, 0)); + } }); var label = $('