ts-maps

04 · Style spec

Data of your own on the basemap, through the style: a GeoJSON source, a fill and a line layer over it, and their paint changed at runtime. Layers are added on style.load, once the basemap's style is in place, since setting a style replaces what was there.

Open it full screen · Edit and run it · Full source: 04-style-spec.ts

map.on('style.load', () => {
  map.addSource('midtown', { type: 'geojson', data: polygon })
  map.addStyleLayer({ id: 'midtown-fill', type: 'fill', source: 'midtown', paint: { 'fill-color': '#4f46e5', 'fill-opacity': 0.2 } })
  map.addStyleLayer({ id: 'midtown-line', type: 'line', source: 'midtown', paint: { 'line-color': '#4f46e5', 'line-width': 3 } })
})

map.setPaintProperty('midtown-fill', 'fill-color', '#e11d48')

← Vector tiles, styled from scratch · Heatmap →