maps
Use when building interactive map tools - Explains MapLibre setup, tiles, and common UI patterns.
When & Why to Use This Skill
This Claude skill streamlines the development of interactive web maps using MapLibre GL. It provides standardized implementation patterns for map initialization, tile server configuration using OpenFreeMap, and robust UI components. By offering pre-defined logic for geolocation, error handling, and responsive layouts, it ensures developers can build high-performance, accessible mapping tools with minimal boilerplate.
Use Cases
- Rapidly bootstrapping a MapLibre GL project with optimized script loading and OpenFreeMap Liberty styles.
- Implementing a user-centric geolocation feature with real-time markers, smooth camera transitions, and comprehensive error messaging.
- Designing full-viewport map interfaces that incorporate accessible navigation controls and unobtrusive UI overlays for status updates.
- Ensuring cross-browser compatibility and graceful degradation by implementing safety checks for global map objects.
| name | maps |
|---|---|
| description | "Use when building interactive map tools - Explains MapLibre setup, tiles, and common UI patterns." |
MapLibre basics
- Include MapLibre's CSS before your styles and load the script from https://unpkg.com/maplibre-gl@3.6.2/dist/maplibre-gl.js.
- Keep the map container absolutely positioned to fill the viewport (see
#mapstyles intools/map-explorer/index.html). - Use the OpenFreeMap Liberty style (
https://tiles.openfreemap.org/styles/liberty) unless a different basemap is required. - Add navigation controls with
map.addControl(new maplibregl.NavigationControl(), 'top-right');. - Guard against missing globals: if
typeof maplibregl === 'undefined', disable map-dependent UI and show an error.
Geolocation pattern
- Provide a dedicated button for
navigator.geolocation.getCurrentPosition. - Disable the button while locating, apply a loading state, and reset it in success/error callbacks.
- On success, create or update a
maplibregl.Markerandmap.easeTothe new center. - On errors, surface user-friendly messages for permission, availability, and timeout cases.
Overlay & interaction tips
- Keep status text in small, unobtrusive elements and update it via helper functions.
Accessibility & layout
- Generally prefer maps that take up the whole viewport, with UI controls and panels overlayed
- Footer links in an overlay too.