Leaflet Examples
22A lightweight, mobile-friendly 2D mapping library with a large plugin ecosystem. All examples use MapTiler Cloud tiles.
Map display & interaction
Satellite Basemap with Leaflet Show MapTiler satellite imagery on a Leaflet map with L.tileLayer() and switch to a labeled hybrid layer through L.control.layers().
Control Map Gestures in Leaflet Turn Leaflet map gestures on or off with L.map() options like scrollWheelZoom and dragging, and re-enable a handler later with enable().
Initialize a Leaflet Map with MapTiler Tiles Create a Leaflet map with L.map() and setView(), load MapTiler raster tiles through L.tileLayer(), and place a marker with a popup.
Switch Tile Layers in Leaflet Switch between MapTiler raster styles at runtime by registering several L.tileLayer() basemaps in a Leaflet L.control.layers() switcher.
Static Map Image with Leaflet Request a PNG from the MapTiler Static Maps API for thumbnails and emails, and show it above an interactive Leaflet map for comparison.
Markers, annotations & overlays
Custom Marker Icons with Leaflet Replace the default Leaflet marker pin with a custom image via L.icon() or an HTML and CSS icon via L.divIcon(), passed to L.marker().
Choropleth Map with Leaflet Color regions on a Leaflet map by data value with L.geoJSON() and a style function, and attach a popup to each region via onEachFeature.
Draw Polylines on a Leaflet Map Connect a series of coordinates with L.polyline() on a Leaflet map and style the route or path with color, weight, and opacity options.
Draw Polygons on a Leaflet Map Outline areas on a Leaflet map with L.polygon(), set custom stroke and fill styles, and attach a popup to each shape with bindPopup().
Add Markers and Popups to a Leaflet Map Place a marker on a Leaflet map with L.marker() and attach an HTML popup to it with bindPopup(), opened when the user clicks the pin.
Marker Clustering with Leaflet Cluster nearby markers on a Leaflet map with L.markerClusterGroup() from the Leaflet.markercluster plugin to keep large datasets readable.
Geocoding & search
Address Search with Leaflet Geocode addresses as the user types with the MapTiler Geocoding API, then move a Leaflet map to the chosen result with setView() and L.marker().
Reverse Geocoding with Leaflet Reverse geocode a clicked point on a Leaflet map with map.on('click') and the MapTiler Geocoding API, then show the address in a popup.
Routing & navigation
Location & real-time
Geofencing with Leaflet Check whether a clicked point falls inside a Leaflet L.polygon() geofence with a point-in-polygon test and report the result in an L.popup().
Show User Location on a Leaflet Map Locate the user on a Leaflet map with map.locate(), then mark the position with L.marker() and an L.circle() sized to the GPS accuracy.
Fuzzy Location with Leaflet Hide an exact location on a Leaflet map by drawing an L.circle() around a randomly offset point instead of placing a precise marker.
Analytics & advanced
Drawing Tools with Leaflet Draw, edit, and delete shapes on a Leaflet map with the Leaflet.draw plugin, using L.Control.Draw and an L.FeatureGroup to store them.
Export Leaflet Map as PNG Export the current Leaflet map view as a PNG by rendering the map container with html2canvas() and saving it with canvas.toDataURL().
Heatmap Visualization with Leaflet Render point density as a heatmap on a Leaflet map with L.heatLayer() from the Leaflet.heat plugin, tuned with radius and blur options.
Load GeoJSON Data in Leaflet Render GeoJSON features on a Leaflet map with L.geoJSON(), styling points as L.circleMarker() via pointToLayer and binding popups per feature.
Store Locator with Leaflet Build a Leaflet store locator that links a sidebar list to L.marker() pins, so clicking a store pans with setView() and opens its popup.
Build maps using Leaflet with AI
Install the Leaflet skill in your IDE and let AI write the code for you.
All examples use MapTiler maps and require a free API key.