From d774f3a53cf4fb6f8ad2948b88c366dce74db124 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Fri, 12 Jul 2024 15:00:33 +0200 Subject: [PATCH] embedding progress --- .github/workflows/deploy.yml | 1 + website/.env.example | 1 + website/src/lib/assets/layers.ts | 5 +- website/src/lib/components/Map.svelte | 7 +- website/src/lib/components/Nav.svelte | 2 +- .../src/lib/components/docs/DocsLoader.svelte | 7 +- .../lib/components/embedding/Embedding.svelte | 205 ++++++++++++++++ .../src/lib/components/embedding/Embedding.ts | 63 +++++ .../EmbeddingPlayground.svelte | 119 +++++---- .../lib/components/gpx-layer/GPXLayers.svelte | 7 +- website/src/lib/docs/en/integration.mdx | 7 +- website/src/locales/en.json | 6 +- .../src/routes/[...language]/app/+page.svelte | 11 + .../routes/[...language]/embed/+page.svelte | 226 +----------------- 14 files changed, 386 insertions(+), 281 deletions(-) create mode 100644 website/.env.example create mode 100644 website/src/lib/components/embedding/Embedding.svelte create mode 100644 website/src/lib/components/embedding/Embedding.ts rename website/src/lib/components/{ => embedding}/EmbeddingPlayground.svelte (68%) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 104f923f..23c69941 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -31,6 +31,7 @@ jobs: - name: Build website env: BASE_PATH: '/${{ github.event.repository.name }}' + PUBLIC_MAPBOX_TOKEN: ${{ secrets.PUBLIC_MAPBOX_TOKEN }} run: | npm run build --prefix website diff --git a/website/.env.example b/website/.env.example new file mode 100644 index 00000000..4d6b95bd --- /dev/null +++ b/website/.env.example @@ -0,0 +1 @@ +PUBLIC_MAPBOX_TOKEN=YOUR_MAPBOX_TOKEN \ No newline at end of file diff --git a/website/src/lib/assets/layers.ts b/website/src/lib/assets/layers.ts index 1207a78b..03c4f17b 100644 --- a/website/src/lib/assets/layers.ts +++ b/website/src/lib/assets/layers.ts @@ -1,7 +1,6 @@ +import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public'; import { type AnySourceData, type Style } from 'mapbox-gl'; -export const mapboxAccessToken = 'pk.eyJ1IjoidmNvcHBlIiwiYSI6ImNseG0zNHpwdTA1NXUycXF4ejJyODc0NWQifQ.4tiCPQ1SxnYl4o7aQc89VA'; - export const basemaps: { [key: string]: string | Style; } = { mapboxOutdoors: 'mapbox://styles/mapbox/outdoors-v12', mapboxSatellite: 'mapbox://styles/mapbox/satellite-streets-v12', @@ -269,7 +268,7 @@ export const basemaps: { [key: string]: string | Style; } = { export function extendBasemap(basemap: string | Style): string | Style { if (typeof basemap === 'object') { basemap["glyphs"] = "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"; - basemap["sprite"] = `https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/sprite?access_token=${mapboxAccessToken}`; + basemap["sprite"] = `https://api.mapbox.com/styles/v1/mapbox/outdoors-v12/sprite?access_token=${PUBLIC_MAPBOX_TOKEN}`; } return basemap; } diff --git a/website/src/lib/components/Map.svelte b/website/src/lib/components/Map.svelte index 0140a941..bf1c3a20 100644 --- a/website/src/lib/components/Map.svelte +++ b/website/src/lib/components/Map.svelte @@ -11,12 +11,13 @@ import { settings } from '$lib/db'; import { locale } from 'svelte-i18n'; import { get } from 'svelte/store'; - import { mapboxAccessToken } from '$lib/assets/layers'; - - mapboxgl.accessToken = mapboxAccessToken; + import { PUBLIC_MAPBOX_TOKEN } from '$env/static/public'; + export let accessToken = PUBLIC_MAPBOX_TOKEN; export let geocoder = true; + mapboxgl.accessToken = accessToken; + let fitBoundsOptions: mapboxgl.FitBoundsOptions = { maxZoom: 15, linear: true, diff --git a/website/src/lib/components/Nav.svelte b/website/src/lib/components/Nav.svelte index 09e3c8f7..efefc824 100644 --- a/website/src/lib/components/Nav.svelte +++ b/website/src/lib/components/Nav.svelte @@ -7,7 +7,7 @@ import { getURLForLanguage } from '$lib/utils'; -