Skip to content

Commit

Permalink
dummy map with a single fire risk layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitb35 committed Aug 23, 2024
1 parent 1b1c666 commit 4fbbf14
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
74 changes: 74 additions & 0 deletions pages/sites/[slug]/[locale]/test-layers.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { AbstractIntlMessages } from 'next-intl';
import { Tenant } from '@planet-sdk/common';
import {
GetStaticProps,
GetStaticPropsContext,
GetStaticPropsResult,
} from 'next';
import {
constructPathsForTenantSlug,
getTenantConfig,
} from '../../../../src/utils/multiTenancy/helpers';
import { defaultTenant } from '../../../../tenant.config';
import getMessagesForPage from '../../../../src/utils/language/getMessagesForPage';
import LayersMap from '../../../../src/layers/LayersMap';

export default function TestLayersPage() {
return (
<div
style={{
marginTop: '90px',
display: 'flex',
height: 'calc(100vh - 90px)',
width: '100vw',
}}
>
<div style={{ width: '100%', height: '100%' }}>
<LayersMap />
</div>
</div>
);
}

export const getStaticPaths = async () => {
const subDomainPaths = await constructPathsForTenantSlug();

const paths = subDomainPaths?.map((path) => {
return {
params: {
slug: path.params.slug,
locale: 'en',
},
};
});

return {
paths,
fallback: 'blocking',
};
};

interface PageProps {
messages: AbstractIntlMessages;
tenantConfig: Tenant;
}

export const getStaticProps: GetStaticProps<PageProps> = async (
context: GetStaticPropsContext
): Promise<GetStaticPropsResult<PageProps>> => {
const tenantConfig =
(await getTenantConfig(context.params?.slug as string)) ?? defaultTenant;

const messages = await getMessagesForPage({
locale: context.params?.locale as string,
filenames: ['common', 'donate', 'country', 'manageProjects', 'leaderboard'],
});

return {
props: {
messages,
tenantConfig,
},
};
};
78 changes: 78 additions & 0 deletions src/layers/LayersMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { useEffect, useState } from 'react';
import Map, { MapStyle, Source, Layer } from 'react-map-gl-v7/maplibre';
import getMapStyle from '../utils/maps/getMapStyle';
import 'maplibre-gl/dist/maplibre-gl.css';
import { NavigationControl } from 'react-map-gl-v7/maplibre';
import { useRef, MutableRefObject } from 'react';
import { ViewState } from 'react-map-gl-v7';

interface MapState {
mapStyle: MapStyle;
dragPan: boolean;
scrollZoom: boolean;
minZoom: number;
maxZoom: number;
}

const EMPTY_STYLE = {
version: 8,
sources: {},
layers: [] as MapStyle['layers'],
} as const;

function LayersMap() {
const mapRef: MutableRefObject<null> = useRef(null);
// mapState and viewState logic will need to be refined and move elsewhere (either context or props) once we fetch data from the API
const [mapState, setMapState] = useState<MapState>({
mapStyle: EMPTY_STYLE,
dragPan: true,
scrollZoom: false,
minZoom: 1,
maxZoom: 15,
});

const [viewState, setViewState] = useState<ViewState>({
longitude: 0,
latitude: 0,
zoom: 1,
bearing: 0,
pitch: 0,
padding: { top: 0, bottom: 0, left: 0, right: 0 },
});

useEffect(() => {
async function loadMapStyle() {
const result = await getMapStyle('default');
if (result) {
setMapState({ ...mapState, mapStyle: result });
}
}
loadMapStyle();
}, []);

return (
<Map
{...viewState}
{...mapState}
onMove={(e) => setViewState(e.viewState)}
attributionControl={false}
ref={mapRef}
>
<Source
id="fire-risk"
type="raster"
tiles={[
'https://earthengine.googleapis.com/v1/projects/earthengine-legacy/maps/9c4db4d0bbe22da0e7c252cc39ca9d65-88782d9edf58c24334f9ab81d59d9e4f/tiles/{z}/{x}/{y}',
// 'https://wayback.maptiles.arcgis.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
// 'https://earthengine.googleapis.com/v1/projects/earthengine-legacy/maps/532c05ae29f0bd7c3bdb152cdce3d916-ace5fc0d8b4f5433db239a31da8d0eb7/tiles/{z}/{x}/{y}',
]}
tileSize={256}
>
<Layer id="fire-risk-layer" source="fire-risk" type="raster" />
</Source>
<NavigationControl position="bottom-right" showCompass={false} />
</Map>
);
}

export default LayersMap;

0 comments on commit 4fbbf14

Please sign in to comment.