Skip to content

Commit

Permalink
Add preview of DEM of Rwanda
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Jun 30, 2024
1 parent 66bf755 commit 37d87ce
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"geofabrik",
"Geographics",
"geoservices",
"hillshade",
"hinanbasho",
"Maxar",
"naturalearthdata",
Expand Down
14 changes: 14 additions & 0 deletions src/components/Datasets/Rwanda10/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, StoryObj } from "@storybook/react";
import { Rwanda10Map } from ".";

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

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

export const Preview: Story = {};
37 changes: 37 additions & 0 deletions src/components/Datasets/Rwanda10/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 { Rwanda10PMTilesSource as source } from "./source";

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

return (
<Map
initialViewState={{
longitude: 30.07232666015625,
latitude: -1.9826364384297364,
pitch: 60,
zoom: 8,
}}
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, exaggeration: 2 }}
>
<Source key={source.id} {...source}>
{source.layers?.map((layer) => <Layer key={layer.id} {...layer} />)}
</Source>
</Map>
);
};
27 changes: 27 additions & 0 deletions src/components/Datasets/Rwanda10/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { PMTilesSource } from "../../../types/PMTilesSource";

export const Rwanda10PMTilesSource: PMTilesSource = {
id: "rwanda-10-source",
tiles: [
"pmtiles://https://data.source.coop/smartmaps/rwanda10/rwanda10.pmtiles/{z}/{x}/{y}.webp",
],
tileSize: 512,
type: "raster-dem",
attribution:
"Water and Sanitation Corporation (WASAC), National Land Authority (NLA)",
maxzoom: 14,
minzoom: 2,
terrain: {
source: "rwanda-10-source",
},
layers: [
{
id: "rwanda-10-hills",
type: "hillshade",
source: "rwanda-10-source",
paint: {
"hillshade-shadow-color": "#473B24",
},
},
],
};
7 changes: 6 additions & 1 deletion src/types/PMTilesSource.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export type PMTilesSource = {
id: string;
url: string;
url?: string;
tiles?: string[];
tileSize?: number;
type: "vector" | "raster" | "raster-dem";
attribution: string;
maxzoom?: number;
minzoom?: number;
layers?: LayerProps[];
terrain?: {
source: string;
};
};

0 comments on commit 37d87ce

Please sign in to comment.