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 Map Designer 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.
Include the following code in your JavaScript file (Example: app.js).
import * as maptilersdk from '@maptiler/sdk';
maptilersdk.config.apiKey = 'YOUR_MAPTILER_API_KEY_HERE';
const map = new maptilersdk.Map({
container: 'map', // container's id or the HTML element to render the map
style: maptilersdk.MapStyle.STREETS,
center: [11.5786, 48.0968], // starting position [lng, lat]
zoom: 10, // starting zoom
});
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 the starting zoom) to match your users’ needs. Additionally, you can change the map’s look (by updating the source 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.
map.setStyle(MapStyle.STREETS.DARK);
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.
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 the starting zoom) to match your users’ needs. Additionally, you can change the map’s look (by updating the source 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.
map.setStyle(MapStyle.STREETS.DARK);
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.