Skip to content

High performance self-hosted photo and video management solution.

fix(web): gracefully handle map errors when WebGL is disabled (#26538)

Mees Frenseld8e25b8df048
diff --git a/i18n/en.json b/i18n/en.json
index 1afd6fb6a2..d0c8d3cbe7 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -1042,6 +1042,8 @@
"unable_to_hide_person": "Unable to hide person",
"unable_to_link_motion_video": "Unable to link motion video",
"unable_to_link_oauth_account": "Unable to link OAuth account",
+ "unable_to_load_map": "Unable to load map",
+ "unable_to_load_map_description": "The map requires WebGL to work properly.",
"unable_to_log_out_all_devices": "Unable to log out all devices",
"unable_to_log_out_device": "Unable to log out device",
"unable_to_login_with_oauth": "Unable to login with OAuth",
diff --git a/web/src/lib/components/shared-components/map/Map.svelte b/web/src/lib/components/shared-components/map/Map.svelte
index 9811a8a7be..21fc991116 100644
--- a/web/src/lib/components/shared-components/map/Map.svelte
+++ b/web/src/lib/components/shared-components/map/Map.svelte
@@ -16,7 +16,7 @@
import { mapSettings } from '$lib/stores/preferences.store';
import { getAssetMediaUrl, handlePromiseError } from '$lib/utils';
import { getMapMarkers, type MapMarkerResponseDto } from '@immich/sdk';
- import { Icon, modalManager, Theme, themeManager } from '@immich/ui';
+ import { Alert, Container, Icon, modalManager, Text, Theme, themeManager } from '@immich/ui';
import { mdiCog, mdiMap, mdiMapMarker } from '@mdi/js';
import type { Feature, GeoJsonProperties, Geometry, Point } from 'geojson';
import { isEqual, omit } from 'lodash-es';
@@ -322,109 +322,119 @@
</script>
<OnEvents onAssetsDelete={onAssetsChanged} onAssetsArchive={onAssetsChanged} onAssetsUnarchive={onAssetsChanged} />
-
<!-- We handle style loading ourselves so we set style blank here -->
-<MapLibre
- {hash}
- style=""
- class="h-full {rounded ? 'rounded-2xl' : 'rounded-none'}"
- {zoom}
- {center}
- bounds={initialBounds}
- fitBoundsOptions={{ padding: 50, maxZoom: 15 }}
- attributionControl={false}
- diffStyleUpdates={true}
- onload={(event: Map) => {
- event.setMaxZoom(18);
- event.on('click', handleMapClick);
- if (!simplified) {
- event.addControl(new GlobeControl(), 'top-left');
- }
- }}
- bind:map
->
- {#snippet children({ map }: { map: Map })}
- {#if showSimpleControls}
- <NavigationControl position="top-left" showCompass={!simplified} />
-
- {#if !simplified}
- <GeolocateControl position="top-left" />
- <ScaleControl />
- <AttributionControl compact={false} />
+
+<svelte:boundary>
+ <MapLibre
+ {hash}
+ style=""
+ class="h-full {rounded ? 'rounded-2xl' : 'rounded-none'}"
+ {zoom}
+ {center}
+ bounds={initialBounds}
+ fitBoundsOptions={{ padding: 50, maxZoom: 15 }}
+ attributionControl={false}
+ diffStyleUpdates={true}
+ onload={(event: Map) => {
+ event.setMaxZoom(18);
+ event.on('click', handleMapClick);
+ if (!simplified) {
+ event.addControl(new GlobeControl(), 'top-left');
+ }
+ }}
+ bind:map
+ >
+ {#snippet children({ map }: { map: Map })}
+ {#if showSimpleControls}
+ <NavigationControl position="top-left" showCompass={!simplified} />
+
+ {#if !simplified}
+ <GeolocateControl position="top-left" />
+ <ScaleControl />
+ <AttributionControl compact={false} />
+ {/if}
{/if}
- {/if}
-
- {#if showSettings}
- <Control>
- <ControlGroup>
- <ControlButton onclick={handleSettingsClick}>
- <Icon icon={mdiCog} size="100%" class="text-black/80" />
- </ControlButton>
- </ControlGroup>
- </Control>
- {/if}
-
- {#if onOpenInMapView && showSimpleControls}
- <Control position="top-right">
- <ControlGroup>
- <ControlButton onclick={() => onOpenInMapView()}>
- <Icon title={$t('open_in_map_view')} icon={mdiMap} size="100%" class="text-black/80" />
- </ControlButton>
- </ControlGroup>
- </Control>
- {/if}
-
- <GeoJSON
- data={{
- type: 'FeatureCollection',
- features: mapMarkers?.map((marker) => asFeature(marker)) ?? [],
- }}
- id="geojson"
- cluster={{ radius: 35, maxZoom: 18 }}
- >
- <MarkerLayer
- applyToClusters
- asButton
- onclick={(event) => handlePromiseError(handleClusterClick(event.feature.properties?.cluster_id, map))}
- >
- {#snippet children({ feature })}
- <div
- class="flex size-10 items-center justify-center rounded-full bg-immich-primary font-mono font-bold text-white opacity-90 shadow-lg transition-all duration-200 hover:bg-immich-dark-primary hover:text-immich-dark-bg"
- >
- {feature.properties?.point_count?.toLocaleString()}
- </div>
- {/snippet}
- </MarkerLayer>
- <MarkerLayer
- applyToClusters={false}
- asButton
- onclick={(event) => {
- if (!popup) {
- handleAssetClick(event.feature.properties?.id, map);
- }
+
+ {#if showSettings}
+ <Control>
+ <ControlGroup>
+ <ControlButton onclick={handleSettingsClick}>
+ <Icon icon={mdiCog} size="100%" class="text-black/80" />
+ </ControlButton>
+ </ControlGroup>
+ </Control>
+ {/if}
+
+ {#if onOpenInMapView && showSimpleControls}
+ <Control position="top-right">
+ <ControlGroup>
+ <ControlButton onclick={() => onOpenInMapView()}>
+ <Icon title={$t('open_in_map_view')} icon={mdiMap} size="100%" class="text-black/80" />
+ </ControlButton>
+ </ControlGroup>
+ </Control>
+ {/if}
+
+ <GeoJSON
+ data={{
+ type: 'FeatureCollection',
+ features: mapMarkers?.map((marker) => asFeature(marker)) ?? [],
}}
+ id="geojson"
+ cluster={{ radius: 35, maxZoom: 18 }}
>
- {#snippet children({ feature }: { feature: Feature })}
- {#if useLocationPin}
- <Icon icon={mdiMapMarker} size="50px" class="translate-y-[calc(5px-50%)] text-primary" />
- {:else}
- <img
- src={getAssetMediaUrl({ id: feature.properties?.id })}
- class="size-15 rounded-full border-2 border-immich-primary bg-immich-primary object-cover shadow-lg transition-all duration-200 hover:scale-150 hover:border-immich-dark-primary"
- alt={feature.properties?.city && feature.properties.country
- ? $t('map_marker_for_image', {
- values: { city: feature.properties.city, country: feature.properties.country },
- })
- : $t('map_marker_with_image')}
- />
- {/if}
- {#if popup}
- <Popup offset={[0, -30]} openOn="click" closeOnClickOutside>
- {@render popup({ marker: asMarker(feature) })}
- </Popup>
- {/if}
- {/snippet}
- </MarkerLayer>
- </GeoJSON>
+ <MarkerLayer
+ applyToClusters
+ asButton
+ onclick={(event) => handlePromiseError(handleClusterClick(event.feature.properties?.cluster_id, map))}
+ >
+ {#snippet children({ feature })}
+ <div
+ class="flex size-10 items-center justify-center rounded-full bg-immich-primary font-mono font-bold text-white opacity-90 shadow-lg transition-all duration-200 hover:bg-immich-dark-primary hover:text-immich-dark-bg"
+ >
+ {feature.properties?.point_count?.toLocaleString()}
+ </div>
+ {/snippet}
+ </MarkerLayer>
+ <MarkerLayer
+ applyToClusters={false}
+ asButton
+ onclick={(event) => {
+ if (!popup) {
+ handleAssetClick(event.feature.properties?.id, map);
+ }
+ }}
+ >
+ {#snippet children({ feature }: { feature: Feature })}
+ {#if useLocationPin}
+ <Icon icon={mdiMapMarker} size="50px" class="translate-y-[calc(5px-50%)] text-primary" />
+ {:else}
+ <img
+ src={getAssetMediaUrl({ id: feature.properties?.id })}
+ class="size-15 rounded-full border-2 border-immich-primary bg-immich-primary object-cover shadow-lg transition-all duration-200 hover:scale-150 hover:border-immich-dark-primary"
+ alt={feature.properties?.city && feature.properties.country
+ ? $t('map_marker_for_image', {
+ values: { city: feature.properties.city, country: feature.properties.country },
+ })
+ : $t('map_marker_with_image')}
+ />
+ {/if}
+ {#if popup}
+ <Popup offset={[0, -30]} openOn="click" closeOnClickOutside>
+ {@render popup({ marker: asMarker(feature) })}
+ </Popup>
+ {/if}
+ {/snippet}
+ </MarkerLayer>
+ </GeoJSON>
+ {/snippet}
+ </MapLibre>
+
+ {#snippet failed()}
+ <Container size="small" class="p-2">
+ <Alert color="warning" title={$t('errors.unable_to_load_map')} size={simplified ? 'medium' : 'large'}>
+ <Text size={simplified ? 'small' : 'medium'}>{$t('errors.unable_to_load_map_description')}</Text>
+ </Alert>
+ </Container>
{/snippet}
-</MapLibre>
+</svelte:boundary>