aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/LocationsMap.svelte
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-02-03 13:46:15 -0800
committerAdam Soltys <[email protected]>2026-02-11 15:34:01 -0800
commit918f4b29bc66be343914fd4c9284375825c57fdf (patch)
tree68f1b93ee8f1d60400988fd71231295ca886bad6 /src/components/LocationsMap.svelte
parent44f09f89eb8f69dbb9bba76e0a55125093e7ecc0 (diff)
downloadcoinos-ui-918f4b29bc66be343914fd4c9284375825c57fdf.tar.gz
coinos-ui-918f4b29bc66be343914fd4c9284375825c57fdf.zip
cleanup
Diffstat (limited to 'src/components/LocationsMap.svelte')
-rw-r--r--src/components/LocationsMap.svelte42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/components/LocationsMap.svelte b/src/components/LocationsMap.svelte
index 5de5ac56..eec704a8 100644
--- a/src/components/LocationsMap.svelte
+++ b/src/components/LocationsMap.svelte
@@ -4,8 +4,6 @@
import Popup from "$comp/Popup.svelte";
import { back } from "$lib/utils";
- import "maplibre-gl/dist/maplibre-gl.css";
-
let { locations } = $props();
let map;
let mapContainer = $state(),
@@ -172,10 +170,46 @@
let locationMarkers = {};
let popups = {};
let counter = 0;
+ let maplibrePromise;
+
+ const loadMaplibre = async () => {
+ if (window.maplibregl) return window.maplibregl;
+ if (maplibrePromise) return maplibrePromise;
+
+ maplibrePromise = new Promise((resolve, reject) => {
+ const existing = document.querySelector("script[data-maplibre]");
+ if (existing) {
+ if (window.maplibregl) return resolve(window.maplibregl);
+ existing.addEventListener("load", () => resolve(window.maplibregl));
+ existing.addEventListener("error", reject);
+ return;
+ }
+
+ const css = document.createElement("link");
+ css.rel = "stylesheet";
+ css.href =
+ "https://unpkg.com/[email protected]/dist/maplibre-gl.css";
+ document.head.appendChild(css);
+
+ const script = document.createElement("script");
+ script.src =
+ "https://unpkg.com/[email protected]/dist/maplibre-gl.js";
+ script.async = true;
+ script.defer = true;
+ script.dataset.maplibre = "true";
+ script.onload = () => resolve(window.maplibregl);
+ script.onerror = reject;
+ document.head.appendChild(script);
+ });
+
+ return maplibrePromise;
+ };
- onMount(() => {
+ onMount(async () => {
if (browser) {
- import("maplibre-gl").then(({ default: maplibre }) => {
+ await tick();
+ if (!mapContainer) return;
+ loadMaplibre().then((maplibre) => {
map = new maplibre.Map({
container: mapContainer,
style: "https://tiles.stadiamaps.com/styles/stamen_toner.json",