An easy leaflet plugin to switch basemap
npm install leaflet-switch-basemap
npm i leaflet-switch-basemap
`
Usage Example
An easy way to implement control to switch between basemaps
`javascript
new L.basemapsSwitcher([
{
layer: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map), //DEFAULT MAP
icon: './assets/images/img1.PNG',
name: 'Map one'
},
{
layer: L.tileLayer('https://tiles.stadiamaps.com/tiles/alidade_smooth/{z}/{x}/{y}{r}.png',{
attribution: '© Stadia Maps, © OpenMapTiles © OpenStreetMap contributors'
}),
icon: './assets/images/img2.PNG',
name: 'Map two'
},
{
layer: L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
attribution: 'Map data: © OpenStreetMap contributors, SRTM | Map style: © OpenTopoMap (CC-BY-SA)'
}),
icon: './assets/images/img3.PNG',
name: 'Map three'
},
], { position: 'topright' }).addTo(map);
``