Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add heatmap layer #598

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/layers/Heat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Layer from './Layer'
import { heatLayer } from '../utils/layers'

class Heat extends Layer {
constructor(options) {
super(options)

this.createSource()
this.createLayers()
}

createLayers() {
const id = this.getId()
const isInteractive = false

this.addLayer(heatLayer({ id }), { isInteractive })
}
}

export default Heat
4 changes: 3 additions & 1 deletion src/layers/layerTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Choropleth from './Choropleth'
import Boundary from './Boundary'
import Markers from './Markers'
import Events from './Events'
import Heat from './Heat'
import ClientCluster from './ClientCluster'
import DonutCluster from './DonutCluster'
import ServerCluster from './ServerCluster'
Expand All @@ -13,13 +14,14 @@ import GeoJson from './GeoJson'
import LayerGroup from './LayerGroup'

export default {
vectorStyle: VectorStyle, //basemap /externalLayer
vectorStyle: VectorStyle, // basemap / externalLayer
tileLayer: TileLayer, // basemap / external layer
wmsLayer: TileLayer, // external layer
choropleth: Choropleth, // thematic layer
boundary: Boundary, // boundary layer
markers: Markers, // facility layer
events: Events, // event layer
heat: Heat, // event layer
clientCluster: ClientCluster, // event layer
donutCluster: DonutCluster, // event layer
serverCluster: ServerCluster, // event layer
Expand Down
38 changes: 38 additions & 0 deletions src/utils/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,41 @@ export const clusterCountLayer = ({ id, color, opacity }) => ({
'text-opacity': opacity ?? defaults.opacity,
},
})

// Layer with heat surface
export const heatLayer = ({ id, source }) => ({
id: `${id}-heat`,
type: 'heatmap',
source: source || id,
paint: {
// Increase the heatmap weight based on frequency and property magnitude
'heatmap-weight': 1,
// Increase the heatmap color weight weight by zoom level
// heatmap-intensity is a multiplier on top of heatmap-weight
'heatmap-intensity': 1,
// Color ramp for heatmap. Domain is 0 (low) to 1 (high).
// Begin color ramp at 0-stop with a 0-transparency color
// to create a blur-like effect.
'heatmap-color': [
'interpolate',
['linear'],
['heatmap-density'],
0,
'rgba(33,102,172,0)',
0.2,
'rgb(103,169,207)',
0.4,
'rgb(209,229,240)',
0.6,
'rgb(253,219,199)',
0.8,
'rgb(239,138,98)',
1,
'rgb(178,24,43)',
],
// Adjust the heatmap radius by zoom level
'heatmap-radius': 30,
// Transition from heatmap to circle layer by zoom level
'heatmap-opacity': 1,
},
})
Loading