Skip to content

Commit 90be5c7

Browse files
committed
fix(web): use the main-map style for the photo-gallery minimap
The minimap was hardcoded to `maptilerStyleUrl("bright-v2", env)` and also bailed early when `env.maptilerKey` was empty. On the self-hosted deployment (`NEXT_PUBLIC_STYLE_PROVIDER=openmapx`, MapTiler key empty) both branches failed: the bail-out skipped MapLibre instantiation entirely, leaving just the bordered container — which is what the gallery rendered as a black box. Mirror the MapCanvas style-loading split: when `env.styleProvider === "openmapx"` resolve `loadOpenMapXStyle(env)` (same self-hosted openmapx-streets style, tiles/sprite/glyphs patched in from env); otherwise fall back to the cloud style URL. The MapLibre import and style fetch run in parallel via `Promise.all`, and a top-level catch keeps a failed style load from surfacing as an unhandled rejection. The minimap now uses the same tiles and style as the main map.
1 parent 076162a commit 90be5c7

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

apps/web/src/components/panels/place/PlacePhotoGallery.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { useLocale, useTranslations } from "next-intl";
2525
import { useCallback, useEffect, useRef, useState } from "react";
2626
import { useEnv } from "@/lib/EnvProvider";
2727
import { useMap } from "@/lib/MapContext";
28-
import { maptilerStyleUrl } from "@/lib/map";
28+
import { loadOpenMapXStyle, maptilerStyleUrl } from "@/lib/map";
2929
import { PhotoAttribution } from "./PhotoAttribution";
3030

3131
interface Props {
@@ -513,12 +513,23 @@ function GalleryMinimap({ lng, lat, onClick }: { lng: number; lat: number; onCli
513513

514514
let cancelled = false;
515515

516-
import("maplibre-gl").then(({ default: maplibregl }) => {
517-
if (cancelled || !el || !env.maptilerKey) return;
516+
// Mirror MapCanvas: when the operator runs the openmapx-streets style
517+
// off a self-hosted tileserver, fetch the style as a JSON object and
518+
// patch in tiles/sprite/glyphs from env. Otherwise fall back to the
519+
// MapTiler Cloud style URL (requires `env.maptilerKey`).
520+
(async () => {
521+
const [{ default: maplibregl }, style] = await Promise.all([
522+
import("maplibre-gl"),
523+
env.styleProvider === "openmapx"
524+
? loadOpenMapXStyle(env)
525+
: Promise.resolve(maptilerStyleUrl("bright-v2", env)),
526+
]);
527+
if (cancelled || !el) return;
528+
if (env.styleProvider !== "openmapx" && !env.maptilerKey) return;
518529

519530
const map = new maplibregl.Map({
520531
container: el,
521-
style: maptilerStyleUrl("bright-v2", env),
532+
style: style as string | maplibregl.StyleSpecification,
522533
center: [lng, lat],
523534
zoom: 16,
524535
interactive: false,
@@ -528,6 +539,8 @@ function GalleryMinimap({ lng, lat, onClick }: { lng: number; lat: number; onCli
528539
const marker = new maplibregl.Marker({ color: "#e53935" }).setLngLat([lng, lat]).addTo(map);
529540

530541
mapRef.current = { map, marker };
542+
})().catch(() => {
543+
// Style load or MapLibre import failed — leave the container empty.
531544
});
532545

533546
return () => {

0 commit comments

Comments
 (0)