Switching layers
-
Hi bozdoz,
I’m trying to use L.control.layers. But I have difficulties with the name of the first tilelayer adding with the shortcode. The second problem is the attribution. The switching tilelayer also receives the attribution from the first tilelayer.
The naming problem I solved, but the attribution I don’t.
My tiles in the code are from https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png.[leaflet-map attribution="Daten von <a href=https://www.openstreetmap.org/>OpenStreetMap</a> - Ver?ffentlicht unter <a href=https://opendatacommons.org/licenses/odbl/>ODbL</a>"] <script> // push deferred map creation function window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || []; window.WPLeafletMapPlugin.push(function () { var map = window.WPLeafletMapPlugin.getCurrentMap(); var layers = []; map.eachLayer(function(layer) { if( layer instanceof L.TileLayer ) { map.removeLayer(layer); layer.options.name = "OSM"; layers.push(layer); map.addLayer(layer); } }); var topoAttr = \'Kartendaten: © <a href="https://openstreetmap.org/copyright">OpenStreetMap</a>-Mitwirkende, <a href="https://viewfinderpanoramas.org">SRTM</a> | Kartendarstellung: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)\', topoUrl = "https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png"; var topoMap = L.tileLayer(topoUrl, {attribution: topoAttr, name: "Topo"}); layers.push(topoMap); var baselayers = {}; layers.forEach(function(layer) { var name = layer.options.name; baselayers[name] = layer; }); L.control.layers(baselayers).addTo(map); }); </script>
Thank you.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Switching layers’ is closed to new replies.