Published on 20 November 2026
Customize Swiss Map Web Styles
This tutorial is intended for users who want to customize the appearance of swisstopo vector maps. It is particularly useful for GIS professionals, cartographers and web developers. You should be familiar with the basic concepts of web maps and have completed the introductory tutorial on creating and embedding a Swiss Map Web map.
Introduction
The swisstopo vector tile basemaps can be customized using MapLibre GL JS. This allows you to adapt the appearance of the map to your own needs, for example by changing label colors, modifying the appearance of roads, or adjusting the colors of buildings and other map elements. In this tutorial, you will learn how to explore the layers of the swisstopo Base Map style and customize their appearance using MapLibre GL JS. We will start with a basic full-screen map and then introduce different examples of style customizations that you can add to the style.
We will use the following swisstopo Base Map style:
https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json
Before customizing the swisstopo basemap, we first need a webpage that displays it. In this tutorial, we use MapLibre GL JS to load the swisstopo Base Map style and display it across the entire browser window.
Create a new file named index.html and add the following complete HTML code:To customize the appearance of the swisstopo basemap, we need to explore its MapLibre style definition. This is where the rendering layers and their visual properties are defined. The style is provided as a JSON file: https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json
There are two ways to explore the style: you can download and inspect the JSON directly or use Maputnik, a visual style editor.2.1 Explore the Style with Maputnik
If you prefer a visual overview instead of inspecting the JSON code, you can use Maputnik. Maputnik is a free, browser-based editor for MapLibre styles. It displays the available rendering layers in a list and allows you to inspect their properties.
Open the Maputnik editor via the following URL: https://maplibre.org/maputnik/
To load the swisstopo Base Map style:- Open Maputnik in your browser.
- Click Open in the top toolbar.
- Select Load from URL.
- Paste the following style URL into the input field: https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json.
- Click Load from URL to open the style.
The style layers should now appear in the Layers panel. Select an individual layer to inspect its settings, including its type, layout properties, and paint properties. Maputnik also provides a map preview, so you can see how the layers contribute to the overall appearance of the basemap.
Tip: You can use Maputnik to explore the style and understand which properties are available. In this tutorial, however, we will apply our customizations directly in MapLibre JavaScript rather than editing and exporting a separate style file from Maputnik.2.2 Find a Layer to Customize
For our first customization example, we will use the rendering layer with the ID place_city. You can find this layer in the Maputnik Layers panel or search for its ID in the style JSON.
The layer ID is important because we use it in MapLibre to identify which rendering layer we want to customize.A MapLibre style consists of several rendering layers. Each layer controls how a particular type of map information is displayed. For example, a style can contain separate layers for:
- City and place labels
- Roads
- Buildings
- Landcover
- ...
MapLibre allows us to change the properties of these layers directly in JavaScript. Depending on the layer type, we can change text colors, adjust line widths, modify fill colors, and more. These changes are applied when the map is displayed in the browser. The original swisstopo style file is not modified.
In the following examples, we will use MapLibre methods to modify individual layers and their visual properties.
4.1 Change the Text Color with MapLibre
For this example, we will target the MapLibre style layer with the ID place_city. MapLibre identifies rendering layers by their IDs. We use this ID to tell MapLibre which layer we want to customize. MapLibre provides the setPaintProperty() method to change the visual appearance of an existing layer.
To change the text color, we use the following JavaScript command:Add the Customization to Your Map
The customization must be applied after the map style has finished loading. We can do this by using MapLibre's load event. In your existing HTML file, find the MapLibre JavaScript section that initializes the map. Replace your existing section with the following updated version:
Save your HTML file and reload the page in your browser. The city labels should now appear in light grey instead of their original color. Other map elements remain unchanged.
4.2 Hide a specific Style Layer
In the previous example, we changed the color of city labels using map.setPaintProperty(). In this example, we will go one step further and hide smaller town and village labels from the map. MapLibre allows you to control whether a layer is visible using the visibility layout property. We will use this to hide the place_town_village layer. Open your index.html file and find the map.on("load", ...) section from the previous example. Replace that section with the following code:
We are keeping the first customization and adding the second one below it. The map.setLayoutProperty() method takes three arguments:
- Layer ID: place_town_village identifies the layer to modify.
- Property: visibility controls whether the layer is displayed.
- Value: none hides the layer.
- To display it again, use visible.
Save your changes and reload the webpage.
4.3 Add a custom Style Layer
In this example, we will create a simple map showing castles in Switzerland. Instead of using the existing POI symbols from the swisstopo basemap, we will add our own style layer to display castles as circles. We will also add a small tooltip that displays the name of a castle when the user hovers over it. To do this, we will use the points of interest (POI) included in the swisstopo vector tiles. We will select castles based on their `class` attribute and use this data to create our own map layer.
Find the Castle Data in the Vector Tile Schema
Before creating a new style layer, we first need to understand where the castle data is stored. The swisstopo vector tile schema documents the available vector tile layers and their attributes. You can find the documentation here: https://swisstopo.github.io/karto-config-vt-schema-sbm/
In the documentation, open the POI layer. This layer contains points of interest and their associated attributes. One of these attributes is class, which describes the type of point of interest. Castles are identified by the value castle.Add a new Style Layer for Castle
Now that we know where to find the castle data, we can create a new MapLibre style layer to display it. For this example, start with the original swisstopo Base Map style in your HTML file, without any customizations from the previous examples: style: “https://vectortiles.geo.admin.ch/styles/ch.swisstopo.basemap.vt/style.json”
The vector tile source is already included in this style, so we do not need to add a new source. We can simply reference the existing source and its POI source layer. Add the following event after you initialized the map with new maplibregl.Map():Let's look at the most important parts:
- id: The ID of our new style layer. We will use it later to add the tooltip interaction.
- type: We use circle to render the selected features as circular points.
- source-layer: Specifies the POI layer within that vector tile source.
- filter: Selects only features where the class attribute equals castle.
- paint: Defines the appearance of the points, including their radius, fill color and white outline.
Save your changes and reload the webpage. You should now see castles displayed as red circular points on the map.
Hide The existing POI Layers
The original swisstopo style already contains several layers for displaying points of interest. Since we now have our own castle symbols, we want to hide the original POI symbols to avoid displaying both representations.
The four existing layers we want to hide are:- poi_rank1
- poi_rank2
- poi_rank3_rotation_flat
- poi_ranklm
We can hide them using map.setLayoutProperty(), setting their visibility property to none. Add the following code inside the same map.on("load", ...) event, before or after the new `castles` layer:
This hides the original POI symbols without removing the underlying vector tile data. Our new castles layer remains visible.
Add a tooltip showing the Castle Name
As a final step, we want to display the name of a castle when the user moves the mouse pointer over one of our points. MapLibre provides a Popup class that we can use to create a simple tooltip. Add the following code after map.addLayer():
Here is what happens:
- We create a popup without a close button.
- The mousemove event listens for mouse movement over our new castles layer.
- When the pointer is over a castle, we read its name from feature.properties.name.
- We position the popup at the current mouse location using e.lngLat.
- When the pointer leaves the layer, the popup is removed and the cursor returns to its default appearance.
We use setText() to display the name as text rather than interpreting it as HTML.
Your map.on("load", ...) section should now contain all three customizations: adding the castle layer, hiding the original POI layers and setting up the tooltip.
Your HTML file should now look like this:You have now created a new style layer using the existing swisstopo vector tile data. By combining a source layer, a filter and a rendering type, you can create your own map representations without modifying the original swisstopo style file.
By customizing the map style, you can adapt the appearance of swisstopo maps to your specific needs and applications. For example, you can:
- Create simplified maps that focus on selected geographic features.
- Highlight specific points of interest, such as castles, museums or tourist attractions.
- Adapt colours, symbols and labels to make maps easier to read for specific audiences.
- Create thematic map styles that emphasize particular topics or activities.
You can also combine existing swisstopo data with your own geographic data to create customized map representations.
Next step: In the next tutorial, you will learn how to access information stored in vector tiles and combine it with external data sources.
Integrating Swisstopo Vector Tiles with External APIs
