Skip to content

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 ​

typescript
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 */ ],
}
PartServed byNeeds a token?
sources (tiles)SimVector, via simvector://Yes, added by the protocol handler
sprite (icon atlas)You, as static filesNo
glyphs (font PBFs)You, as static filesNo

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/:

text
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:

typescript
const origin = typeof window === 'undefined' ? '' : window.location.origin

Concatenate, 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:

typescript
layout: { 'text-font': ['OpenSansRegular'], 'text-field': ['get', 'name'] }

Sources ​

Globe (vector) ​

typescript
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) ​

typescript
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:

  1. background
  2. Terrain tint (color-relief) and hillshade, if used
  3. land, water, water_lines
  4. streets, buildings, boundaries
  5. Aviation surfaces: aprons, aerodromes, taxiways, runways, aeroway_markings, parking_positions, helipads
  6. aero_navaids, obstacles
  7. Labels: boundary_labels, place_labels, aerodrome, runway and navaid labels
  8. 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:

LayerSuggested minzoom
aerodromes (labels)8
runways (lines)9
aerodromes, runways, taxiways (areas), aprons, aero_navaids, obstacles10
taxiways (centerlines)11
helipads12
aeroway_markings13
parking_positions15

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:

typescript
{
  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:

typescript
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:

TechniqueLayer / APINotes
Hypsometric tintcolor-relief layerColour by elevation in metres. See the VFR bands.
Hillshadehillshade layerhillshade-exaggeration around 0.3 looks natural.
3D terrainmap.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:

typescript
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:

typescript
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:

typescript
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:

typescript
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 ​

SymptomLikely cause
Map is blank, console shows 401Token problem. See Authentication.
Map draws but no textglyphs URL is wrong, the font stack in text-font does not match your hosted folder, or the PBFs are not being served.
Icons missingsprite URL is wrong or the icon name is not in your sprite sheet.
Fonts fail with a 404 for %7Bfontstack%7DYou built the glyphs URL with new URL(). Concatenate the string instead.
Elevation looks torn along tile edgesThe DEM source is missing tileSize: 512.
Terrain looks flat or wrong heightsThe DEM source is missing encoding: 'mapbox', or exaggeration is too low.
Nothing from aerodromes / runwaysYou are below the layer's minzoom; zoom in.

AMXM schema © 2024 RTCA, EUROCAE. Use does not imply endorsement by RTCA or EUROCAE.