All skills
mapbox avatar

/mapbox-style-patterns

@9077a82 official
by mapboxmapbox/mapbox-agent-skills80 stars
17

Common style patterns, layer configurations, and recipes for typical mapping scenarios including restaurant finders, real estate, data visualization, navigation, delivery/logistics, and more. Use when implementing specific map use cases or looking for proven style patterns.

Use this Skill: https://skilld.dev/gh/mapbox/mapbox-agent-skills/mapbox-style-patterns

This session only. Nothing lands on disk.

referencesinteractions.md

≈1.4k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Interactions: addInteraction, setFeatureState, and appearances

Three complementary mechanisms, not competing alternatives. They form a pipeline:

addInteraction (bind the event) -> setFeatureState (flip the state) -> appearances or raw feature-state expressions (apply the visual change)

addInteraction + setFeatureState

addInteraction (GL JS v3.9+) binds click/mouseenter/mouseleave events to features, replacing map.on(event, layerId, handler). Its handler is where you call setFeatureState to record what happened.

// Custom layer: target by layerId
map.addInteraction('building-hover', {
  type: 'mouseenter',
  target: { layerId: 'buildings-layer' },
  handler: ({ feature }) => {
    if (hoveredBuilding) {
      map.setFeatureState(hoveredBuilding, { highlight: false });
    }
    hoveredBuilding = feature;
    map.setFeatureState(feature, { highlight: true });
    map.getCanvas().style.cursor = 'pointer';
  }
});

// Standard Style / style-import featureset: target by featuresetId + importId
map.addInteraction('place-click', {
  type: 'click',
  target: { featuresetId: 'place-labels', importId: 'basemap' },
  handler: ({ feature }) => {
    if (selectedPlace) {
      map.setFeatureState(selectedPlace, { select: false });
    }
    selectedPlace = feature;
    map.setFeatureState(feature, { select: true });
  }
});

// Omit `target` for a map-wide interaction (e.g. clicking empty space to deselect)
map.addInteraction('map-click', {
  type: 'click',
  handler: () => {
    if (selectedPlace) map.setFeatureState(selectedPlace, { select: false });
    selectedPlace = null;
  }
});

setFeatureState(feature, state) works with any source/layer type, given a stable feature id (promoteId/generateId for GeoJSON/vector sources).

appearances

appearances is a style-spec layer property that defines an array of named, condition-gated property bundles:

{
  "id": "poi-labels",
  "type": "symbol",
  "appearances": [
    {
      "name": "selected",
      "condition": ["feature-state", "select"],
      "properties": {
        "icon-size": 1.3,
        "text-color": "#ff0000",
        "text-halo-color": "#c0caff"
      }
    },
    {
      "name": "highlighted",
      "condition": ["feature-state", "highlighted"],
      "properties": {
        "icon-size": 2,
        "text-color": "#4264fb"
      }
    }
  ]
}

If multiple conditions are true, only the first matching appearance applies. setFeatureState(feature, { select: true }) is what drives the condition here — appearances doesn't replace setFeatureState, it replaces writing the same ["case", ["boolean", ["feature-state", "x"], false], ...] expression into every paint property you want to bundle under one named state.

Constraint: appearances currently only works on symbol layers, and only on properties tagged "Works with appearances" (icon-*, text-*, symbol-z-offset) — it cannot be used on fill, fill-extrusion, circle, or line layers. Known issue: appearances combined with text-variable-anchor on the same layer doesn't work correctly. Available in recent Mapbox GL JS v3.x releases — check the CHANGELOG for the exact version in your SDK.

When to use each

Need Use
Bind a click/hover event to a feature addInteraction (new code, works with custom layers via layerId or Standard Style/style-import featuresets via featuresetId+importId)
Bind a click/hover event, targeting a v2-era or non-featureset setup Legacy map.on(event, layerId, handler) — still works, but has no featureset targeting
Apply the visual change on a symbol layer, several properties at once, under one named condition appearances — cleaner than repeating the condition per property
Apply the visual change on fill, fill-extrusion, circle, or line, or need finer per-property control Raw ["feature-state", ...] expressions written directly into each paint property (see SKILL.md and performance.md)

Either way, setFeatureState is the mechanism that actually flips the state — addInteraction decides when to call it, appearances/raw expressions decide what happens once it's called.

Source: SKILL.md on GitHub

No alerts14d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    This skill provides Mapbox map style patterns and configuration recipes. No security vulnerabilities, malicious code, or suspicious behaviors were detected. All external resource references are standard Mapbox vendor services.

  • Socket14d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer6mo

    1/2 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 9077a82. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 9 hours ago.

Activeupdated 2 weeks ago
  • mapbox
  • cartography
  • style-patterns
  • layer-configuration
  • poi-finder
  • real-estate
  • data-visualization
  • navigation
  • delivery-logistics

README badge

README badge for mapbox/mapbox-agent-skills/mapbox-style-patterns

Provides battle-tested Mapbox style layer configurations and recipes for common mapping scenarios including restaurant finders, real estate, data visualization, navigation, and delivery tracking. Use this when building a new map style or optimizing layer configurations for a specific use case like POI discovery or logistics tracking.

Generated from the current SKILL.md.

Does this skill cover dark mode styles?
Yes. The skill includes a Dark Mode / Night Theme pattern in references/dark-mode.md with near-black backgrounds and reduced brightness suitable for low-light environments.
Can I use these patterns for real estate maps?
Yes. The skill provides a Real Estate pattern in references/real-estate.md that handles property boundaries, price color-coding, and amenity markers.
Does this include delivery/logistics tracking?
Yes. The Delivery/Logistics pattern in references/delivery-logistics.md covers real-time tracking, zones, driver markers, and ETA badges, including pulse animations for customer markers.
How do I optimize performance for dense data?
The skill provides a Simplified by Zoom pattern that filters layers based on zoom level, and references/expressions-clustering.md covers data-driven expressions and clustering for dense POIs.
Are these patterns tested for mobile and desktop?
The skill includes a visual regression checklist covering zoom levels, mobile (375px), desktop (1920px), dense/sparse data, label collision, and color contrast, but you must run these tests yourself.

Generated from the current SKILL.md. These answers refresh after source changes.