Skip to content

Commit

Permalink
Merge pull request #97 from UNopenGIS/yuiseki/impl-smp-gelmap
Browse files Browse the repository at this point in the history
Implement Smart Maps GEL Map component
  • Loading branch information
yuiseki authored Jul 1, 2024
2 parents f02ccb2 + 9e14377 commit 88b439f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/components/Datasets/GEL/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, StoryObj } from '@storybook/react';
import { GELMap } from '.';

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

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

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

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

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

export const GELPMTilesSource: PMTilesSource = {
id: "gel-source",
url: "https://beta.source.coop/smartmaps/gel/gel.pmtiles",
type: "raster",
attribution: '<a href="https://lpdaac.usgs.gov/products/nasadem_hgtv001/">NASADEM</a>, <a href="https://globalmaps.github.io/">Global Map (ISCGM)</a>',
maxzoom: 12,
minzoom: 6,
terrain: {
source: "gel-source",
},
layers: [
{
id: "gel-hills",
type: "hillshade",
source: "gel-source",
paint: {
"hillshade-shadow-color": "#473B24",
},
},
],
};

0 comments on commit 88b439f

Please sign in to comment.