Make TileLayerControl always aware of the map

fix #587
This commit is contained in:
Yohan Boniface 2018-06-16 13:58:31 +02:00
parent fbb7125167
commit cfbe5c0b88
3 changed files with 15 additions and 7 deletions

View file

@ -60,6 +60,8 @@ COMMIT;
el (Greek), gl (Galician) el (Greek), gl (Galician)
- JS locales are now bundled, no need to generate them while installing - JS locales are now bundled, no need to generate them while installing
- local settings are now loaded from `/etc/umap/umap.conf` if available - 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)

View file

@ -729,10 +729,16 @@ L.U.Map.include({
L.U.TileLayerControl = L.Control.extend({ L.U.TileLayerControl = L.Control.extend({
options: { options: {
position: 'topleft' position: 'topleft'
}, },
initialize: function (map, options) {
this.map = map;
L.Control.prototype.initialize.call(this, options);
},
onAdd: function () { onAdd: function () {
var container = L.DomUtil.create('div', 'leaflet-control-tilelayers umap-control'); var container = L.DomUtil.create('div', 'leaflet-control-tilelayers umap-control');
@ -754,22 +760,22 @@ L.U.TileLayerControl = L.Control.extend({
}, },
buildList: function (options) { buildList: function (options) {
this._map.eachTileLayer(function (tilelayer) { this.map.eachTileLayer(function (tilelayer) {
this.addTileLayerElement(tilelayer, options); this.addTileLayerElement(tilelayer, options);
}, this); }, 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) { 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), el = L.DomUtil.create('li', selectedClass, this._tilelayers_container),
img = L.DomUtil.create('img', '', el), img = L.DomUtil.create('img', '', el),
name = L.DomUtil.create('div', '', 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; name.innerHTML = tilelayer.options.name;
L.DomEvent.on(el, 'click', function () { L.DomEvent.on(el, 'click', function () {
this._map.selectTileLayer(tilelayer); this.map.selectTileLayer(tilelayer);
this._map.ui.closePanel(); this.map.ui.closePanel();
if (options && options.callback) options.callback(tilelayer); if (options && options.callback) options.callback(tilelayer);
}, this); }, this);
} }

View file

@ -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.fullscreen = new L.Control.Fullscreen({title: {'false': L._('View Fullscreen'), 'true': L._('Exit Fullscreen')}});
this._controls.search = new L.U.SearchControl(); this._controls.search = new L.U.SearchControl();
this._controls.embed = new L.Control.Embed(this, this.options.embedOptions); 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({ this._controls.editinosm = new L.Control.EditInOSM({
position: 'topleft', position: 'topleft',
widgetOptions: {helpText: L._('Open this map extent in a map editor to provide more accurate data to OpenStreetMap')} widgetOptions: {helpText: L._('Open this map extent in a map editor to provide more accurate data to OpenStreetMap')}