MapLibre GL JS Examples
28A WebGL-powered vector mapping library with 3D terrain and data-driven styling. All examples use MapTiler Cloud tiles.
Map display & interaction
3D Building Extrusions with MapLibre GL JS Extrude MapTiler building footprints in MapLibre GL JS with a fill-extrusion layer whose fill-extrusion-height reads each feature's render_height.
3D Terrain with MapLibre GL JS Render 3D terrain in MapLibre GL JS from a MapTiler raster-dem source with map.setTerrain() and an exaggeration factor, plus fog via setSky().
Satellite Basemap with MapLibre GL JS Show MapTiler satellite imagery as the basemap of a MapLibre GL JS map by loading the satellite style into maplibregl.Map, tilted with pitch.
Control Map Interactions in MapLibre GL JS Stop an embedded MapLibre GL JS map from hijacking page scroll by setting cooperativeGestures in the maplibregl.Map constructor options.
Globe Projection with MapLibre GL JS Turn a MapLibre GL JS map into a 3D globe by calling map.setProjection() with type globe after style.load, shown on the MapTiler satellite style.
Initialize a MapLibre GL JS Map Initialize a MapLibre GL JS map with maplibregl.Map and the MapTiler streets-v4 style, then add a NavigationControl and a Marker with a Popup.
Switch Vector Styles in MapLibre GL JS Switch MapTiler styles at runtime in MapLibre GL JS by calling map.setStyle() with a new style URL such as streets-v4, outdoor-v4, or dataviz-dark.
Static Map Image with MapLibre GL JS Embed a PNG from the MapTiler Static Maps API, built from center, zoom, and size in the URL, above an interactive MapLibre GL JS map of the same view.
Markers, annotations & overlays
Custom Marker Icons with MapLibre GL JS Replace the default MapLibre GL JS pin by passing a custom SVG or HTML element to maplibregl.Marker through its element option, with a Popup.
Data-Driven Choropleth with MapLibre GL JS Color GeoJSON polygons by value in MapLibre GL JS with a fill layer whose fill-color uses an interpolate expression over a data property.
Line Layers with MapLibre GL JS Plot a route in MapLibre GL JS by adding a GeoJSON LineString source and a line layer styled with line-color, line-width, and round line-join.
Fill Layers with MapLibre GL JS Shade an area in MapLibre GL JS by adding a GeoJSON Polygon source and rendering it with a fill layer plus a line layer for the outline.
Add Markers and Popups in MapLibre GL JS Add maplibregl.Marker instances to a MapLibre GL JS map with setLngLat() and attach a clickable maplibregl.Popup to each with setPopup().
Point Clustering with MapLibre GL JS Cluster points in MapLibre GL JS with the GeoJSON source cluster option, step expressions for circle size and getClusterExpansionZoom() on click.
Style Expressions with MapLibre GL JS Style circle and symbol layers in MapLibre GL JS with interpolate and get expressions that scale circle-radius and circle-color by population.
Geocoding & search
Address Search with MapLibre GL JS Geocode a place name with the MapTiler Geocoding API via fetch(), then drop a maplibregl.Marker and flyTo() the chosen result in MapLibre GL JS.
Reverse Geocoding with MapLibre GL JS Turn a map click into an address in MapLibre GL JS by sending its lng,lat to the MapTiler Geocoding API and showing the result in a maplibregl.Popup.
Routing & navigation
Location & real-time
Geofencing with MapLibre GL JS Test whether a clicked point lies inside a geofence in MapLibre GL JS with a pointInPolygon() check against a polygon drawn as a fill layer.
Geolocation Control in MapLibre GL JS Track the user's position in MapLibre GL JS with maplibregl.GeolocateControl, setting trackUserLocation and calling trigger() on load.
Fuzzy Location Circle with MapLibre GL JS Blur an exact location in MapLibre GL JS by building a circle polygon from Math.cos() and Math.sin() offsets and showing it as a fill layer.
Live GPS Tracking with MapLibre GL JS Move a tracked point in MapLibre GL JS by updating a GeoJSON source with setData() on a setInterval timer, drawing a trail and following with panTo().
Analytics & advanced
Animated Data with MapLibre GL JS Animate a pulsing ring in MapLibre GL JS by updating circle-radius and circle-stroke-opacity with setPaintProperty() inside requestAnimationFrame.
Draw Polygons with MapLibre GL JS Collect polygon vertices from map clicks in MapLibre GL JS and redraw a GeoJSON source with setData() into fill, line, and circle layers.
Export Map as PNG with MapLibre GL JS Export a MapLibre GL JS map as a PNG by enabling preserveDrawingBuffer and passing map.getCanvas().toDataURL() to a download link.
Heatmap Layer with MapLibre GL JS Render point density in MapLibre GL JS with a native heatmap layer, weighting points by heatmap-weight and coloring them by heatmap-density.
Load GeoJSON Source in MapLibre GL JS Load a remote GeoJSON file in MapLibre GL JS with fetch(), add it via map.addSource() and style it as fill and line layers with a click Popup.
Store Locator with MapLibre GL JS Link a sidebar store list to maplibregl.Marker popups in MapLibre GL JS, calling flyTo() and togglePopup() when a store is clicked.
Build maps using MapLibre GL JS with AI
Install the MapLibre GL JS skill in your IDE and let AI write the code for you.
All examples use MapTiler maps and require a free API key.