@deck.gl-community/leaflet

中文文档
9.4.10发布于 2026/11/02MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3.3万

deck.gl integration with Leaflet

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. API Reference
  4. DeckOverlay
  5. Supported Features and Limitations

@deck.gl-community/leaflet

NPM Version NPM Downloads

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.setProps
  • deckOverlay.pickObject
  • deckOverlay.pickMultipleObjects
  • deckOverlay.pickObjects

Supported Features and Limitations

Supported deck.gl features:

  • Layers
  • Effects
  • Auto-highlighting
  • Attribute transitions
  • onHover and onClick callbacks
  • Tooltip

Not supported features:

  • Tilting
  • Multiple views
  • Controller
  • React integration
  • Gesture event callbacks (e.g. onDrag*)

版本与发布记录

@deck.gl-community/leaflet 共发布 31 个版本,首次发布于 2025/11/17;过去 12 个月发布了 31 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.4.10latest2026/11/029 天前
9.4.92026/10/3111 天前
9.4.9-beta.2beta2026/10/2517 天前
9.4.82026/10/2419 天前
9.4.72026/10/2320 天前
9.4.52026/10/2220 天前

关于 @deck.gl-community/leaflet 的常见问题

@deck.gl-community/leaflet 是什么?

deck.gl integration with Leaflet

如何安装 @deck.gl-community/leaflet?

在项目目录运行 npm install @deck.gl-community/leaflet,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:leaflet(^1.9.4)、@deck.gl/core(~9.4.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@deck.gl-community/leaflet 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@deck.gl-community/leaflet 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deck.gl-community/leaflet 可以商用吗?

@deck.gl-community/leaflet 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@deck.gl-community/leaflet 的下载量有多少?

根据 npm 官方下载统计,@deck.gl-community/leaflet 在 2026/10/12 – 2026/11/10 这 30 天内被下载 33,220 次,日均约 1,107 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deck.gl-community/leaflet 还在维护吗?

最新版本 9.4.10 发布于 2026/11/02(9 天前);至今共发布 31 个版本,其中过去 12 个月发布了 31 个;首次发布于 2025/11/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。