Learn how to change the static basemap tiles style.
The static basemap tiles service (beta) provides access to raster basemap tiles for the world. The service supports a number of ArcGIS styles such as navigation
, streets
, outdoor
, and light-gray
. The tiles are returned as PNG files.
In this tutorial, you use the L.esri.
class to change the static basemap tiles style.
Prerequisites
An ArcGIS Location Platform account.
Steps
Get the starter app
Select a type of authentication below and follow the steps to create a new application.
Set up authentication
Create developer credentials in your portal for the type of authentication you selected.
Set developer credentials
Use the API key or OAuth developer credentials so your application can access location services.
Update script references
The map will use static basemap tiles as its basemap layer. Therefore, you remove references to the esri-leaflet-vector
plugin and the vector basemap layer. Then, you reference the static
plugin.
-
Remove the script references to
esri-leaflet-vector
plugin.Use dark colors for code blocks <head> <meta charset="utf-8" /> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> <title>Esri Leaflet Tutorials: Display a map</title> <!-- Load Leaflet from CDN --> <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" crossorigin="" /> <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js" crossorigin=""></script> <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.14/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-vector@4.2.6/dist/esri-leaflet-vector.js"></script>
-
Remove the
basemap
andEnum vector
references.Basemap Layer Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }) map.setView([34.02, -118.805], 13); const basemapEnum = "arcgis/streets"; L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map);
-
Add
<script
tag to reference the> static
plugin.Basemap Tile Layer Use dark colors for code blocks <!-- Load Esri Leaflet from CDN --> <script src="https://unpkg.com/esri-leaflet@3.0.14/dist/esri-leaflet.js"></script> <script src="https://unpkg.com/esri-leaflet-static-basemap-tile@1.0.0-beta.2/dist/esri-leaflet-static-basemap-tile.js"></script>
Update the map's viewpoint
-
Change the map's center to
[37.1174, -91.2996]
and zoom level to5
. This will focus the map on the United States of America.Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URL", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; const map = L.map("map", { minZoom: 2 }) map.setView([37.1174, -91.2996], 5); </script>
Add the basemap styles
You will get all the available basemap styles from the static basemap tiles service and create a menu that allows users to change the basemap style of your map.
-
Use the
get
method fromSelf L.esri.
to make a request to the static basemap tiles service that returns all available basemap styles and their metadata.Static. Util Use dark colors for code blocks <script> /* Use for API key authentication */ const accessToken = "YOUR_ACCESS_TOKEN"; // or /* Use for user authentication */ // const session = await arcgisRest.ArcGISIdentityManager.beginOAuth2({ // clientId: "YOUR_CLIENT_ID", // Your client ID from OAuth credentials // redirectUri: "YOUR_REDIRECT_URL", // The redirect URL registered in your OAuth credentials // portal: "YOUR_PORTAL_URL" // Your portal URL // }) // const accessToken = session.token; const map = L.map("map", { minZoom: 2 }) map.setView([37.1174, -91.2996], 5); L.esri.Static.Util.getSelf(accessToken).then((data) => { }) </script>
-
Create a
basemap
object to store all the returned basemap styles.Layers Use dark colors for code blocks L.esri.Static.Util.getSelf(accessToken).then((data) => { const basemapLayers = {}; })
-
Iterate through each basemap style and create an
L.esri.
from theStatic.static Basemap Tile Layer style
. Store it inside thebasemap
object.Layers Use dark colors for code blocks L.esri.Static.Util.getSelf(accessToken).then((data) => { const basemapLayers = {}; data.styles.forEach(style => { basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, { token: accessToken }) }) })
-
Create a
Layers
control that referencesbasemap
and add it to your map.Layers Use dark colors for code blocks L.esri.Static.Util.getSelf(accessToken).then((data) => { const basemapLayers = {}; data.styles.forEach(style => { basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, { token: accessToken }) }) L.control.layers(basemapLayers, null, { collapsed: false }).addTo(map); })
-
Append
add
to theTo ArcGI
entry so that it is the default style when the application loads.S Navigation Use dark colors for code blocks L.esri.Static.Util.getSelf(accessToken).then((data) => { const basemapLayers = {}; data.styles.forEach(style => { basemapLayers[style.name] = L.esri.Static.staticBasemapTileLayer('beta' + style.path, { token: accessToken }) }) L.control.layers(basemapLayers, null, { collapsed: false }).addTo(map); basemapLayers['ArcGIS Navigation'].addTo(map); })
Run the app
Run the app.
Use the layers control in the top right to select and explore different basemap layer styles from the static basemap tiles service.
What's next?
Learn how to use additional ArcGIS location services in these tutorials: