Last active
March 28, 2023 14:49
-
-
Save geog4046instructor/416b9edf6cab7eb85ad53fb1b7b6cbb4 to your computer and use it in GitHub Desktop.
Leaflet - Basemap switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
easy and simple ! nice work