Building a Map Style
A MapLibre style is a JSON document that says where tiles come from (sources) and how to draw them (layers). SimVector provides the tiles; the style is yours. This guide shows how the pieces fit together. It assumes you have finished the Quick Start.
The parts of a style
const style = {
version: 8,
sprite: `${origin}/map/sprites`, // icons
glyphs: `${origin}/map/{fontstack}/{range}.pbf`, // text fonts
sources: { /* where tiles come from */ },
layers: [ /* how to draw them, bottom to top */ ],
}| Part | Served by | Needs a token? |
|---|---|---|
sources (tiles) | SimVector, via simvector:// | Yes, added by the protocol handler |
sprite (icon atlas) | You, as static files | No |
glyphs (font PBFs) | You, as static files | No |
Sprites and glyphs are your responsibility
Only tiles go through the simvector:// protocol. Host your own sprite sheet and font glyph files as static assets on your own origin and point sprite and glyphs at them. Without glyphs, text layers will not render; without sprite, icon layers will not.
Hosting sprites and glyphs
Place them under a path on your site, for example /map/:
public/map/
├── sprites.json
├── sprites.png
├── sprites@2x.json
├── sprites@2x.png
└── OpenSansRegular/
├── 0-255.pbf
├── 256-511.pbf
└── …Then reference them with an absolute URL. MapLibre requires absolute URLs here, so build one from window.location.origin:
const origin = typeof window === 'undefined' ? '' : window.location.originConcatenate, don't use new URL()
Build the glyphs string by concatenation. new URL('/map/{fontstack}/{range}.pbf', origin) percent-encodes the {fontstack} and {range} placeholders and breaks font loading.
Whatever font stack you host is the one you must name in text-font:
layout: { 'text-font': ['OpenSansRegular'], 'text-field': ['get', 'name'] }Sources
Globe (vector)
sources: {
'vector-tiles': {
type: 'vector',
tiles: ['simvector://globe/{z}/{x}/{y}.pbf'],
minzoom: 0,
maxzoom: 14,
attribution: '<a href="https://simvector.net/">© SimVector</a> | <a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> | <a href="https://docs.simvector.net/anav/tiles/attributions">Attributions</a>',
},
}The tiles stop at zoom 14. Beyond that MapLibre overzooms: it keeps drawing the zoom-14 tiles larger, so you can leave the map's maxZoom at its default. See the Globe specification for every source layer and attribute.
Terrain (raster-dem)
sources: {
'elevation-dem': {
type: 'raster-dem',
tiles: ['simvector://global_elevation_90m/{z}/{x}/{y}.png'],
encoding: 'mapbox',
tileSize: 512,
minzoom: 0,
maxzoom: 10,
bounds: [-180, -89.9511287798066, 180, 85.0511287798066],
},
}tileSize: 512 is required; see the Terrain specification.
A DEM source is only loaded when something uses it
If every layer that reads elevation-dem is hidden, MapLibre does not request its tiles. You can keep the source in your style and toggle hillshade or tinting on demand without paying for the traffic up front.
Layers
Layers draw bottom to top, in array order. A sensible order for SimVector data is:
background- Terrain tint (
color-relief) and hillshade, if used land,water,water_linesstreets,buildings,boundaries- Aviation surfaces:
aprons,aerodromes,taxiways,runways,aeroway_markings,parking_positions,helipads aero_navaids,obstacles- Labels:
boundary_labels,place_labels, aerodrome, runway and navaid labels - Your own overlays (routes, traffic, markers)
Choosing zoom levels
Aviation layers exist from low zoom, but detail only makes sense when zoomed in. Typical thresholds that work well:
| Layer | Suggested minzoom |
|---|---|
aerodromes (labels) | 8 |
runways (lines) | 9 |
aerodromes, runways, taxiways (areas), aprons, aero_navaids, obstacles | 10 |
taxiways (centerlines) | 11 |
helipads | 12 |
aeroway_markings | 13 |
parking_positions | 15 |
These are styling choices, not data limits. Check the Globe specification for the zoom range where each layer actually carries data.
Styling by attribute
Most basemap layers carry a kind (and sometimes class) attribute you can match on:
{
id: 'streets-major',
type: 'line',
source: 'vector-tiles',
'source-layer': 'streets',
minzoom: 5,
filter: ['in', ['get', 'kind'], ['literal', ['motorway', 'trunk', 'primary']]],
paint: { 'line-color': '#475569', 'line-width': 1.2 },
}Labels commonly fall back through several attributes. For example, aerodrome labels prefer icao, then iata, then name:
layout: { 'text-field': ['coalesce', ['get', 'icao'], ['get', 'iata'], ['get', 'name']] }Place and boundary labels use name_en with a fallback to name.
Terrain
SimVector DEM tiles can drive three things, from cheapest to most expensive:
| Technique | Layer / API | Notes |
|---|---|---|
| Hypsometric tint | color-relief layer | Colour by elevation in metres. See the VFR bands. |
| Hillshade | hillshade layer | hillshade-exaggeration around 0.3 looks natural. |
| 3D terrain | map.setTerrain({ source: 'elevation-dem', exaggeration: 1 }) | Requires the source to be loaded; best with pitch. |
Tint and hillshade are independent of 3D terrain; many apps use only those two.
Light and dark themes
Keep one set of layers and re-colour them when the theme changes, rather than replacing the whole style. Replacing the style would remove any layers you added at runtime (routes, traffic). Re-apply paint properties instead:
function applyTheme(map, palette) {
map.setPaintProperty('background', 'background-color', palette.background)
map.setPaintProperty('land', 'fill-color', palette.land)
map.setPaintProperty('water', 'fill-color', palette.water)
// …one call per themed layer
}Define your palettes in one place and loop over them so adding a layer is a one-line change.
Showing and hiding groups
Group related layers and toggle them together with setLayoutProperty:
const groups = {
runways: ['runway-areas', 'runway-lines', 'runway-labels'],
hillshade: ['terrain-hillshade'],
}
function setGroupVisible(map, name, visible) {
for (const id of groups[name]) {
map.setLayoutProperty(id, 'visibility', visible ? 'visible' : 'none')
}
}Start layers you rarely need (tint, hillshade) with layout: { visibility: 'none' }.
Attribution
Show the Globe source's attribution on the map, and link to Attributions for the terrain credits. If you create the map with attributionControl: false, add it back yourself so the credit stays visible:
const map = new maplibregl.Map({ container: 'map', style, attributionControl: false })
map.addControl(new maplibregl.AttributionControl({ compact: true }), 'bottom-right')Adding your own data on top
Add GeoJSON sources and layers after the style has loaded, and insert them above the base layers:
map.on('load', () => {
map.addSource('routes', { type: 'geojson', data: routesGeoJson })
map.addLayer({
id: 'routes-lines',
type: 'line',
source: 'routes',
paint: { 'line-color': '#38bdf8', 'line-width': 2 },
})
})Troubleshooting
| Symptom | Likely cause |
|---|---|
Map is blank, console shows 401 | Token problem. See Authentication. |
| Map draws but no text | glyphs URL is wrong, the font stack in text-font does not match your hosted folder, or the PBFs are not being served. |
| Icons missing | sprite URL is wrong or the icon name is not in your sprite sheet. |
Fonts fail with a 404 for %7Bfontstack%7D | You built the glyphs URL with new URL(). Concatenate the string instead. |
| Elevation looks torn along tile edges | The DEM source is missing tileSize: 512. |
| Terrain looks flat or wrong heights | The DEM source is missing encoding: 'mapbox', or exaggeration is too low. |
Nothing from aerodromes / runways | You are below the layer's minzoom; zoom in. |