From cfbe5c0b88ba64a2a3164d109c9c9993c003a23a Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 16 Jun 2018 13:58:31 +0200 Subject: [PATCH] Make TileLayerControl always aware of the map fix #587 --- docs/changelog.md | 2 ++ umap/static/umap/js/umap.controls.js | 18 ++++++++++++------ umap/static/umap/js/umap.js | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 8f0d68ed..d1b2ac0e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -60,6 +60,8 @@ COMMIT; el (Greek), gl (Galician) - JS locales are now bundled, no need to generate them while installing - local settings are now loaded from `/etc/umap/umap.conf` if available +- fixed an issue where it was not possible to change the tilelayer if the + tilelayer control was not added to the map (#587) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 7179dd9b..995af8cb 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -729,10 +729,16 @@ L.U.Map.include({ L.U.TileLayerControl = L.Control.extend({ + options: { position: 'topleft' }, + initialize: function (map, options) { + this.map = map; + L.Control.prototype.initialize.call(this, options); + }, + onAdd: function () { var container = L.DomUtil.create('div', 'leaflet-control-tilelayers umap-control'); @@ -754,22 +760,22 @@ L.U.TileLayerControl = L.Control.extend({ }, buildList: function (options) { - this._map.eachTileLayer(function (tilelayer) { + this.map.eachTileLayer(function (tilelayer) { this.addTileLayerElement(tilelayer, options); }, this); - this._map.ui.openPanel({data: {html: this._tilelayers_container}, className: options.className}); + this.map.ui.openPanel({data: {html: this._tilelayers_container}, className: options.className}); }, addTileLayerElement: function (tilelayer, options) { - var selectedClass = this._map.hasLayer(tilelayer) ? 'selected' : '', + var selectedClass = this.map.hasLayer(tilelayer) ? 'selected' : '', el = L.DomUtil.create('li', selectedClass, this._tilelayers_container), img = L.DomUtil.create('img', '', el), name = L.DomUtil.create('div', '', el); - img.src = L.Util.template(tilelayer.options.url_template, this._map.demoTileInfos); + img.src = L.Util.template(tilelayer.options.url_template, this.map.demoTileInfos); name.innerHTML = tilelayer.options.name; L.DomEvent.on(el, 'click', function () { - this._map.selectTileLayer(tilelayer); - this._map.ui.closePanel(); + this.map.selectTileLayer(tilelayer); + this.map.ui.closePanel(); if (options && options.callback) options.callback(tilelayer); }, this); } diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index 326ad6a9..2c8a8634 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -247,7 +247,7 @@ L.U.Map.include({ this._controls.fullscreen = new L.Control.Fullscreen({title: {'false': L._('View Fullscreen'), 'true': L._('Exit Fullscreen')}}); this._controls.search = new L.U.SearchControl(); this._controls.embed = new L.Control.Embed(this, this.options.embedOptions); - this._controls.tilelayers = new L.U.TileLayerControl(); + this._controls.tilelayers = new L.U.TileLayerControl(this); this._controls.editinosm = new L.Control.EditInOSM({ position: 'topleft', widgetOptions: {helpText: L._('Open this map extent in a map editor to provide more accurate data to OpenStreetMap')}