Skip to content

Commit

Permalink
add dtp heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
gcor committed Nov 6, 2023
1 parent 19dac8a commit e24db7f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
5 changes: 3 additions & 2 deletions components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React, { useContext } from 'react';
import MapGl from 'react-map-gl';
import maplibregl from 'maplibre-gl';
import { COORDS_EKATERINBURG } from 'constants/coords';
import { MAX_ZOOM, MIN_ZOOM } from 'constants/map';

import { BuildingSource } from './layers/BuildingSource';
import { OknSource } from './layers/OknSource';
Expand Down Expand Up @@ -39,8 +40,8 @@ export function Map() {
zoom: 15,
pitch: 30,
}}
minZoom={11}
maxZoom={20}
minZoom={MIN_ZOOM}
maxZoom={MAX_ZOOM}
// hash
style={{ width: '100vw', height: '100vh', color: 'black' }}
mapStyle="https://map-backend.netlify.app/style.json"
Expand Down
43 changes: 39 additions & 4 deletions components/Map/layers/DtpSource.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React, { useEffect } from 'react';
import { Source, Layer, useMap } from 'react-map-gl';
import type { CircleLayer } from 'react-map-gl';
import type { CircleLayer, HeatmapLayer } from 'react-map-gl';
import { useSelector } from 'react-redux';
import { activeFilterSelector, activeFilterParamsSelector } from 'state/features/selectors';
import { FilterType } from 'types/Filters.types';
import { SEVERITY_CONFIG } from 'components/Layers/DTP/DTP.constants';
import { MapItemType } from 'types/map-item';
import { getLayerStyle } from 'components/Map/helpers/getFeatureState';
import { MAX_ZOOM, MIN_ZOOM } from 'constants/map';
import dtp from '../../../public/ekb-dtp.json';
import { usePopup } from '../providers/usePopup';
import useMapObjectState from '../providers/useMapObjectState';

const DTP_LAYER_ID = 'dtp-point';
const DTP_LAYER_HEATMAP_ID = 'dtp-point-heatmap';

export function DtpSource() {
const ekbMap = useMap();
Expand Down Expand Up @@ -66,20 +67,54 @@ export function DtpSource() {
type: 'circle',
source: 'ekb-dtp-source',
paint: {
'circle-radius': getLayerStyle<number>({ initial: 8, hover: 10, active: 12 }),
// @ts-ignore
'circle-color': ['case'].concat(...colors).concat(['rgba(0, 0, 0, 0)']),
// @ts-ignore
'circle-stroke-width': 1,
// @ts-ignore
'circle-stroke-color': ['case'].concat(...strokeColors).concat(['rgba(0, 0, 0, 0)']),
'circle-radius': ['interpolate', ['linear'], ['zoom'], MIN_ZOOM, 1, MAX_ZOOM, 12],
},
};

const heatmapStyle: HeatmapLayer = {
id: DTP_LAYER_HEATMAP_ID,
source: 'ekb-dtp-source',
type: 'heatmap',
paint: {
'heatmap-weight': {
type: 'exponential',
property: 'weight',
stops: [
[0, 0],
[1, 1],
],
},
'heatmap-intensity': 1,
'heatmap-color': [
'interpolate',
['linear'],
['heatmap-density'],
0,
'rgba(0, 0, 255, 0)',
0.2,
'rgb(0, 255, 0)',
0.4,
'rgb(255, 255, 0)',
0.6,
'rgb(255, 0, 0)',
1,
'rgb(255, 0, 0)',
],
'heatmap-radius': ['interpolate', ['linear'], ['zoom'], MIN_ZOOM, 2, MAX_ZOOM, 30],
'heatmap-opacity': ['interpolate', ['linear'], ['zoom'], MIN_ZOOM, 1, MAX_ZOOM, 0],
},
};

return (
<>
<Source generateId id="ekb-dtp-source" type="geojson" data={data}>
<Layer {...layerStyle} />
<Layer {...heatmapStyle} />
</Source>
</>
);
Expand Down
2 changes: 2 additions & 0 deletions constants/map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const MIN_ZOOM = 11;
export const MAX_ZOOM = 20;

1 comment on commit e24db7f

@ekbdev
Copy link

@ekbdev ekbdev commented on e24db7f Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for map ready!

✅ Preview
https://map-5elgbhgpk-ekbdev.vercel.app
https://ekbdev-map-heatmap-dtp.vercel.app

Built with commit e24db7f.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.