Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Heatmap
# Deck.gl Heatmap

This uses the `useMapsLibrary` hook showing earthquake magnitude data in a
heatmap.
This uses deck.gl's `HeatmapLayer` and `GoogleMapsOverlay` to show earthquake
magnitude data in a heatmap.

## Google Maps Platform API key

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no" />
<title>Heatmap</title>
<title>deck.gl Heatmap</title>

<style>
body {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"type": "module",
"dependencies": {
"@deck.gl/aggregation-layers": "9.3.3",
"@deck.gl/google-maps": "9.3.3",
"@types/geojson": "^7946.0.14",
"@vis.gl/react-google-maps": "latest",
"deck.gl": "9.3.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vite": "^8.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {createRoot} from 'react-dom/client';
import {APIProvider, Map} from '@vis.gl/react-google-maps';

import ControlPanel from './control-panel';
import Heatmap from './heatmap';
import DeckGlHeatmap from './deckgl-heatmap';
import {EarthquakesGeojson, loadEarthquakeGeojson} from './earthquakes';

const API_KEY =
Expand All @@ -28,16 +28,15 @@ const App = () => {
defaultCenter={{lat: 40.7749, lng: -130.4194}}
defaultZoom={3}
gestureHandling={'greedy'}
disableDefaultUI={true}
/>

{earthquakesGeojson && (
<Heatmap
geojson={earthquakesGeojson}
radius={radius}
opacity={opacity}
/>
)}
disableDefaultUI={true}>
{earthquakesGeojson && (
<DeckGlHeatmap
geojson={earthquakesGeojson}
radius={radius}
opacity={opacity}
/>
)}
</Map>

<ControlPanel
radius={radius}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ function ControlPanel({
}: Props) {
return (
<div className="control-panel">
<h3>Heatmap</h3>
<h3>deck.gl Heatmap</h3>
<p>
This uses the <code>useMapsLibrary()</code> hook and the{' '}
<code>google.maps.visualization</code> library to show earthquake
magnitude data in a heatmap.
This uses deck.gl&apos;s <code>HeatmapLayer</code> with a{' '}
<code>GoogleMapsOverlay</code> to show earthquake magnitude data on top
of the map.
</p>

{/* Circle Controls */}
Expand Down Expand Up @@ -60,13 +60,13 @@ function ControlPanel({

<div className="links">
<a
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/heatmap"
href="https://codesandbox.io/s/github/visgl/react-google-maps/tree/main/examples/deckgl-heatmap"
target="_new">
Try on CodeSandbox ↗
</a>

<a
href="https://github.com/visgl/react-google-maps/tree/main/examples/heatmap"
href="https://github.com/visgl/react-google-maps/tree/main/examples/deckgl-heatmap"
target="_new">
View Code ↗
</a>
Expand Down
35 changes: 35 additions & 0 deletions examples/deckgl-heatmap/src/deckgl-heatmap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, {useMemo} from 'react';

import {HeatmapLayer} from '@deck.gl/aggregation-layers';

import {DeckGlOverlay} from './deckgl-overlay';
import {EarthquakesGeojson} from './earthquakes';

type HeatmapProps = {
geojson: EarthquakesGeojson;
radius: number;
opacity: number;
};

type EarthquakeFeature = EarthquakesGeojson['features'][number];

const DeckGlHeatmap = ({geojson, radius, opacity}: HeatmapProps) => {
const layers = useMemo(
() => [
new HeatmapLayer({
id: 'earthquake-heatmap',
data: geojson.features,
radiusPixels: radius,
opacity,
getPosition: (feature: EarthquakeFeature) =>
feature.geometry.coordinates,
getWeight: (feature: EarthquakeFeature) => feature.properties?.mag ?? 0
})
],
[geojson, opacity, radius]
);

return <DeckGlOverlay layers={layers} />;
};

export default DeckGlHeatmap;
25 changes: 25 additions & 0 deletions examples/deckgl-heatmap/src/deckgl-overlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {useMap} from '@vis.gl/react-google-maps';
import {useEffect, useMemo} from 'react';

import {GoogleMapsOverlay} from '@deck.gl/google-maps';

import type {LayersList} from '@deck.gl/core';

export type DeckGlOverlayProps = {layers?: LayersList};

export const DeckGlOverlay = ({layers}: DeckGlOverlayProps) => {
const deck = useMemo(() => new GoogleMapsOverlay({interleaved: true}), []);

const map = useMap();
useEffect(() => {
deck.setMap(map);

return () => deck.setMap(null);
}, [deck, map]);

useEffect(() => {
deck.setProps({layers});
}, [deck, layers]);

return null;
};
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/deckgl-overlay/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"type": "module",
"dependencies": {
"@deck.gl/google-maps": "^9.1.0",
"@deck.gl/google-maps": "9.3.3",
"@types/geojson": "^7946.0.14",
"@vis.gl/react-google-maps": "latest",
"deck.gl": "^9.1.0",
"deck.gl": "9.3.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"vite": "^8.0.0"
Expand Down
51 changes: 0 additions & 51 deletions examples/heatmap/src/heatmap.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion website/src/examples-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const sidebars = {
'marker-clustering',
'custom-marker-clustering',
'geometry',
'heatmap',
'drawing',
'terra-draw',
'autocomplete',
'directions',
'routes-api',
'deckgl-overlay',
'deckgl-heatmap',
'map-3d',
'map-3d-markers',
'extended-component-library',
Expand Down
5 changes: 5 additions & 0 deletions website/src/examples/deckgl-heatmap.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Deck.gl Heatmap

import App from 'website-examples/deckgl-heatmap/src/app';

<App />
5 changes: 0 additions & 5 deletions website/src/examples/heatmap.mdx

This file was deleted.

Binary file added website/static/images/examples/deckgl-heatmap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.