BSD 2-Clause "Simplified" License

项目介绍

Leaflet/Leaflet.heat 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 BSD 2-Clause "Simplified" License 许可证,目前获得 1.7k 个 Star、497 次 Fork。

仓库全名
Leaflet/Leaflet.heat
开源许可证
BSD 2-Clause "Simplified" License
Star 数
1.7k
Fork 数
497
未关闭 Issue
41

README 摘要

Leaflet.heat A tiny, simple and fast Leaflet heatmap plugin. Uses simpleheat under the hood, additionally clustering points into a grid for performance. Works with Leaflet 1.9 and 2.0. Demos 10,000 points → Adding points dynamically → Leaflet 1.9 as an ES module → Leaflet 1.9 with plain scripts → Usage Install with npm install leaflet.heat. TypeScript types are included (for Leaflet 2.0). From a…

完整内容见 GitHub 原始 README 或本页 。

常见问题

Leaflet.heat 用什么语言开发?

主要使用 JavaScript 编写,采用 BSD 2-Clause "Simplified" License 许可证,目前有 1.7k 个 Star。

Leaflet.heat 可以免费商用吗?

仓库采用 BSD 2-Clause "Simplified" License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 Leaflet.heat 的源码?

可以直接克隆仓库:git clone https://github.com/Leaflet/Leaflet.heat.git,默认分支为 main;安装与运行步骤见仓库 README。

Leaflet.heat 最近还在维护吗?

仓库最近一次更新为 4 天前,当前有 41 个未关闭 Issue;Star 数为 1.7k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

A tiny, simple and fast heatmap plugin for Leaflet.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
2716
价值分
1150
活跃状态
活跃
暂无主题

语言占比

JavaScript
TypeScript

Release

README

Leaflet.heat

A tiny, simple and fast Leaflet heatmap plugin. Uses simpleheat under the hood, additionally clustering points into a grid for performance. Works with Leaflet 1.9 and 2.0.

Build Status

Demos

Usage

import {HeatLayer} from 'leaflet.heat';

const heat = new HeatLayer([
    [50.5, 30.5, 0.2], // lat, lng, intensity
    [50.6, 30.4, 0.5],
    ...
], {radius: 25}).addTo(map);

Install with npm install leaflet.heat. TypeScript types are included (for Leaflet 2.0).

From a CDN

With Leaflet 2.0, map leaflet in an import map and import the plugin’s ES module build, which includes simpleheat:

<script type="importmap">
    {"imports": {"leaflet": "https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"}}
</script>
<script type="module">
    import {LeafletMap, TileLayer} from 'leaflet';
    import {HeatLayer} from 'https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-heat.js';
</script>

Leaflet 1.9 has no ES module package entry, so map leaflet to its ESM build explicitly:

{"imports": {"leaflet": "https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-src.esm.js"}}

As a plain script

leaflet-heat-global.js reads Leaflet from the global L and adds L.HeatLayer to it. Load it after Leaflet 1.9’s leaflet.js:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet-heat-global.js"></script>
<script>
    const heat = L.heatLayer(points, {radius: 25}).addTo(map);
</script>

Or after Leaflet 2.0’s leaflet-global.js, which has no factory functions, so use new L.HeatLayer(points) there. The L.heatLayer factory is only added on Leaflet 1.x.

Reference

new HeatLayer(latlngs, options?)

Creates a heatmap layer from an array of points. Each point can be an array like [50.5, 30.5, 0.5] (the third element being the intensity), a {lat, lng, alt} object, or a LatLng, with the intensity in alt. Intensity is 1 if not set.

Options:

  • radius: radius of each point, 25 by default.
  • blur: amount of blur, 15 by default.
  • minOpacity: the minimum opacity the heat will start at, 0.05 by default.
  • max: intensity that maps to the end of the gradient, 1 by default.
  • maxZoom: zoom level where points reach full intensity, the map’s maxZoom by default.
  • gradient: color gradient config, e.g. {0.4: 'blue', 0.65: 'lime', 1: 'red'}.
  • pane: map pane where the heat will be drawn, 'overlayPane' by default.

Points close to each other are merged into grid cells of (radius + blur) / 2 pixels, and their intensities are summed. Below maxZoom, each point’s intensity is halved per zoom level. So at lower zooms, max is compared against the total of all points in a cell, not against single points.

Methods
  • setLatLngs(latlngs): replaces the heatmap data and redraws it.
  • addLatLng(latlng): adds a point and redraws the heatmap.
  • setOptions(options): sets new options and redraws the heatmap.
  • redraw(): redraws the heatmap on the next animation frame. Several calls before that frame make a single redraw. Call it after changing points in the array in place; points added to its end are picked up on any redraw.
  • getBounds(): returns the LatLngBounds of all points.

Compatibility

Leaflet.heat supports Leaflet 1.9 and 2.0 from the same code, using only public Leaflet APIs.

Upgrading from 0.2

  • The package is an ES module and exports the HeatLayer class. It no longer sets globals; use dist/leaflet-heat-global.js for that.
  • dist/leaflet-heat.js is now the ES module build. The plain script is dist/leaflet-heat-global.js.
  • L.heatLayer(...) only exists in the plain script build on Leaflet 1.x. Use new HeatLayer(...) elsewhere.
  • Leaflet 1.9 or later is required.

Changelog

See CHANGELOG.md.

评论

暂无评论