The is the first pillar of interactivity. Unlike traditional maps that only pan and zoom, MapLibre offers a full 6-degrees-of-freedom camera model (pan, zoom, rotate, pitch). Methods like map.flyTo() provide smooth, cinematic transitions between locations—perfect for storytelling or guided tours.
The style is composed of layers, processed in a specific order (bottom to top: background, then polygon, then line, then symbol). Each layer has a (where the vector data comes from) and a set of paint and layout properties.
Introduction In the modern digital landscape, maps have transcended their paper-based origins to become dynamic, interactive interfaces for understanding our world. From real-time logistics and urban planning to location-based gaming and data journalism, web-based mapping is the silent engine of countless applications. For years, developers had two primary choices: the proprietary, powerful but restrictive Google Maps API, or the open-source, flexible but initially less performant Leaflet.js. However, a revolution began with the introduction of WebGL for cartography, spearheaded by Mapbox GL JS. When Mapbox shifted its core rendering engine to a proprietary license in late 2020, the open-source community did not let it die. Instead, they forked the final open-source version, giving birth to MapLibre GL JS .
import maplibregl from 'maplibre-gl'; const map = new maplibregl.Map({ container: 'map', // HTML element ID style: 'https://tiles.stadiamaps.com/styles/alps.json', // A style URL center: [2.3488, 48.8534], // Paris (longitude, latitude) zoom: 12, pitch: 45, // 3D tilt bearing: -30 // Rotation });
The third, and most powerful, pillar is . Using map.queryRenderedFeatures() , you can click anywhere on the map and instantly retrieve all the vector data underlying that pixel. This enables the classic "hover to highlight" or "click for info" functionality without needing a separate backend database lookup.
For example:
This simple constructor belies the complex WebGL pipeline it initiates. The API abstracts away shader compilation, tile fetching, and camera matrix math, providing a clean interface for complex 3D cartography. If the engine is WebGL, the soul of MapLibre GL JS is its Style Specification – a JSON document that dictates absolutely everything about the map’s appearance. This specification is declarative, powerful, and deeply extensible.






