SkilVaultSign inStart free

Catalogue / map-style-scenario-recipes

map-style-scenario-recipes

Older skill: source not recordedSignedBuilds Mapbox GL style recipes for six common map scenarios — POI discovery, property search, analytics, navigation, logistics tracking, and night mode — with complete layer/source definitions, data-driven expressions, clustering, hover states, live updates, and performance guidance. Use when the us…
---
name: map-style-scenario-recipes
description: >-
  Builds Mapbox GL style recipes for six common map scenarios — POI discovery,
  property search, analytics, navigation, logistics tracking, and night mode —
  with complete layer/source definitions, data-driven expressions, clustering,
  hover states, live updates, and performance guidance. Use when the user asks
  to "style a store-finder map", "color parcels by price", "make a dark map
  theme", "show a route", "track drivers on a map", or "fix a Mapbox layer".
  Not for collecting location data without consent, backend tile pipelines,
  or assuming undocumented source layers, sprites, or fonts exist.
---

Map style scenario recipes

Pick the primary task before touching layers. The visual hierarchy should serve one of: discovery, boundary selection, analytical comparison, route following, or live tracking. Design mobile-first; desktop can carry more detail.

Before you style anything

  • Read the installed renderer and style-spec version locally; APIs drift.
  • Identify the loaded sources, their vector source-layer names, property

names, and whether features have stable IDs.

  • Confirm actual sprite (icon) and glyph (font) coverage. A layer that

references a missing icon or font stack renders nothing.

  • icon-color recolors only SDF images — not every bitmap.
  • Check source ordering before inserting with a before layer id; insert

only before a layer that exists.

  • Rendering an existing style makes network requests; establish the token

and source scope with the user before running anything.

| Layer type | Represents | Key properties | |---|---|---| | background | canvas color | background-color | | fill | polygons (parks, parcels) | fill-color, fill-opacity | | line | roads, routes, borders | line-color, line-width | | symbol | labels and icons | text-field, icon-image | | circle | point markers | circle-radius, circle-color | | heatmap | density | heatmap-intensity, heatmap-color | | fill-extrusion | 3D volumes | fill-extrusion-height | | raster | imagery | raster-opacity | | hillshade + raster-dem | terrain shading | hillshade-exaggeration |

These are visual representations, not geographic truth or computed routes.

Choosing a scenario

| Task | What must stay visible | |---|---| | POI discovery | Distinct markers and names, clustering when dense; muted roads/water/parks so photos and content win; collision-aware labels | | Property search | Parcel fills shaded by a price ramp with a legend, crisp parcel outlines, parks/water/schools/transit context | | Analytics | Neutral low-detail base (dashed admin borders, faded major roads, city labels); choropleth or sized points carrying the data | | Navigation | Thick route with casing, readable street names, user position with pulse, maneuver arrows, simplified background | | Logistics | Zone fills/borders by status, service radius, active + completed route, pickup/customer/driver markers, heading arrows, ETA badges | | Night | Near-black backdrop, deep-toned water/parks/buildings, muted roads, light text with dark halos |

Accessibility notes:

  • Do not encode price or risk in red/green alone; add a legend and text

alternatives, and keep an accessible list alongside important map results.

  • A screen-pixel circle is not a geographic delivery radius; use a computed

geodesic polygon in the data.

  • A pulsing marker signals attention, not tracking accuracy.

Data contracts the recipes expect

The recipe builder below builds full inline definitions from supplied GeoJSON. It performs no network calls and invents no features: a missing dataset becomes a visible empty collection. Supply whichever of these you actually have — label layers additionally need a real font stack.

  • Polygons: water, parks, buildings, service zones, radius, analysis areas

(numeric measure), parcels (numeric price)

  • Lines: roads, boundaries, route, completed route
  • Points: POIs (name, category), places, schools, transit, position,

pickup, customer, drivers (id, status, bearing, eta)

  • Validate geometry and properties at ingestion, before rendering.
export function makeRecipe(task, data = {}, options = {}) {
  const tasks = ['poi', 'property', 'analytics', 'navigation', 'logistics', 'night'];
  if (!tasks.includes(task)) throw new Error('Unknown map task');
  const night = task === 'night' || options.night === true;
  const prefix = options.prefix || 'scenario';
  const sources = {};
  const layers = [];
  const empty = () => ({ type: 'FeatureCollection', features: [] });
  const source = (name, extra = {}) => {
    const id = `${prefix}-${name}`;
    if (!sources[id]) sources[id] = { type: 'geojson', data: data[name] || empty(), ...extra };
    return id;
  };
  const add = (name, type, dataset, paint, extra = {}) =>
    layers.push({ id: `${prefix}-${name}`, type, source: source(dataset), paint, ...extra });
  const num = f => ['to-number', ['get', f], 0];
  const ramp = (f, lo, hi, from, to) => ['interpolate', ['linear'], num(f), lo, from, hi, to];
  const zoomWidth = ['interpolate', ['linear'], ['zoom'], 7, 1, 13, 3, 18, 9];
  const dot = (name, dataset, color, radius = 7) => add(name, 'circle', dataset,
    { 'circle-color': color, 'circle-radius': radius,
      'circle-stroke-color': night ? '#17242d' : '#ffffff', 'circle-stroke-width': 2 });
  const label = (name, dataset, field, extraLayout = {}) => {
    if (!options.fontStack) return;                 // no real glyphs -> no label layer
    add(name, 'symbol', dataset,
      { 'text-color': night ? '#e5eef3' : '#26343d',
        'text-halo-color': night ? '#17242d' : '#ffffff', 'text-halo-width': 1 },
      { layout: { 'text-field': ['to-string', ['get', field]],
                  'text-font': options.fontStack, 'text-size': 12,
                  'text-offset': [0, 1.3], ...extraLayout } });
  };

  layers.push({ id: `${prefix}-backdrop`, type: 'background',
                paint: { 'background-color': night ? '#17242d' : '#f3f1eb' } });
  add('water', 'fill', 'water', { 'fill-color': night ? '#203e50' : '#c8dde5', 'fill-opacity': 0.6 });
  add('parks', 'fill', 'parks', { 'fill-color': night ? '#294738' : '#c8d8bd', 'fill-opacity': 0.5 });
  if (night) add('buildings', 'fill', 'buildings',
    { 'fill-color': '#29363d', 'fill-outline-color': '#41515a' });
  add('roads', 'line', 'roads',
    { 'line-color': night ? '#667881' : '#bac3c5', 'line-width': zoomWidth },
    { minzoom: task === 'analytics' ? 9 : 5 });
  if (options.fontStack) label('place-names', 'places', 'name');

  if (task === 'poi' || task === 'night') {
    const id = source('pois', { cluster: true, clusterRadius: 42, clusterMaxZoom: 13 });
    layers.push({ id: `${prefix}-poi-groups`, type: 'circle', source: id,
      filter: ['has', 'point_count'], paint: {
        'circle-color': ['step', num('point_count'), '#226b80', 24, '#825625', 90, '#594d8d'],
        'circle-radius': ['step', num('point_count'), 17, 24, 23, 90, 29],
        'circle-stroke-color': '#ffffff', 'circle-stroke-width': 1 } });
    dot('poi-items', 'pois',
      ['match', ['get', 'category'], 'cafe', '#825625', 'restaurant', '#594d8d', '#226b80']);
    layers[layers.length - 1].filter = ['!', ['has', 'point_count']];
    label('poi-names', 'pois', 'name');
    if (options.fontStack) {
      label('poi-counts', 'pois', 'point_count_abbreviated', { 'text-offset': [0, 0] });
      layers[layers.length - 1].filter = ['has', 'point_count'];
    }
  }

  if (task === 'property') {
    if (!(options.priceHigh > options.priceLow))
      throw new Error('Set observed increasing price bounds');
    add('parcel-shading', 'fill', 'parcels',
      { 'fill-color': ramp('price', options.priceLow, options.priceHigh, '#dceaf0', '#315a83'),
        'fill-opacity': 0.4 });
    add('parcel-outline', 'line', 'parcels', { 'line-color': '#594d8d', 'line-width': 1.5 });
    dot('schools', 'schools', '#825625'); label('school-labels', 'schools', 'name');
    dot('transit', 'transit', '#226b80', 5);
  }

  if (task === 'analytics') {
    if (!(options.measureHigh > options.measureLow))
      throw new Error('Set the observed measurement domain');
    add('area-measure', 'fill', 'areas',
      { 'fill-color': ramp('measure', options.measureLow, options.measureHigh, '#e4eef1', '#27546d'),
        'fill-opacity': 0.7 });
    add('admin-outline', 'line', 'boundaries',
      { 'line-color': '#697983', 'line-width': 1, 'line-dasharray': [2, 2] });
    dot('scaled-observations', 'observations', '#594d8d',
      ['*', ['sqrt', ['max', 0, num('population')]], options.populationScale || 0.02]);
  }

  if (task === 'navigation' || task === 'logistics') {
    add('route-casing', 'line', 'route', { 'line-color': '#ffffff', 'line-width': 9 });
    add('route-core', 'line', 'route', { 'line-color': '#27546d', 'line-width': 5 },
      { layout: { 'line-cap': 'round', 'line-join': 'round' } });
    dot('position', 'position', '#27546d', 8);
    dot('position-halo', 'position', '#27546d', 14);
    layers[layers.length - 1].paint['circle-opacity'] = 0.15;
    if (options.arrowImage) add('maneuver-arrows', 'symbol', 'maneuvers', {},
      { layout: { 'icon-image': options.arrowImage, 'icon-rotate': num('bearing'),
                  'icon-rotation-alignment': 'map', 'icon-size': 0.7 } });
  }

  if (task === 'logistics') {
    const zoneColor = ['match', ['get', 'status'],
      'available', '#226b80', 'busy', '#825625', 'unavailable', '#594d8d', '#697983'];
    add('service-zones', 'fill', 'zones', { 'fill-color': zoneColor, 'fill-opacity': 0.16 });
    add('zone-borders', 'line', 'zones', { 'line-color': zoneColor, 'line-width': 2, 'line-dasharray': [2, 2] });
    add('radius-shading', 'fill', 'radius', { 'fill-color': '#226b80', 'fill-opacity': 0.12 });
    add('radius-edge', 'line', 'radius', { 'line-color': '#226b80', 'line-width': 1.5, 'line-dasharray': [4, 2] });
    add('completed-route', 'line', 'completed', { 'line-color': '#594d8d', 'line-width': 5 });
    dot('pickup', 'pickup', '#825625', 9); label('pickup-labels', 'pickup', 'name');
    dot('customer', 'customer', '#594d8d', 9);
    dot('customer-halo', 'customer', '#594d8d', 16);
    layers[layers.length - 1].paint['circle-opacity'] = 0.18;
    dot('driver-shadow', 'drivers', '#17242d', 11);
    layers[layers.length - 1].paint['circle-opacity'] = 0.2;
    layers[layers.length - 1].paint['circle-translate'] = [1, 2];
    dot('drivers', 'drivers',
      ['match', ['get', 'status'], 'picking_up', '#825625',
       'en_route', '#226b80', 'delivered', '#594d8d', '#697983'], 9);
    if (options.arrowImage) add('driver-heading', 'symbol', 'drivers', {},
      { layout: { 'icon-image': options.arrowImage, 'icon-rotate': num('bearing'),
                  'icon-rotation-alignment': 'map', 'icon-size': 0.5 } });
    if (options.fontStack) {
      label('driver-eta', 'drivers', 'eta', { 'text-offset': [0, -1.8],
        'text-field': ['concat', ['to-string', ['get', 'eta']], ' min'] });
    }
  }
  return { sources, layers };
}

Caveats for the builder output:

  • to-number maps missing values to 0, which can misrepresent data; filter

invalid rows or style an explicit no-data class with a legend.

  • Price/measure bounds and the population scale are product inputs from

observed data — there are no universal thresholds.

  • The returned layer order is a starting point; logistics zones usually go

beneath routes and markers. Review the full list, then reorder.

  • Source geometry must match each layer's type (polygons for fill, etc.).

Helper functions: install, hover, updates, pulse

The arrow icon is generated locally as raw RGBA pixels — no sprite download, no assumption about bundled icon sets. Register it with a unique image id using the installed renderer's addImage before any symbol layer needs it.

export function arrowPixels(size = 24) {

Preview shortened. The full SKILL.md is in the pack.