mcpField
R
react-map-gl

react-map-gl

github.com/fixmyberlinDevelopment082 installsUpdated 5d ago
Repository

About react-map-gl

A repository-specific skill for building and reviewing MapLibre maps with `react-map-gl/maplibre` in FixMyBerlin / FMC projects. It documents conventions for React-based layers, events, map state, and testing-oriented inspection.

Key features

  1. 01Declarative source and layer patterns
  2. 02Map event and access conventions
  3. 03Loaded-state guards and debug exposure
  4. 04Feature selection and highlighting rules
  5. 05URL and viewport synchronization

Use cases

  1. 01Reviewing map source and layer changes
  2. 02Implementing feature click and hover handling
  3. 03Synchronizing map view with URL state
  4. 04Inspecting maps in agent or E2E tests

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/fixmyberlin/fixmyskills --skill react-map-gl

After installing, type/react-map-glin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

references/
cursor-handling.md
declarative-source-layer.md
feature-state.md
flat-source-layer.md
initial-view-state.md
interactive-layer-ids.md
layer-visibility-vs-unmount.md
map-debug-exposure.md
map-event-handlers.md
map-images.md
map-loaded-hook.md
map-props-attribution-locale.md
map-provider-wrapper.md
map-url-state.md

Details

From the project README

react-map-gl (MapLibre)

Conventions for react-map-gl/maplibre in FixMyBerlin / FMC projects. Import from react-map-gl/maplibre (not react-map-gl alone). Always import maplibre-gl/dist/maplibre-gl.css.

import 'maplibre-gl/dist/maplibre-gl.css'
import { MapProvider, Map, Source, Layer, useMap } from 'react-map-gl/maplibre'

Rules

TopicRule
Sources / layers<Source> + <Layer> in JSX only. Never map.addSource / map.addLayer (or remove*) for app data. Show/hide via layout.visibility or conditional render.
Layer structureFlat siblings: one <Source> per source id, then <Layer> siblings (not nested).
Map eventsCamera, pointer, load, tile lifecycle go on <Map> callback props. Not useEffect + map.on(…). useEffect only for React → map sync after load, or events without a Map prop (styleimagemissing).
Map accessWrap app map UI in <MapProvider>. useMap() keyed by <Map id="…">. Never pass ref to <Map> for child access.
Map readyGuard getStyle, queryRenderedFeatures, setFeatureState with useMapLoaded() (set in onLoad).
Debug exposureIn onLoad, call exposeMainMapForDebugging(event.target) (dev + Playwright only). Agents/tests read window.__mainMap.
ClicksLayer ids in interactiveLayerIds; read event.features. No queryRenderedFeatures for primary click picking unless syncing URL features.
Feature highlightInspector/form truth in React; map tint via setFeatureState (paint) or React filter layer. Clear old state before applying new.
AttributionattributionControl={false} on <Map>, <AttributionControl compact> as child. RTLTextPlugin={false} on every <Map>.
Viewport URLzoom/lat/lng with zoom-aware rounding; write on onMoveEnd with history: 'replace'.
View stateUncontrolled initialViewState seeded from URL; no mirrored viewState in React unless programmatic camera is needed.

Which file to read

Read only the file for your task.

TaskRead
Add or review <Source> / <Layer>, remove addSourcedeclarative-source-layer.md, flat-source-layer.md
Show/hide layerslayer-visibility-vs-unmount.md
Click/hover handler, choose a <Map> callbackmap-event-handlers.md, interactive-layer-ids.md
Cursor over featurescursor-handling.md
Child/sibling needs the map instancemap-provider-wrapper.md
getStyle / queryRenderedFeatures before loadmap-loaded-hook.md
Agent/E2E map inspectionmap-debug-exposure.md
Selected/hovered feature highlight, setFeatureStatefeature-state.md
Initial camera, fitBounds, boundsinitial-view-state.md
?map= URL syncmap-url-state.md
Attribution, locale, RTL text pluginmap-props-attribution-locale.md
Missing or dynamic icons, styleimagemissing, addImagemap-images.md

All files are in references/. Pair with skills tanstack-router-conventions (?map= contract), zustand-state-management (useMapLoaded store), playwright-skill (E2E map helpers).

Review checklist

  • No addSource / addLayer / removeSource / removeLayer / setLayoutProperty for app data; flat <Source> + <Layer>
  • <MapProvider> parent, useMap(), no ref on <Map>
  • No useEffect + map.on for move/click/hover; viewport sync on onMoveEnd / onMove
  • Effects touching the map are React → map sync guarded by mainMap + mapLoaded
  • onLoad sets map-ready flag and calls exposeMainMapForDebugging
  • Every pickable layer id is in interactiveLayerIds; handlers use event.features
  • Old feature state cleared before new applied; features have ids (promoteId for vector)
  • attributionControl={false} + child <AttributionControl>; RTLTextPlugin={false}
  • URL: shared parseMapParam / serializeMapParam, replace on pan/zoom, no encodeURIComponent around the serialized value
  • Fixed icons via useMapImages; dynamic icons via styleimagemissing in useEffect with off() cleanup and hasImage guard

Comments

Markdown supported