Change map styles
This tutorial demonstrates the process of altering map styles, allowing users to seamlessly transition between the built-in maps and their customized maps. Explore the selection of pre-designed styles available in MapTiler’s library by referring to the list of built-in styles.
MapTiler provides a wide range of predefined styles, enabling users to customize their maps to suit their specific preferences. Additionally, you have the option to create a completely 100% customized map using MapTiler’s Customize tool.
Using the built-in styles and their variants defined in the SDK (maptilersdk.MapStyle
) has several advantages such as:
- If we make an update to a style, you won’t have to modify your codebase. Always use the latest version of styles.
- They are easier to remember, no need to type along the style URL. No more putting the API key in every URL.
- Code completion: reducing typos and other common mistakes.
The built-in styles generally define a purpose for which this style is the most relevant: street navigation, outdoor adventure, minimalist dashboard, etc. Then, each style offers a range of variants that contain the same level of information and have the same purpose but use different color schemes like dark, light, etc.
-
Copy the following code, paste it into your favorite text editor, and save it as a
.html
file.
-
Replace
YOUR_MAPTILER_API_KEY_HERE
with your actual MapTiler API key. -
The next is up to you. You can center your map wherever you desire (modifying the
starting position
) and set an appropriate zoom level (modifying thestarting zoom
) to match your users’ needs. Additionally, you can change the map’s look (by updating thesource URL
); choose from a range of visually appealing map styles from our extensive MapTiler standard maps, or create your own to truly differentiate your application.
-
Change the map style to a hybrid satellite images.
- Create a selector to change the map style. In this example we will use some of the build-in styles. See the full list of styles. Copy the following code into your HTML file.
MapStyle.STREETS
, reference style for navigation and city explorationMapStyle.STREETS.DARK
(variant)MapStyle.STREETS.LIGHT
(variant)MapStyle.STREETS.PASTEL
(variant)MapStyle.OUTDOOR
reference style for adventureMapStyle.WINTER
reference style for winter adventureMapStyle.SATELLITE
reference style satellite and airborne imageryMapStyle.HYBRID
reference style satellite and airborne imagery with labelsMapStyle.BASIC
reference style for minimalist design and general purposeMapStyle.BASIC.DARK
(variant)MapStyle.BASIC.LIGHT
(variant)MapStyle.DATAVIZ
the perfect style for data visualization, with very little noiseMapStyle.DATAVIZ.DARK
(variant)MapStyle.DATAVIZ.LIGHT
(variant)MapStyle.BRIGHT
reference style for high contrast navigationMapStyle.BRIGHT.DARK
(variant)MapStyle.BRIGHT.LIGHT
(variant)MapStyle.BRIGHT.PASTEL
(variant)MapStyle.TOPO
reference style for topographic studyMapStyle.TOPO.SHINY
(variant)MapStyle.TOPO.PASTEL
(variant)MapStyle.TOPO.TOPOGRAPHIQUE
(variant)MapStyle.VOYAGER
reference style for stylish yet minimalist mapsMapStyle.VOYAGER.DARK
(variant)MapStyle.VOYAGER.LIGHT
(variant)MapStyle.VOYAGER.VINTAGE
(variant)MapStyle.TONER
reference style for very high contrast stylish mapsMapStyle.TONER.BACKGROUND
(variant)MapStyle.TONER.LITE
(variant)MapStyle.TONER.LINES
(variant)MapStyle.BACKDROP
neutral greyscale style with hillshadingMapStyle.BACKDROP.DARK
(variant)MapStyle.BACKDROP.LIGHT
(variant)MapStyle.OPENSTREETMAP
reference style for OpenStreetMap
-
Change the style when the user select one style.
- Create the layer selector style. Add the selector style to your stylesheet.
Learn more
If you want to switch between built-in styles see this example Built-in map styles.
Check out this tutorial How to display a style switcher control to learn how to create a visual style switcher control.