Skip to content

Commit

Permalink
add population layer
Browse files Browse the repository at this point in the history
  • Loading branch information
gcor committed Sep 26, 2023
1 parent 2ac4a2e commit 82b9e69
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/Layers/Filters.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ export const FILTERS_CONFIG: FilterConfig = {
component: <LinesFilter />,
isVerified: true,
},
[FilterType.Population]: {
title: 'Население',
component: null,
isVerified: true,
},
};
4 changes: 4 additions & 0 deletions components/Layers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ export const MODEL_CONFIG = {
cardContent: LinesCardContent,
requests: { oneItemRequest: lines.getObject },
},
[MapItemType.Population]: {
cardContent: LinesCardContent,
requests: { oneItemRequest: lines.getObject },
},
} as const;
2 changes: 2 additions & 0 deletions components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { OknSource } from './layers/OknSource';
import { DtpSource } from './layers/DtpSource';
import { LinesSource } from './layers/LinesSource';
import { DesignCodeSource } from './layers/DesignCodeSource';
import { PopulationSource } from './layers/PopulationSource';
import { MapContext } from './providers/MapProvider';

import 'maplibre-gl/dist/maplibre-gl.css';
Expand All @@ -23,6 +24,7 @@ function MapLayers() {
<DtpSource />
<LinesSource />
<DesignCodeSource />
<PopulationSource />
</>
);
}
Expand Down
50 changes: 50 additions & 0 deletions components/Map/layers/PopulationSource.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Source, Layer } from 'react-map-gl';
import { useSelector } from 'react-redux';
import React from 'react';
import type { FillLayer } from 'react-map-gl';
import { activeFilterSelector } from 'state/features/selectors';
import { FilterType } from 'types/Filters.types';
import useMapObjectState from '../providers/useMapObjectState';

const layerId = 'ekb-population-layer';
const sourceId = 'ekb-population-source';

export function PopulationSource() {
const activeFilter = useSelector(activeFilterSelector);

useMapObjectState(layerId);

if (activeFilter !== FilterType.Population) {
return null;
}

const layerStyle: FillLayer = {
id: layerId,
type: 'fill',
source: sourceId,
paint: {
// @ts-ignore
'fill-color': [
'interpolate',
['linear'],
['get', 'population'],
0,
'green',
8000,
'red',
],
'fill-opacity': 0.5,
},
};

return (
<Source
id={sourceId}
data="https://map-backend.netlify.app/kontur-population.json"
type="geojson"
generateId
>
<Layer {...layerStyle} />
</Source>
);
}
1 change: 1 addition & 0 deletions types/Filters.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum FilterType {
DesignCode = 'designCode',
DTP = 'dtp',
Line = 'line',
Population = 'population',
}

export interface FilterConfigItem {
Expand Down
1 change: 1 addition & 0 deletions types/map-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export enum MapItemType {
PinkLines = 'pinkLines',
BlueLines = 'blueLines',
OKN = 'okn',
Population = 'population',
}

1 comment on commit 82b9e69

@ekbdev
Copy link

@ekbdev ekbdev commented on 82b9e69 Sep 26, 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-191kylezo-ekbdev.vercel.app
https://ekbdev-map-population.vercel.app

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

Please sign in to comment.