Skip to content

Commit

Permalink
Merge pull request #115 from UNopenGIS/add-kontur-population
Browse files Browse the repository at this point in the history
Add KonturPopulationMap
  • Loading branch information
yuiseki authored Aug 17, 2024
2 parents 4523551 + 3d1d69f commit 97e8b09
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"hillshade",
"hinanbasho",
"ISCGM",
"Kontur",
"kpop",
"landuse",
"Maxar",
"NASADEM",
Expand Down
14 changes: 14 additions & 0 deletions src/components/Datasets/KonturPopulation/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, StoryObj } from '@storybook/react';
import { KonturPopulationMap as MapComponent } from '.';

const meta: Meta<typeof MapComponent> = {
component: MapComponent,
parameters: {
layout: 'fullscreen',
},
} satisfies Meta<typeof MapComponent>;

export default meta;
type Story = StoryObj<typeof MapComponent>;

export const Preview: Story = {};
38 changes: 38 additions & 0 deletions src/components/Datasets/KonturPopulation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Protocol } from "pmtiles";
import maplibregl from "maplibre-gl";
import "maplibre-gl/dist/maplibre-gl.css";
import { Layer, Map, Source } from "react-map-gl/maplibre";
import { useEffect } from "react";
import { KonturPopulationPMTilesSource as source } from "./source";

export const KonturPopulationMap = () => {
useEffect(() => {
const protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
return () => {
maplibregl.removeProtocol("pmtiles");
};
}, []);

return (
<Map
initialViewState={{
longitude: 28.034088,
latitude: -26.195246,
zoom: 6,
}}
dragPan={true}
scrollZoom={true}
hash={false}
style={{ width: "100%", height: "100%" }}
mapStyle="stylejson/tile.openstreetmap.jp/fiord-color-gl-style/style.json"
terrain={{ source: source.id }}
>
<Source key={source.id} {...source}>
{source.layers?.map((layer) => (
<Layer key={layer.id} source-layer={layer.sourceLayer} {...layer} />
))}
</Source>
</Map>
);
};
30 changes: 30 additions & 0 deletions src/components/Datasets/KonturPopulation/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { PMTilesSource } from "../../../types/PMTilesSource";

export const KonturPopulationPMTilesSource: PMTilesSource = {
id: "kpop-source",
url: "pmtiles://https://data.source.coop/smartmaps/foil4gr1/kpop.pmtiles",
type: "vector",
attribution:
'<a href="https://data.humdata.org/m/dataset/kontur-population-dataset">Kontur Population: Global Population Density for 400m H3 Hexagons</a>',
maxzoom: 14,
minzoom: 0,
layers: [
{
id: "kpop-layer",
type: "fill",
source: "kpop-source",
sourceLayer: "kpop",
paint: {
"fill-color": [
"interpolate",
["linear"],
["number", ["get", "pop"]],
0,
"rgba(0, 255, 0, 0.01)",
100000,
"rgba(0, 255, 0, 0.6)",
],
},
},
],
};

0 comments on commit 97e8b09

Please sign in to comment.