Learn how to change a basemap style
The ArcGIS Basemap Styles service
In this tutorial, you use the layers control to toggle between a number of different basemap styles
Prerequisites
You need an ArcGIS Location Platform or ArcGIS Online account.
Steps
Get the starter app
Select a type of authentication and follow the steps to create a new app.
Choose API key authentication if you:
- Want the easiest way to get started.
- Want to build public applications
A public application is an application that allows anonymous access without requiring users to sign in with an ArcGIS account. It supports API key or app authentication. that access ArcGIS Location ServicesArcGIS Location Services, also referred to as Location Services, are services hosted by Esri that provide geospatial functionality for developing mapping applications. They include the ArcGIS Basemap Styles service, ArcGIS Static Basemap Tiles service, ArcGIS Places service, ArcGIS Geocoding service, ArcGIS Routing service, ArcGIS GeoEnrichment service, and ArcGIS Elevation service. An ArcGIS Location Platform or ArcGIS Online account is required to use the services. and secure itemsAn item, also known as a content item, is a resource stored in a portal such as a web map, hosted layer, style, script tool, file, or notebook. . - Have an ArcGIS Location Platform or ArcGIS Online account.
Choose user authentication if you:
- Want to build private applications.
- Require application users to sign in with their own ArcGIS account
An ArcGIS account is an identity with a user type and set of privileges that can access specific ArcGIS products, tools, APIs, services, and resources. The main account types that can be used for development are an ArcGIS Location Platform account, ArcGIS Online account, and ArcGIS Enterprise account. ArcGIS Location Platform and ArcGIS Online accounts are also associated with a subscription. and access resources their behalf. - Have an ArcGIS Online account.
To learn more about both types of authentication, go to Authentication.
Set up authentication
Set developer credentials
Use the API key or OAuth developer credentials
Remove the basemap code
-
Remove the
basemapandEnum vectorreferences contained in the .Basemap Layer Use dark colors for code blocks const map = L.map("map", { minZoom: 2 }); map.setView([30, -20], 3); const basemapEnum = "arcgis/outdoor"; L.esri.Vector.vectorBasemapLayer(basemapEnum, { token: accessToken }).addTo(map);
Create a basemap style function
Create a function that accepts a basemap style enumeration and returns the corresponding basemap style.
-
Define a new
getfunction that accepts a style enumeration and returns aV2 Basemap Vector. Include your API key to validate the call.Basemap Layer Use dark colors for code blocks function getV2Basemap(style) { return L.esri.Vector.vectorBasemapLayer(style, { token: accessToken }); }
Add the basemap styles
Reference the basemap styles
-
Use
L.esri.getto make a request to the Basemap Styles service. This dynamically fetches the available basemap styles. For each enumerated style, call thegetfunction to populate theV2 Basemap styleslist.Use dark colors for code blocks function getV2Basemap(style) { return L.esri.Vector.vectorBasemapLayer(style, { token: accessToken }); } L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching basemap styles:", error); return; } const styles = {}; let firstStyleLayer; // Store the first style layer const basemapStyles = response.styles.filter((style) => !style.deprecated); basemapStyles.forEach((style, index) => { const layer = getV2Basemap(style.path); styles[style.name] = layer; }); } ); -
Append
addto theTo arcgis/outdoorentry so that it is the default style when the application loads.Use dark colors for code blocks function getV2Basemap(style) { return L.esri.Vector.vectorBasemapLayer(style, { token: accessToken }); } L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching basemap styles:", error); return; } const styles = {}; let firstStyleLayer; // Store the first style layer const basemapStyles = response.styles.filter((style) => !style.deprecated); basemapStyles.forEach((style, index) => { const layer = getV2Basemap(style.path); styles[style.name] = layer; if (index === 0) { firstStyleLayer = layer; firstStyleLayer.addTo(map); } }); } ); -
Create a
Layerscontrol that referencesbasemapand add it to your map.Layers Use dark colors for code blocks L.esri.get( "https://basemapstyles-api.arcgis.com/arcgis/rest/services/styles/v2/styles/self", { token: accessToken }, (error, response) => { if (error) { console.error("Error fetching basemap styles:", error); return; } const styles = {}; let firstStyleLayer; // Store the first style layer const basemapStyles = response.styles.filter((style) => !style.deprecated); basemapStyles.forEach((style, index) => { const layer = getV2Basemap(style.path); styles[style.name] = layer; if (index === 0) { firstStyleLayer = layer; firstStyleLayer.addTo(map); } }); L.control.layers(styles, null, { collapsed: false }).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 Basemap Styles serviceWhat's next?
Learn how to use additional location services in these tutorials:

Change the basemap style
Switch a vector basemap style on a map.

Change language labels
Switch the language of place labels on a basemap.

Display a custom basemap style
Add a custom vector basemap style to a map.

Style vector tiles
Change the fill and outline color of vector tiles based on their attributes on the client side.

Change the basemap style
Switch a static basemap style on a map.