rc-leaflet-heat v1.0.0
React HeatMap Component based on rc-leaflet
History Versions
Docs
Features
TypeScriptsupport
Data Structure
Point:interface Point { lat: number lng: number value?: number }Gradient:type Gradient = { [key: string]: string }Extrema:type Extrema = { gradient: Gradient max: number min: number }
Usage
Install
npm install rc-leaflet-heat --saveExample
import React, { Component } from 'react'
import { RCMap, TileLayer } from 'rc-leaflet'
import HeatLayer from 'rc-leaflet-heat'
class App extends Component {
state = {
pointsWithValue: [
{ lat, lng, value }
],
pointsWithoutValue: [
{ lat, lng }
]
}
render () {
const values = this.state.pointsWithValue.map(({ value }) => value)
const max = Math.max(...values)
const half = max / 2
return (
<RCMap>
<TileLayer />
<HeatLayer points={this.state.pointsWithValue} dataMax={/* value between half and max */} />
<HeatLayer points={this.state.pointsWithoutValue} dataMax={1.2} />
</RCMap>
)
}
}Props
points
type: Point
required:
truepoints to render heatmap.
dataMax
type:
numberrequired:
falsevalue to control the appearance of heatmap.
dataMin
type:
numberrequired:
falsevalue to control the appearance of heatmap.
backgroundColor
type:
stringrequired:
falsebackground color of heatmap layer.
gradient
type: Gradient
required:
falsecolor behavior of heatmap point.
radius
type:
numberrequired:
falsedefault:
0.002radius of heatmap point.
opacity
type:
numberrequired:
falseopacity of heatmap point, range from 0 to 1.
maxOpacity
type:
numberrequired:
falsemaxOpacity of heatmap point, range from 0 to 1.
minOpacity
type:
numberrequired:
falseminOpacity of heatmap point, range from 0 to 1.
blur
type:
numberrequired:
falseblur of heatmap point, range from 0 to 1.
scaleRadius
type:
booleanrequired:
falsedefault:
trueautomatic change radius of heatmap point when map is zoomed.
useLocalExtrema
type:
booleanrequired:
falseif set to true, dataMax and dataMin is set by script according to the current view of map.
onExtremaChange
type:
(extrema: Extrema): voidExtremarequired:
falsefired when extrema is probably changed.
6 years ago