VersaTiles Style
VersaTiles Style generates styles and sprites for MapLibre.
Upgrading from v5? v6 is a breaking release: the palette builders (colorful,shadow, …) are
replaced byosm({ theme }), options are grouped (textScale→layout.scale.labels), all 34 of
the renamed colour keys moved under a group prefix, and both sprite sheets were renamed.
Unknown option keys now throw, and the error names the v6 replacement.
> - Migration from v5 — the full option, colour-key and type tables.
- Migrating sprite ids from v5 —basics→baseandmarkers→extras/icons.
- CHANGELOG — every breaking change in 6.0.0.
Styles Overview
The osm() function renders OpenStreetMap vector tiles using one of five built-in color palettes,
each available as a light theme and a dark one (colorful-dark, …). satellite() renders raster/satellite tiles with an optional
vector overlay.
| Palette | Preview |
| ------------- | ----------------------------------------------------------------------------------------------------- |
| colorful |
|
| natural |
|
| muted |
|
| gray |
|
| toner |
|
| satellite |
|
Using VersaTiles Styles
Prebuilt Styles and Sprites
Download the assets from the latest release:
- styles.tar.gz: Contains all styles in multiple languages.
tiles.versatiles.org as the source for tiles, fonts (glyphs), and icons (sprites).
- sprites.tar.gz: Includes map icons and other sprites.
- Sprite overview: every icon in all three sheets, with its sprite ID, title and aliases.
- versatiles-style.tar.gz: Contains a JavaScript file to generate styles dynamically in the browser.
Generating Styles On-the-Fly
Frontend Usage (Web Browser)
Download the latest release:
curl -Ls "https://github.com/versatiles-org/versatiles-style/releases/latest/download/versatiles-style.tar.gz" | gzip -d | tar -xf -
Integrate it into your HTML application:
<div id="map"></div>
<script src="maplibre-gl.js"></script>
<script src="versatiles-style.js"></script>
<script>
(async () => {
const style = VersaTilesStyle.osm({
theme: 'colorful-dark',
text: { language: 'de' },
recolor: { gamma: 0.5 },
});
const map = new maplibregl.Map({
container: 'map',
style: await VersaTilesStyle.inlineSources(style),
});
})();
</script>
inlineSourcesis required, not optional.osm()andsatellite()are synchronous and do no
I/O: they leave each source as a { type, url } reference to a TileJSON and let MapLibre fetch it.
That works only if the TileJSON lists absolute tile URLs — and the VersaTiles ones list relative
templates (/tiles/osm/{z}/{x}/{y}), which MapLibre does not resolve. Handing such a style straight
to new maplibregl.Map() fails with
Request constructor: /tiles/osm/2/2/2 is not a valid URL and no tiles appear.
> inlineSources fetches the TileJSON and folds it in, so the tile URLs come out absolute and the
attribution, bounds and maxzoom it carries are preserved. That last part matters: the attribution
is a licensing obligation.
> If your own tile server publishes absolute tile URLs, you can skip it and stay fully synchronous.
Requires MapLibre GL JS 5.0 or newer.
The generated styles set the globe projection
and a root sky. Older versions ignore both and
render a flat Mercator map with no sky — everything else works, so this degrades rather than breaks.
> npm users have this checked automatically through an optional peer dependency. Loading MapLibre
from a tag, as above, bypasses that check entirely — so verify the version yourself.
To stay on Mercator deliberately, pass projection: 'mercator'.
Backend Usage (Node.js)
Install the library via NPM:
npm install @versatiles/style
Generate styles programmatically:
import { osm, inlineSources } from '@versatiles/style';
import { writeFileSync } from 'node:fs';
const style = osm({
theme: 'colorful',
text: { language: 'en' },
});
// resolves the TileJSON reference into absolute tile URLs — see the note above
writeFileSync('style.json', JSON.stringify(await inlineSources(style)));
A style.json written without inlineSources still carries a url reference, so whoever loads it
hits the same relative-tile problem. This is exactly what the published styles do — build-styles.ts
calls inlineSources before writing each one.
Style Generation Methods
osm() and satellite() are synchronous and do no I/O; guessStyle() is asynchronous,
because it has to read the TileJSON before it can decide what to build. All three return a MapLibre
StyleSpecification — pass it through inlineSources before handing it to MapLibre, as above:
osm(options)- OpenStreetMap vector style. Documentation
theme: a palette name ('colorful' | 'natural' | 'muted' | 'gray' | 'toner'), or its dark theme with a -dark suffix ('colorful-dark', …).
- text: label language, and fonts — a glyph name per label topic ({ water: 'fira_sans_regular_italic' }).
- colors, recolor, layers, features, urls: see OsmOptions.
satellite(options)- raster/satellite style with an optional OSM overlay. Documentation — see SatelliteOptions.guessStyle(source)- inspect a tileset, given as a TileJSON URL or object, and return the most appropriate style. Documentation
import { guessStyle } from '@versatiles/style';
const style = await guessStyle(tileJSON); // or the URL of a TileJSON document
guessSchema(tileJSON)- recognise a vector tileset's schema ('shortbread' | 'openmaptiles' | 'protomaps') from its TileJSON object, synchronously and without I/O. It reads onlyvector_layers, and scores every schema so a caller can see why. Documentation
import { guessSchema } from '@versatiles/style';
const guess = guessSchema(tileJSON); // { type: 'vector', schema: 'openmaptiles', candidates: [...] }
guessOptions(style)- from@versatiles/style/migrate: read a MapLibre style built for OpenMapTiles, Protomaps or Shortbread tiles, and return theosm()orsatellite()options whose style looks most like it — for moving a map onto VersaTiles.deriveOptions(style, tileJSONs?, fontNames?)is its synchronous, I/O-free core.
import { osm } from '@versatiles/style';
import { guessOptions } from '@versatiles/style/migrate';
const guess = await guessOptions('https://example.org/my-style/style.json');
if (guess.kind === 'osm') map.setStyle(osm(guess.options)); // guess.report says what was not carried over
fetchFontFaces(urls?)andfontCovers(face, language)- for a font picker overtext.fonts: the faces a glyph server publishes (from itsfont_families.json), with titles, and whether a face has the glyphs for a label language.osm.fontGroupslists the layers each font topic sets.
import { fetchFontFaces, fontCovers } from '@versatiles/style';
const faces = await fetchFontFaces(); // undefined when the server publishes no list
const forGreek = faces?.filter((face) => fontCovers(face, 'el') !== false);
Build Instructions
Prerequisites
To build new sprites, ensure optipng is installed.
SVG Source Requirements
- SVGs must consist only of paths and should not contain any
transform()attributes. - Styles and colors within the SVG are ignored.
- All length values must be specified in pixels without units.
Recommended icon sources
When adding new icons, Pinhead Map Icons (source) is a useful starting point — a CC0-licensed collection of 1000+ cartographic SVGs designed to be legible at pin-marker scale, unifying icons from Maki, Temaki, OSM Carto, and NPMap.
Configuration
Define icon sets in the configuration file: scripts/config/sprites.ts
Development
Run the project in development mode:
npm run dev
A local server will be available at src/themes/... and src/shortbread/..., and reload the page to view the changes.
Dependency Graph
---
config:
layout: elk
flowchart TB
subgraph 0["src"]
subgraph 1["api"]
2["code.ts"]
Q["guessSchema.ts"]
S["guessStyle.ts"]
1I["osm.ts"]
2P["satellite.ts"]
2Q["index.ts"]
2R["schema-builder.ts"]
end
subgraph 3["options"]
4["urls.ts"]
8["keys.ts"]
9["v5-hints.ts"]
A["colors.ts"]
P["sprite.ts"]
T["index.ts"]
U["osm-overlay.ts"]
V["parts.ts"]
W["features-hillshade.ts"]
X["features-terrain.ts"]
Y["features.ts"]
Z["fonts.ts"]
10["layer-groups.ts"]
11["layout.ts"]
12["projection.ts"]
13["recolor.ts"]
14["satellite-raster.ts"]
15["sky.ts"]
16["sun.ts"]
17["text.ts"]
18["theme.ts"]
19["osm.ts"]
1A["satellite.ts"]
23["minimize.ts"]
end
subgraph 5["lib"]
6["index.ts"]
7["fetchFontFaces.ts"]
I["utils.ts"]
J["fetchTileJSON.ts"]
K["loadTileSource.ts"]
L["fontCovers.ts"]
M["inlineSources.ts"]
N["tileSource.ts"]
O["styleMeta.ts"]
R["schema-signatures.ts"]
1D["opacity.ts"]
22["languages.ts"]
2U["schema-audit.ts"]
end
subgraph B["themes"]
C["index.ts"]
D["colorful.ts"]
E["gray.ts"]
F["muted.ts"]
G["natural.ts"]
H["toner.ts"]
49["types.ts"]
end
subgraph 1B["features"]
1C["satellite-overlay.ts"]
1T["index.ts"]
1U["elevation-source.ts"]
1V["hillshade.ts"]
1W["landcover.ts"]
1X["layout.ts"]
1Y["projection.ts"]
1Z["sky.ts"]
20["sun.ts"]
21["terrain.ts"]
end
subgraph 1E["types"]
1F["index.ts"]
1G["tilejson.ts"]
1H["vector_layer.ts"]
4A["maplibre.ts"]
end
subgraph 1J["color"]
1K["index.ts"]
1L["parse.ts"]
1M["abstract.ts"]
1N["hsl.ts"]
1O["hsv.ts"]
1P["random.ts"]
1Q["utils.ts"]
1R["rgb.ts"]
1S["recolor.ts"]
end
subgraph 24["shortbread"]
25["layer-groups-map.ts"]
29["context.ts"]
subgraph 2B["layers"]
2C["* (13 files)"]
end
2G["schema.ts"]
2N["index.ts"]
2O["groups.ts"]
end
subgraph 26["dsl"]
27["group-maps.ts"]
28["fonts.ts"]
2A["context.ts"]
2D["assemble.ts"]
2E["build.ts"]
2F["index.ts"]
end
subgraph 2H["cartography"]
2I["boundaries.ts"]
2J["buildings.ts"]
2K["labels.ts"]
2L["roads.ts"]
2M["transitstops.ts"]
end
2S["index.ts"]
2T["variants.ts"]
subgraph 2V["migrate"]
2W["calibrate.ts"]
2X["evaluate.ts"]
2Y["math.ts"]
2Z["probes.ts"]
30["derive.ts"]
31["guess.ts"]
32["index.ts"]
end
subgraph 33["omt"]
34["api.ts"]
35["context.ts"]
36["schema.ts"]
37["layer-groups-map.ts"]
subgraph 38["layers"]
39["index.ts"]
3A["airport.ts"]
3B["background.ts"]
3C["boundaries.ts"]
3D["buildings.ts"]
3E["labels.ts"]
3F["landcover.ts"]
3G["markings.ts"]
3H["pois.ts"]
3I["roads.ts"]
3J["sites.ts"]
3K["transitstops.ts"]
3L["water.ts"]
end
3M["options.ts"]
3N["index.ts"]
end
subgraph 3O["protomaps"]
3P["api.ts"]
3Q["context.ts"]
3R["schema.ts"]
3S["layer-groups-map.ts"]
subgraph 3T["layers"]
3U["index.ts"]
3V["airport.ts"]
3W["background.ts"]
3X["boundaries.ts"]
3Y["buildings.ts"]
3Z["labels.ts"]
40["landcover.ts"]
41["markings.ts"]
42["pois.ts"]
43["roads.ts"]
44["sites.ts"]
45["transitstops.ts"]
46["water.ts"]
end
47["options.ts"]
48["index.ts"]
end
end
2-->4
4-->6
4-->8
4-->P
6-->7
6-->J
6-->L
6-->M
6-->K
6-->O
6-->N
6-->I
7-->8
7-->4
7-->I
8-->9
9-->A
A-->C
A-->8
C-->D
C-->E
C-->F
C-->G
C-->H
J-->8
J-->K
K-->I
M-->8
M-->K
M-->N
N-->I
P-->6
Q-->R
S-->6
S-->R
S-->T
S-->8
S-->1F
S-->Q
S-->1I
S-->2P
T-->U
T-->19
T-->V
T-->1A
U-->8
U-->V
V-->A
V-->W
V-->X
V-->Y
V-->Z
V-->10
V-->11
V-->12
V-->13
V-->14
V-->15
V-->P
V-->16
V-->17
V-->18
V-->4
W-->8
X-->8
Y-->W
Y-->X
Y-->8
Z-->8
10-->8
11-->8
13-->8
14-->8
15-->8
16-->8
17-->Z
17-->8
18-->C
19-->8
19-->V
1A-->1C
1A-->8
1A-->U
1A-->V
1C-->1D
1C-->Z
1C-->17
1F-->1G
1F-->1H
1I-->1K
1I-->1T
1I-->6
1I-->22
1I-->T
1I-->23
1I-->2N
1I-->25
1I-->2C
1I-->2G
1I-->C
1I-->2
1K-->1L
1K-->1S
1L-->1M
1L-->1N
1L-->1O
1L-->1R
1N-->1M
1N-->1O
1N-->1R
1N-->1Q
1O-->1M
1O-->1N
1O-->1P
1O-->1R
1O-->1Q
1P-->1O
1P-->1Q
1R-->1M
1R-->1N
1R-->1O
1R-->1Q
1S-->1L
1T-->1U
1T-->1V
1T-->1W
1T-->1X
1T-->1Y
1T-->1C
1T-->1Z
1T-->20
1T-->21
1U-->6
1V-->1U
21-->1U
23-->1K
23-->25
23-->W
23-->X
23-->Z
23-->10
23-->11
23-->19
23-->13
23-->1A
23-->16
23-->18
23-->4
25-->27
25-->1C
25-->T
25-->29
25-->2C
27-->28
28-->Z
29-->2A
2A-->1K
2A-->T
2A-->C
2C-->2D
2C-->2F
2C-->2G
2C-->2I
2C-->2J
2C-->2K
2C-->2L
2C-->2M
2D-->2E
2D-->28
2E-->1K
2E-->1D
2F-->2D
2F-->2E
2F-->2A
2F-->28
2I-->2F
2J-->2F
2K-->2F
2L-->2F
2M-->2F
2N-->29
2N-->2O
2N-->2C
2O-->2C
2P-->1T
2P-->6
2P-->T
2P-->23
2P-->2N
2P-->25
2P-->2
2P-->1I
2Q-->Q
2Q-->S
2Q-->1I
2Q-->2P
2S-->2Q
2S-->1K
2S-->6
2S-->T
2S-->1F
2S-->2T
2T-->2Q
2T-->T
2W-->1K
2W-->T
2W-->2X
2W-->2Y
2W-->2Z
30-->Q
30-->1I
30-->2P
30-->28
30-->T
30-->25
30-->2G
30-->C
30-->2W
30-->2X
30-->2Y
30-->2Z
31-->6
31-->8
31-->30
32-->30
32-->31
34-->2
34-->1K
34-->1T
34-->6
34-->22
34-->T
34-->C
34-->35
34-->37
34-->39
34-->3M
34-->36
35-->2A
35-->36
37-->27
37-->35
37-->39
37-->3M
39-->2D
39-->2F
39-->36
39-->3A
39-->3B
39-->3C
39-->3D
39-->3E
39-->3F
39-->3G
39-->3H
39-->3I
39-->3J
39-->3K
39-->3L
3A-->2F
3B-->2F
3C-->2I
3D-->2J
3E-->2K
3E-->2F
3F-->2F
3G-->2F
3H-->2F
3I-->2L
3J-->2F
3K-->2M
3L-->2F
3M-->I
3M-->T
3M-->8
3M-->23
3N-->34
3N-->36
3P-->2
3P-->1K
3P-->1T
3P-->6
3P-->22
3P-->T
3P-->C
3P-->3Q
3P-->3S
3P-->3U
3P-->47
3P-->3R
3Q-->2A
3Q-->3R
3S-->27
3S-->3Q
3S-->3U
3S-->47
3U-->2D
3U-->2F
3U-->3R
3U-->3V
3U-->3W
3U-->3X
3U-->3Y
3U-->3Z
3U-->40
3U-->41
3U-->42
3U-->43
3U-->44
3U-->45
3U-->46
3V-->2F
3W-->2F
3X-->2I
3Y-->2J
3Z-->2K
3Z-->2F
40-->2F
41-->2F
42-->2F
43-->2L
44-->2F
45-->2M
46-->2F
47-->I
47-->T
47-->8
47-->23
48-->3P
48-->3R
class 0,1,3,5,B,1B,1E,1J,24,2B,26,2H,2V,33,38,3O,3T subgraphs;
classDef subgraphs fill-opacity:0.1, fill:#888, color:#888, stroke:#888;
Licenses
- Source Code: Unlicense
- Iconsets and Rendered Spritemaps: CC0 1.0 Universal