Skip to content

Instantly share code, notes, and snippets.

@geog4046instructor
Last active March 28, 2023 14:49
Show Gist options
  • Save geog4046instructor/416b9edf6cab7eb85ad53fb1b7b6cbb4 to your computer and use it in GitHub Desktop.
Save geog4046instructor/416b9edf6cab7eb85ad53fb1b7b6cbb4 to your computer and use it in GitHub Desktop.
Leaflet - Basemap switcher
/* This example is similar to the leaflet-layer-control.js example:
* (https://gist.github.com/geog4046instructor/65f38124e3f56f11c9461b23335c0c92)
* but this example only adds basemaps (tileLayer) to the control.
*/
// create a street map layer and add it to the map, making it the default basemap
let streets = L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ).addTo( map )
// create a satellite imagery layer
let satellite = L.tileLayer( 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' )
// create an object to hold layer names as you want them to appear in the basemap switcher list
let basemapControl = {
"Streets": streets,
"Satellite": satellite
}
// display the control (switcher list) on the map, by default in the top right corner
L.control.layers( basemapControl ).addTo( map )
@adwaith-anil
Copy link

easy and simple ! nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment