Custom style

When changing the built-in theme is not enough (see Style), a style of your own answers one question for every feature of every tile: how does it draw? On the web the map parses tiles in WebAssembly workers, so a style can’t be written in TypeScript yet. This page says what a style is made of and how far the theme takes you instead.

Two halves

A map style is two pieces:

  • The schema says what a feature is: a road in a tunnel, a building 30 m tall, a place with names in several languages. It reads the tile’s tags, which every tile provider spells its own way.
  • The style says how it looks: colours, widths, labels. It reads the schema’s answer, never the tags again.

On the web both are built into the tile workers. A function in TypeScript cannot run inside that parse without a call across the worker boundary for every feature, which is the cost the workers are there to avoid.

A style

settings.mapStyle(...) takes the built-in style in a theme, nothing else. A look of your own comes from the theme instead. It reaches every colour of the ground, the roads, the buildings’ features, the trees, the names and the relief shading:

const grey = (level: number): [number, number, number, number] => [level, level, level, 1];

const settings = ImmersiveMapSettings.default.edit((draft) => {
  const theme = draft.mapStyle.theme;
  theme.layers.land = grey(0.95);
  theme.layers.water = [0.75, 0.8, 0.85, 1];
  for (const cover of ["wood", "grass", "farmland", "sand", "wetland", "park", "residential", "industrial"] as const) {
    theme.layers[cover] = grey(0.93);
  }
  theme.labels.city.fillColor = [0.2, 0.2, 0.2];
  theme.labels.city.strokeColor = [1, 1, 1];
  theme.labels.city.weight = "bold";
});

const map = await ImmersiveMap.create({ container, settings });
  • The label text is not the theme’s. The map shows the schema’s name in the map’s language (.labelSettings({ language })), and the theme says only how it looks.
  • The cache. The map keeps parsed tiles on disk under a fingerprint of everything the parse depends on, the theme included, so a changed theme never shows tiles drawn by the old one. There is no fingerprint of your own to keep up to date.
  • Beyond the colours, the theme also holds the road widths by class (roadMetrics), the route shields (routeShields), which labels show at which zoom (labelVisibility), the trees’ palette (layers.trees), the relief shading (hillshade, terrainOcclusion) and the label opacity by zoom (labelOpacity).

The globe’s overview biomes are laid into the tiles of zooms 0 to 7 under the archive’s own land cover. .overviewTiles({ isEnabled: false }) leaves them out:

ImmersiveMapSettings.default.overviewTiles({ isEnabled: false });

A schema

The built-in schema reads the Protomaps basemap schema, and there is no schema of your own on the web. An archive in another schema does not draw correctly.

The code of this page is in examples/custom-style.ts.