Skip to content

Commit

Permalink
feat: Add preview of PMTiles of Overture Maps by OSMFJ
Browse files Browse the repository at this point in the history
  • Loading branch information
yuiseki committed Jun 30, 2024
1 parent fcc454b commit 8dbd570
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 50 deletions.
37 changes: 20 additions & 17 deletions src/components/Combined/ArmedConflictWithBaseMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import "maplibre-gl/dist/maplibre-gl.css";
import { Layer, Map, Source } from "react-map-gl/maplibre";
import { useEffect } from "react";

export const ArmedConflictWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}) => {
const source = {
id: "uppsala-conflict",
url: "pmtiles://https://data.source.coop/smartmaps/uppsala-conflict/a.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

export const ArmedConflictWithBaseMap: React.FC<{ mapStyle: string }> = ({
mapStyle,
}) => {
useEffect(() => {
const protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
Expand All @@ -13,14 +23,6 @@ export const ArmedConflictWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}
};
}, []);

const layer = {
id: "uppsala-conflict",
url: "pmtiles://https://data.source.coop/smartmaps/uppsala-conflict/a.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

return (
<Map
initialViewState={{
Expand All @@ -35,17 +37,18 @@ export const ArmedConflictWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}
mapStyle={mapStyle}
>
<Source
key={`${layer.id}-source`}
id={`${layer.id}-source`}
key={`${source.id}-source`}
id={`${source.id}-source`}
type="vector"
url={layer.url}
attribution={layer.attribution}
maxzoom={layer.maxzoom}
minzoom={layer.minzoom}
url={source.url}
attribution={source.attribution}
maxzoom={source.maxzoom}
minzoom={source.minzoom}
>
<Layer
id={`${layer.id}-layer`}
source={`${layer.id}-source`}
key={`${source.id}-layer`}
id={`${source.id}-layer`}
source={`${source.id}-source`}
source-layer="event"
type="circle"
paint={{
Expand Down
37 changes: 20 additions & 17 deletions src/components/Combined/OpenCellIdWithBaseMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import "maplibre-gl/dist/maplibre-gl.css";
import { Layer, Map, Source } from "react-map-gl/maplibre";
import { useEffect } from "react";

export const OpenCellIdWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}) => {
const source = {
id: "opencellid",
url: "pmtiles://https://data.source.coop/smartmaps/opencellid/cellid.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

export const OpenCellIdWithBaseMap: React.FC<{ mapStyle: string }> = ({
mapStyle,
}) => {
useEffect(() => {
const protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);
Expand All @@ -13,14 +23,6 @@ export const OpenCellIdWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}) =
};
}, []);

const layer = {
id: "opencellid",
url: "pmtiles://https://data.source.coop/smartmaps/opencellid/cellid.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

return (
<Map
initialViewState={{
Expand All @@ -35,17 +37,18 @@ export const OpenCellIdWithBaseMap:React.FC<{mapStyle: string}> = ({mapStyle}) =
mapStyle={mapStyle}
>
<Source
key={`${layer.id}-source`}
id={`${layer.id}-source`}
key={`${source.id}-source`}
id={`${source.id}-source`}
type="vector"
url={layer.url}
attribution={layer.attribution}
maxzoom={layer.maxzoom}
minzoom={layer.minzoom}
url={source.url}
attribution={source.attribution}
maxzoom={source.maxzoom}
minzoom={source.minzoom}
>
<Layer
id={`${layer.id}-layer`}
source={`${layer.id}-source`}
key={`${source.id}-layer`}
id={`${source.id}-layer`}
source={`${source.id}-source`}
source-layer="a"
type="circle"
paint={{
Expand Down
33 changes: 17 additions & 16 deletions src/components/Datasets/OpenCellId/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import "maplibre-gl/dist/maplibre-gl.css";
import { Layer, Map, Source } from "react-map-gl/maplibre";
import { useEffect } from "react";

const source = {
id: "opencellid",
url: "pmtiles://https://data.source.coop/smartmaps/opencellid/cellid.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

export const OpenCellId = () => {
useEffect(() => {
const protocol = new Protocol();
Expand All @@ -13,14 +21,6 @@ export const OpenCellId = () => {
};
}, []);

const layer = {
id: "opencellid",
url: "pmtiles://https://data.source.coop/smartmaps/opencellid/cellid.pmtiles",
attribution: '<a href="https://opencellid.org/">OpenCelliD</a>',
maxzoom: 18,
minzoom: 2,
};

return (
<Map
initialViewState={{
Expand All @@ -35,17 +35,18 @@ export const OpenCellId = () => {
mapStyle="stylejson/tile.openstreetmap.jp/fiord-color-gl-style/style.json"
>
<Source
key={`${layer.id}-source`}
id={`${layer.id}-source`}
key={`${source.id}-source`}
id={`${source.id}-source`}
type="vector"
url={layer.url}
attribution={layer.attribution}
maxzoom={layer.maxzoom}
minzoom={layer.minzoom}
url={source.url}
attribution={source.attribution}
maxzoom={source.maxzoom}
minzoom={source.minzoom}
>
<Layer
id={`${layer.id}-layer`}
source="opencellid-source"
key={`${source.id}-layer`}
id={`${source.id}-layer`}
source={`${source.id}-source`}
source-layer="a"
type="circle"
paint={{
Expand Down
14 changes: 14 additions & 0 deletions src/components/Datasets/OvertureMaps/index.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta, StoryObj } from "@storybook/react";
import { OvertureMaps } from ".";

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

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

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

const source = {
id: "overture-maps-source",
url: "pmtiles://https://tile.openstreetmap.jp/static/overture.pmtiles",
attribution: '<a href="https://overturemaps.org/">Overture Maps Foundation</a>',
maxzoom: 18,
minzoom: 2,
layers: [
{
id: "building-layer",
sourceLayer: "building",
type: "fill",
paint: {
"fill-color": "rgba(141, 211, 199, 0.8)",
},
},
{
id: "transportation-layer",
sourceLayer: "transportation",
type: "line",
paint: {
"line-color": "rgba(255, 255, 179, 0.8)",
"line-width": 1,
},
},
{
id: "water-layer",
sourceLayer: "water",
type: "fill",
paint: {
"fill-color": "rgba(173, 216, 230, 0.8)",
},
}
]
};

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

return (
<Map
initialViewState={{
longitude: 139.75288,
latitude: 35.68458,
zoom: 14,
}}
dragPan={true}
scrollZoom={true}
hash={false}
style={{ width: "100%", height: "100%" }}
mapStyle="stylejson/tile.openstreetmap.jp/fiord-color-gl-style/style.json"
>
<Source
key={`${source.id}-source`}
id={`${source.id}-source`}
type="vector"
url={source.url}
attribution={source.attribution}
maxzoom={source.maxzoom}
minzoom={source.minzoom}
>
{source.layers.map((layer) => {
switch (layer.type) {
case "fill":
case "line":
return (
<Layer
key={`${layer.id}-layer`}
id={`${layer.id}-layer`}
source={`${source.id}-source`}
source-layer={layer.sourceLayer}
type={layer.type}
paint={layer.paint}
/>
);
default:
return null;
}
})}
</Source>
</Map>
);
};

0 comments on commit 8dbd570

Please sign in to comment.