@deck.gl-community/leaflet
This module allows Leaflet to be used as a deck.gl basemap.
More precisely, it provides a Leaflet custom layer that wraps a deck.gl renderer, enabling deck.gl to render layers synchronized with the Leaflet basemap.
Installation
npm install deck.gl @deck.gl-community/leaflet leaflet
Usage
import {DeckOverlay} from '@deck.gl-community/leaflet';
import {MapView} from '@deck.gl/core';
import {GeoJsonLayer, ArcLayer} from '@deck.gl/layers';
import * as L from 'leaflet';
import 'leaflet/dist/leaflet.css';
// source: Natural Earth http://www.naturalearthdata.com/ via geojson.xyz
const AIR_PORTS =
'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_airports.geojson';
// Create map
const map = L.map(document.getElementById('map'), {
center: [51.47, 0.45],
zoom: 4,
});
L.tileLayer('https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/BlueMarble_ShadedRelief_Bathymetry/default/GoogleMapsCompatible_Level8/{z}/{y}/{x}.jpeg', {
maxZoom: 22,
maxNativeZoom: 8,
attribution: 'Imagery courtesy NASA GIBS',
}).addTo(map);
// Add deck.gl overlay
const deckOverlay = new DeckOverlay({
views: [
new MapView({ repeat: true }),
],
layers: [
new GeoJsonLayer({
id: 'airports',
data: AIR_PORTS,
// Styles
filled: true,
pointRadiusMinPixels: 2,
pointRadiusScale: 2000,
getPointRadius: (f) => 11 - f.properties.scalerank,
getFillColor: [200, 0, 80, 180],
// Interactive props
pickable: true,
autoHighlight: true,
onClick: (info) =>
// eslint-disable-next-line
info.object && alert(`${info.object.properties.name} (${info.object.properties.abbrev})`)
}),
new ArcLayer({
id: 'arcs',
data: AIR_PORTS,
dataTransform: (d: any) => d.features.filter((f) => f.properties.scalerank < 4),
// Styles
getSourcePosition: (f) => [-0.4531566, 51.4709959], // London
getTargetPosition: (f) => f.geometry.coordinates,
getSourceColor: [0, 128, 200],
getTargetColor: [200, 0, 80],
getWidth: 1
})
],
getTooltip: (info) => info.object && info.object.properties.name
});
map.addLayer(deckOverlay);
API Reference
DeckOverlay
An implementation of L.Layer.
const deckOverlay = new DeckOverlay({
views: [
new MapView({ repeat: true }),
],
layers: [...],
});
map.addLayer(deckOverlay);
The constructor accepts a props object that is passed to the Deck constructor. See the limitations section below for more details.
The following Deck methods can be called directly from a DeckOverlay instance:
deckOverlay.setPropsdeckOverlay.pickObjectdeckOverlay.pickMultipleObjectsdeckOverlay.pickObjects
Supported Features and Limitations
Supported deck.gl features:
- Layers
- Effects
- Auto-highlighting
- Attribute transitions
onHoverandonClickcallbacks- Tooltip
Not supported features:
- Tilting
- Multiple views
- Controller
- React integration
- Gesture event callbacks (e.g.
onDrag*)