Basemaps
This guide shows how you can change the basemap in your CARTO for React application. By default, the application will use the CARTO Voyager basemap, but you can choose any other CARTO basemap (Dark Matter, Voyager) or you can also use a Google Maps basemap.
These are the available basemaps:
BASEMAP | PREVIEW | Style description |
---|---|---|
POSITRON | ||
DARK_MATTER | ||
VOYAGER | ||
GOOGLE_ROADMAP | No preview available yet | |
GOOGLE_SATELLITE | No preview available yet | |
GOOGLE_HYBRID | No preview available yet | |
GOOGLE_CUSTOM | No preview available yet |
If you want to change the default (Voyager) basemap, you need to edit the src/store/initialStateSlice.js
file. At the top of this file we are importing the basemap from the @carto/react
package.
For instance, if you want to use a Google Maps roadmap
basemap, you need to import it like this:
Then you need to modify the “basemap” property in the initialState object and provide the Google Maps API key:
Custom basemaps
You can use custom basemaps, in addition to the default basemaps provided by CARTO and Google. In this section we discuss how to configure your application to use these basemaps.
Google custom basemap
If you want to use a Google Maps custom basemap, you need to import it like this in the src/store/initialStateSlice.js
file:
Then you need to modify the “basemap” property in the initialState object and provide the map ID and Google Maps API key:
CARTO custom basemap
CARTO basemaps follow the Mapbox Style Specification. If you want to create your custom basemap, you can use a visual editor like Maputnik. This is the process:
Load the style closest to the basemap you want to create (Positron, Voyager or Dark Matter) through the
Load from URL
option in theOpen Style
dialog, using the URLs provided above.Edit the style properties for each layer you want to customize.
Export the style in JSON format using the
Export
dialog.Add the JSON file to your project (adding it to your public folder is a good choice, for example public/custom_basemap.json).
Edit the
basemap
property in thesrc/store/initialStateSlice.js
:
Custom layer as a basemap
You can also use a custom layer as the basemap. In this case you will be actually not using a basemap but just adding a deck.gl layer in the bottom most position. For instance, this can be used to load a WMTS service using the TileLayer.
You can add the basemap layer to each of the views where you want to use it or even add it to the <Main>
view if you want to use it in all the application views.
Last updated