Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basemap control component in mapper frontend + opfs pmtile support (pt1) #1922

Merged
merged 8 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OSM_CLIENT_ID=${OSM_CLIENT_ID}
OSM_CLIENT_SECRET=${OSM_CLIENT_SECRET}
OSM_URL=${OSM_URL:-"https://www.openstreetmap.org"}
OSM_SCOPE=${OSM_SCOPE:-'["read_prefs", "send_messages"]'}
OSM_LOGIN_REDIRECT_URI=${OSM_LOGIN_REDIRECT_URI:-"http${FMTM_DOMAIN:+s}://${FMTM_DOMAIN:-127.0.0.1:7051}/osmauth"}
OSM_LOGIN_REDIRECT_URI=${OSM_LOGIN_REDIRECT_URI:-http${FMTM_DOMAIN:+s}://${FMTM_DOMAIN:-127.0.0.1:7051}/osmauth}
OSM_SECRET_KEY=${OSM_SECRET_KEY}

### S3 File Storage ###
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/e2e/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ setup('authenticate', async ({ browserName, page }) => {

// Note this sets a token so we can proceed, but the login will be
// overwritten by svcfmtm localadmin user (as DEBUG=True)
await page.goto('/playwright-temp-login/');
await page.goto('/playwright-temp-login');

// Now check we are signed in as localadmin
await page.waitForSelector('text=localadmin');
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const routes = createBrowserRouter([
),
},
{
path: '/osmauth/',
path: '/osmauth',
element: (
<Suspense fallback={<div>Loading...</div>}>
<ErrorBoundary>
Expand All @@ -189,7 +189,7 @@ const routes = createBrowserRouter([
),
},
{
path: '/playwright-temp-login/',
path: '/playwright-temp-login',
element: (
<Suspense fallback={<div>Loading...</div>}>
<ErrorBoundary>
Expand Down
2 changes: 2 additions & 0 deletions src/mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
"@turf/helpers": "^7.1.0",
"drizzle-orm": "^0.35.3",
"flatgeobuf": "^3.35.0",
"maplibre-gl": "^4.7.1",
"pako": "^2.1.0",
"pmtiles": "^4.0.1",
"svelte-maplibre": "^0.9.14",
"uuid": "^11.0.2"
},
Expand Down
13 changes: 13 additions & 0 deletions src/mapper/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions src/mapper/src/assets/images/oam-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/mapper/src/constants/baseLayers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import oamLogo from '$assets/images/oam-logo.svg';

export const osmStyle = {
id: 'OSM Raster',
version: 8,
Expand Down Expand Up @@ -105,4 +107,31 @@ let satellite = {
],
};

export const customStyle = {
id: 'Custom',
version: 8,
name: 'Custom',
metadata: {
thumbnail: oamLogo,
},
sources: {
custom: {
type: 'raster',
url: '',
tileSize: 512,
attribution: 'Protmaps',
},
},
layers: [
{
id: 'custom',
type: 'raster',
source: 'custom',
layout: {
visibility: 'visible',
},
},
],
};

export const baseLayers = [stamenStyle, esriStyle, satellite];
84 changes: 0 additions & 84 deletions src/mapper/src/lib/components/event-card.svelte

This file was deleted.

2 changes: 1 addition & 1 deletion src/mapper/src/lib/components/map/layer-switcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ map = new Map({
* Process the style to add metadata and return it.
*/
function processStyle(style: maplibregl.StyleSpecification): MapLibreStylePlusMetadata {
const thumbnailUrl = getRasterThumbnailUrl(style);
const thumbnailUrl = style?.metadata?.thumbnail || getRasterThumbnailUrl(style);
return {
...style,
metadata: {
Expand Down
51 changes: 45 additions & 6 deletions src/mapper/src/lib/components/map/main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ControlGroup,
ControlButton,
} from 'svelte-maplibre';
import maplibre from 'maplibre-gl';
import { Protocol } from 'pmtiles';
import { polygon } from '@turf/helpers';
import { buffer } from '@turf/buffer';
import { bbox } from '@turf/bbox';
Expand All @@ -30,10 +32,10 @@
import Geolocation from '$lib/components/map/geolocation.svelte';
import FlatGeobuf from '$lib/components/map/flatgeobuf-layer.svelte';
import { getTaskStore } from '$store/tasks.svelte.ts';
import { getProjectSetupStepStore } from '$store/common.svelte.ts';
import { getProjectSetupStepStore, getProjectBasemapStore } from '$store/common.svelte.ts';
// import { entityFeatcolStore, selectedEntityId } from '$store/entities';
import { projectSetupStep as projectSetupStepEnum } from '$constants/enums.ts';
import { baseLayers, osmStyle } from '$constants/baseLayers.ts';
import { baseLayers, osmStyle, customStyle } from '$constants/baseLayers.ts';
type bboxType = [number, number, number, number];
Expand All @@ -49,12 +51,31 @@
const taskStore = getTaskStore();
const projectSetupStepStore = getProjectSetupStepStore();
const projectBasemapStore = getProjectBasemapStore();
let map: maplibregl.Map | undefined = $state();
let loaded: boolean = $state(false);
let taskAreaClicked: boolean = $state(false);
let toggleGeolocationStatus: boolean = $state(false);
let projectSetupStep = $state(null);
// If no custom layer URL, omit, else set URL from projectPmtilesUrl
let processedBaseLayers = $derived(
[
...baseLayers,
...(projectBasemapStore.projectPmtilesUrl
? [{
...customStyle,
sources: {
...customStyle.sources,
custom: {
...customStyle.sources.custom,
url: projectBasemapStore.projectPmtilesUrl,
},
},
}]
: []),
]
);
$effect(() => {
projectSetupStep = +projectSetupStepStore.projectSetupStep;
Expand All @@ -64,6 +85,11 @@
$effect(() => {
if (map) {
setMapRef(map);
// Register pmtiles protocol
if (!maplibre.config.REGISTERED_PROTOCOLS.hasOwnProperty('pmtiles')) {
let protocol = new Protocol();
maplibre.addProtocol('pmtiles', protocol.tile);
}
}
});
Expand Down Expand Up @@ -103,6 +129,7 @@
{ id: 'locationDot', url: LocationDotImg },
]}
>
<!-- Controls -->
<NavigationControl position="top-left" />
<ScaleControl />
<Control class="flex flex-col gap-y-2" position="top-left">
Expand All @@ -115,6 +142,10 @@
>
</ControlGroup></Control
>
<Control class="flex flex-col gap-y-2" position="bottom-right">
<LayerSwitcher {map} extraStyles={processedBaseLayers} sourcesIdToReAdd={['tasks', 'entities', 'geolocation']} />
<Legend />
</Control>
<!-- Add the Geolocation GeoJSON layer to the map -->
{#if toggleGeolocationStatus}
<Geolocation bind:map bind:toggleGeolocationStatus></Geolocation>
Expand Down Expand Up @@ -191,10 +222,18 @@
manageHoverState
/>
</FlatGeobuf>
<Control class="flex flex-col gap-y-2" position="bottom-right">
<LayerSwitcher {map} extraStyles={baseLayers} sourcesIdToReAdd={['tasks', 'entities', 'geolocation']} />
<Legend />
</Control>

<!-- Offline pmtiles, if present (alternative approach, not baselayer) -->
<!-- {#if projectBasemapStore.projectPmtilesUrl}
<RasterTileSource
url={projectBasemapStore.projectPmtilesUrl}
tileSize={512}
>
<RasterLayer id="pmtile-basemap" paint={{'raster-opacity': 0.8}}></RasterLayer>
</RasterTileSource>
{/if} -->

<!-- Help text for user on first load -->
{#if projectSetupStep === projectSetupStepEnum['task_selection']}
<div class="absolute top-5 w-fit bg-[#F097334D] z-10 left-[50%] translate-x-[-50%] p-1">
<p class="uppercase font-barlow-medium text-base">please select a task / feature for mapping</p>
Expand Down
Loading