Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

feat: 新增探索地图,可通过查询参数跳转到指定图片位置

Timothy Yin9ca6cd6d81d0
diff --git a/app/components/ThumbImage.vue b/app/components/ThumbImage.vue
new file mode 100644
index 00000000..c4d6af99
--- /dev/null
+++ b/app/components/ThumbImage.vue
@@ -0,0 +1,101 @@
+<script lang="ts" setup>
+import { twMerge } from 'tailwind-merge'
+import type { CSSProperties } from 'vue'
+
+const props = withDefaults(
+ defineProps<{
+ src: string
+ alt: string
+ thumbhash?: string | null
+ class?: string
+ style?: CSSProperties
+ threshold?: number | number[]
+ rootMargin?: string
+ }>(),
+ {
+ thumbhash: null,
+ class: '',
+ style: undefined,
+ threshold: 0.1,
+ rootMargin: '50px',
+ },
+)
+
+const emit = defineEmits<{
+ load: []
+ error: []
+}>()
+
+const elemRef = useTemplateRef('elemRef')
+const isElemVisible = ref(false)
+const isLoaded = ref(false)
+const isError = ref(false)
+
+const { stop } = useIntersectionObserver(
+ elemRef,
+ ([entry], _observerElement) => {
+ isElemVisible.value = entry?.isIntersecting || false
+ if (isElemVisible.value) {
+ stop()
+ }
+ },
+ {
+ threshold: props.threshold,
+ rootMargin: props.rootMargin,
+ },
+)
+
+const onLoaded = () => {
+ isLoaded.value = true
+ emit('load')
+}
+
+const onError = () => {
+ isError.value = true
+ emit('error')
+}
+</script>
+
+<template>
+ <div
+ ref="elemRef"
+ :class="twMerge('relative overflow-hidden', $props.class)"
+ :style="style"
+ >
+ <ThumbHash
+ v-if="thumbhash && !isLoaded"
+ :thumbhash="thumbhash"
+ class="absolute inset-0 scale-110 blur-sm"
+ />
+
+ <img
+ v-if="isElemVisible"
+ loading="lazy"
+ :src="src"
+ :alt="alt"
+ :class="
+ twMerge(
+ 'w-full h-full object-cover transition-opacity duration-300',
+ isLoaded ? 'opacity-100' : 'opacity-0',
+ )
+ "
+ @load="onLoaded"
+ @error="onError"
+ />
+
+ <div
+ v-if="isError"
+ class="absolute inset-0 flex justify-center items-center bg-neutral-200 dark:bg-neutral-800"
+ >
+ <Icon
+ name="tabler:photo-off"
+ class="size-6 text-neutral-400"
+ />
+ <p class="mt-2 text-sm text-neutral-500 dark:text-neutral-400">
+ 加载图片失败
+ </p>
+ </div>
+ </div>
+</template>
+
+<style scoped></style>
diff --git a/app/components/map/GlassButton.vue b/app/components/map/GlassButton.vue
index af6775ec..783e7ef7 100644
--- a/app/components/map/GlassButton.vue
+++ b/app/components/map/GlassButton.vue
@@ -25,8 +25,8 @@ withDefaults(
type="button"
:class="
twMerge(
- $props.class,
'pointer-events-auto flex size-10 items-center justify-center rounded-xl bg-black/20 text-white backdrop-blur-md border border-white/10 shadow-lg shadow-black/25 overflow-hidden',
+ $props.class,
)
"
@click="$emit('click')"
diff --git a/app/components/map/MarkerPhotoPin.vue b/app/components/map/MarkerPhotoPin.vue
new file mode 100644
index 00000000..6ae2d075
--- /dev/null
+++ b/app/components/map/MarkerPhotoPin.vue
@@ -0,0 +1,248 @@
+<script lang="ts" setup>
+import { motion } from 'motion-v'
+import ThumbImage from '../ThumbImage.vue'
+import { twMerge } from 'tailwind-merge'
+
+withDefaults(
+ defineProps<{
+ photo: Photo
+ isSelected?: boolean
+ }>(),
+ {
+ isSelected: false,
+ },
+)
+
+const emit = defineEmits<{
+ click: [photo: Photo]
+ close: []
+}>()
+
+const dayjs = useDayjs()
+
+const onClick = (photo: Photo) => {
+ emit('click', photo)
+}
+</script>
+
+<template>
+ <MapboxDefaultMarker
+ :key="photo.id"
+ :marker-id="`photo-${photo.id}`"
+ :lnglat="[photo.longitude, photo.latitude]"
+ :options="{}"
+ >
+ <template #marker>
+ <HoverCardRoot
+ :open="isSelected || undefined"
+ :open-delay="isSelected ? 0 : 600"
+ :close-delay="isSelected ? Number.MAX_SAFE_INTEGER : 100"
+ @close="$event.preventDefault()"
+ >
+ <HoverCardTrigger as-child>
+ <motion.div
+ class="relative group cursor-pointer"
+ :initial="{ opacity: 0, scale: 0 }"
+ :animate="{ opacity: 1, scale: 1 }"
+ :while-hover="{ scale: 1.1 }"
+ :while-press="{ scale: 0.95 }"
+ :transition="{
+ type: 'spring',
+ stiffness: 400,
+ damping: 30,
+ }"
+ @click="onClick(photo)"
+ >
+ <div
+ v-if="isSelected"
+ class="bg-primary/30 absolute -inset-1 animate-pulse rounded-full"
+ />
+
+ <div class="absolute inset-0 overflow-hidden rounded-full">
+ <ThumbImage
+ :src="photo.thumbnailUrl!"
+ :alt="photo.title || `照片 ${photo.id}`"
+ :thumbhash="photo.thumbnailHash"
+ :threshold="0.1"
+ root-margin="100px"
+ class="h-full w-full object-cover opacity-40"
+ />
+ <div
+ class="from-green/60 to-emerald/80 dark:from-green/70 dark:to-emerald/90 absolute inset-0 bg-gradient-to-br"
+ />
+ </div>
+
+ <!-- main -->
+ <div
+ :class="
+ twMerge(
+ 'relative size-10 flex justify-center items-center rounded-full border shadow-lg hover:shadow-xl backdrop-blur-md',
+ isSelected
+ ? 'border-primary/40 bg-primary/90 shadow-primary/50 dark:border-primary/30 dark:bg-primary/80'
+ : 'border-white/40 bg-white/95 hover:bg-white dark:border-white/20 dark:bg-black/80 dark:hover:bg-black/90',
+ )
+ "
+ >
+ <div
+ class="absolute inset-0 rounded-full bg-gradient-to-br from-white/30 to-white/10 dark:from-white/20 dark:to-white/5"
+ />
+ <Icon
+ name="tabler:photo"
+ class="size-5 text-white drop-shadow"
+ />
+ <div
+ class="absolute inset-0 rounded-full shadow-inner shadow-black/5"
+ />
+ </div>
+ </motion.div>
+ </HoverCardTrigger>
+ <HoverCardPortal>
+ <AnimatePresence>
+ <HoverCardContent
+ as-child
+ side="top"
+ align="center"
+ :side-offset="8"
+ @pointer-down-outside="
+ isSelected ? $event.preventDefault() : undefined
+ "
+ @escape-key-down="
+ isSelected ? $event.preventDefault() : undefined
+ "
+ @focus-outside="isSelected ? $event.preventDefault() : undefined"
+ @interact-outside="
+ isSelected ? $event.preventDefault() : undefined
+ "
+ >
+ <motion.div
+ class="bg-black/50 backdrop-blur-md border border-neutral-700 rounded-lg shadow-lg w-xs max-w-xs overflow-hidden relative"
+ :initial="{ opacity: 0, scale: 0.95, y: 4 }"
+ :animate="{ opacity: 1, scale: 1, y: 0 }"
+ :exit="{ opacity: 0, scale: 0.95, y: 4 }"
+ :transition="{ duration: 0.2 }"
+ >
+ <MapGlassButton
+ v-if="isSelected"
+ class="absolute top-2 right-2 z-10 size-8"
+ @click="$emit('close')"
+ >
+ <Icon
+ name="tabler:x"
+ class="size-5"
+ />
+ </MapGlassButton>
+ <div class="relative h-36 overflow-hidden">
+ <ThumbImage
+ :src="photo.thumbnailUrl!"
+ :alt="photo.title || `照片 ${photo.id}`"
+ :thumbhash="photo.thumbnailHash"
+ :threshold="0.1"
+ root-margin="200px"
+ class="w-full h-full object-cover"
+ />
+ </div>
+ <div class="relative px-3 py-2 space-y-1">
+ <!-- Header -->
+ <NuxtLink
+ :to="`/${photo.id}`"
+ target="_blank"
+ rel="noopener"
+ class="flex items-center gap-2 text-white group/link"
+ >
+ <h3 class="flex-1 text-lg font-semibold truncate">
+ {{ photo.title || `照片 ${photo.id}` }}
+ </h3>
+ <Icon
+ name="tabler:external-link"
+ class="size-4 text-muted opacity-0 group-hover/link:opacity-100 transition-opacity"
+ />
+ </NuxtLink>
+
+ <!-- Metadata -->
+ <div class="space-y-1">
+ <div
+ v-if="photo.city || photo.exif?.DateTimeOriginal"
+ class="flex items-center gap-1 text-xs text-muted font-medium mb-2"
+ >
+ <div v-if="photo.city">
+ <span class="truncate">
+ {{ photo.city }}
+ </span>
+ </div>
+ <span>·</span>
+ <div v-if="photo.exif?.DateTimeOriginal">
+ <span class="truncate">
+ {{
+ dayjs(photo.exif.DateTimeOriginal).format(
+ 'YY年MM月DD日',
+ )
+ }}
+ </span>
+ </div>
+ </div>
+ <!-- Camera -->
+ <div
+ v-if="photo.exif?.Make || photo.exif?.Model"
+ class="flex items-center gap-1 text-xs text-muted"
+ >
+ <Icon
+ name="tabler:camera"
+ class="size-4"
+ />
+ <span class="truncate">
+ {{
+ [photo.exif?.Make, photo.exif?.Model]
+ .filter(Boolean)
+ .join(' ')
+ }}
+ </span>
+ </div>
+ <!-- Latlng -->
+ <div
+ v-if="photo.exif?.GPSLatitude || photo.exif?.GPSLongitude"
+ class="flex items-center gap-1 text-xs text-muted"
+ >
+ <Icon
+ name="tabler:map-pin"
+ class="size-4"
+ />
+ <span class="truncate font-mono">
+ {{
+ photo.exif?.GPSLatitude
+ ? `${Math.abs(Number(photo.exif?.GPSLatitude)).toFixed(4)}°${photo.exif?.GPSLatitudeRef}`
+ : '未知'
+ }},
+ {{
+ photo.exif?.GPSLongitude
+ ? `${Math.abs(Number(photo.exif?.GPSLongitude)).toFixed(4)}°${photo.exif?.GPSLongitudeRef}`
+ : '未知'
+ }}
+ </span>
+ </div>
+ <!-- Altitude -->
+ <div
+ v-if="photo.exif?.GPSAltitude"
+ class="flex items-center gap-1 text-xs text-muted"
+ >
+ <Icon
+ name="tabler:mountain"
+ class="size-4"
+ />
+ <span class="truncate font-mono">
+ {{
+ `${photo.exif.GPSAltitudeRef === 'Below Sea Level' ? '-' : ''}${Math.abs(Number(photo.exif.GPSAltitude)).toFixed(1)}m`
+ }}
+ </span>
+ </div>
+ </div>
+ </div>
+ </motion.div>
+ </HoverCardContent>
+ </AnimatePresence>
+ </HoverCardPortal>
+ </HoverCardRoot>
+ </template>
+ </MapboxDefaultMarker>
+</template>
+
+<style scoped></style>
diff --git a/app/components/photo/InfoPanel.vue b/app/components/photo/InfoPanel.vue
index 94c7c4e8..a62f8cb2 100644
--- a/app/components/photo/InfoPanel.vue
+++ b/app/components/photo/InfoPanel.vue
@@ -407,6 +407,10 @@ const formatedExifData = computed<Record<string, KVData[]>>(() => {
})
const isMobile = useMediaQuery('(max-width: 768px)')
+
+const onMinimapClick = (photoId: string) => {
+ window.open(`/explore?photoId=${photoId}`)
+}
</script>
<template>
@@ -471,6 +475,8 @@ const isMobile = useMediaQuery('(max-width: 768px)')
:photo="currentPhoto"
:latitude="gpsCoordinates?.latitude"
:longitude="gpsCoordinates?.longitude"
+ class="cursor-pointer"
+ @click="onMinimapClick(currentPhoto.id)"
/>
<!-- EXIF/对象信息渲染器 -->
diff --git a/app/composables/useMapPerformance.ts b/app/composables/useMapPerformance.ts
new file mode 100644
index 00000000..e69de29b
diff --git a/app/pages/explore.vue b/app/pages/explore.vue
index 41d30dcf..d5a8f722 100644
--- a/app/pages/explore.vue
+++ b/app/pages/explore.vue
@@ -5,10 +5,12 @@ useHead({
title: '地图探索',
})
+const route = useRoute()
+const router = useRouter()
+
const MAPID = 'explore-map'
const { photos } = usePhotos()
-// 筛选出有GPS坐标的照片
const photosWithLocation = computed(() => {
return photos.value.filter(
(photo) =>
@@ -19,6 +21,18 @@ const photosWithLocation = computed(() => {
)
})
+const currentPhotoId = ref<string | null>(null)
+const mapInstance = ref<any>(null)
+
+watch(currentPhotoId, (newId) => {
+ if (newId) {
+ router.replace({ query: { ...route.query, photoId: newId } })
+ } else {
+ const { photoId, ...rest } = route.query
+ router.replace({ query: { ...rest } })
+ }
+})
+
const mapViewState = computed(() => {
if (photosWithLocation.value.length === 0) {
return {
@@ -61,14 +75,39 @@ const mapViewState = computed(() => {
}
})
-onMounted(() => {
- console.log(`找到 ${photosWithLocation.value.length} 张有位置信息的照片`)
-})
+const onMarkerPinClick = (photo: Photo) => {
+ if (photo.id === currentPhotoId.value) {
+ currentPhotoId.value = null
+ return
+ }
+ currentPhotoId.value = photo.id
+}
+
+const onMarkerPinClose = () => {
+ currentPhotoId.value = null
+}
+
+const onMapLoaded = (map: any) => {
+ mapInstance.value = map
+ const { photoId } = route.query
+ if (photoId && typeof photoId === 'string') {
+ const photo = photosWithLocation.value.find((photo) => photo.id === photoId)
+ if (photo && photo.latitude && photo.longitude) {
+ currentPhotoId.value = photoId
+ nextTick(() => {
+ map.flyTo({
+ center: [photo.longitude, photo.latitude],
+ zoom: 8,
+ essential: true,
+ })
+ })
+ }
+ }
+}
</script>
<template>
<div class="w-full h-svh relative overflow-hidden">
-
<MapGlassButton
class="absolute top-4 left-4 z-10"
@click="$router.push('/')"
@@ -82,14 +121,14 @@ onMounted(() => {
<motion.div
:initial="{ opacity: 0, scale: 1.1 }"
:animate="{ opacity: 1, scale: 1 }"
- :transition="{ duration: 0.6, delay: 1.5 }"
+ :transition="{ duration: 0.6, delay: 0.1 }"
class="w-full h-full"
>
<MapboxMap
class="w-full h-full"
:map-id="MAPID"
:options="{
- style: 'mapbox://styles/mapbox/standard',
+ style: 'mapbox://styles/hoshinosuzumi/cmev0eujf01dw01pje3g9cmlg',
zoom: mapViewState.zoom,
center: [mapViewState.longitude, mapViewState.latitude],
config: {
@@ -100,62 +139,27 @@ onMounted(() => {
},
language: 'zh-Hans',
}"
+ @load="onMapLoaded"
>
- <!-- 为每张有位置信息的照片添加标记 -->
- <MapboxDefaultMarker
+ <LazyMapMarkerPhotoPin
v-for="photo in photosWithLocation"
:key="photo.id"
- :marker-id="`photo-${photo.id}`"
- :lnglat="[photo.longitude, photo.latitude]"
- :options="{}"
- >
- <template #marker>
- <HoverCardRoot>
- <HoverCardTrigger as-child>
- <div
- class="photo-marker"
- :style="{
- width: '40px',
- height: '40px',
- borderRadius: '50%',
- backgroundImage: `url(${photo.thumbnailUrl})`,
- backgroundSize: 'cover',
- backgroundPosition: 'center',
- border: '3px solid white',
- boxShadow: '0 2px 8px rgba(0,0,0,0.3)',
- cursor: 'pointer',
- transition: 'transform 0.2s ease',
- }"
- />
- </HoverCardTrigger>
- <HoverCardPortal>
- <HoverCardContent
- side="top"
- :side-offset="8"
- as-child
- >
- <motion.div
- class="bg-white rounded-lg shadow-lg p-2 min-w-32 max-w-xs"
- :initial="{ opacity: 0, y: 10 }"
- :animate="{ opacity: 1, y: 0 }"
- :exit="{ opacity: 0, y: 10 }"
- :transition="{ duration: 0.2 }"
- >
- <div class="text-sm font-medium">
- {{ photo.title || `照片 ${photo.id}` }}
- </div>
- <div class="text-xs text-gray-600">
- {{ photo.city || photo.country || '未知位置' }}
- </div>
- </motion.div>
- </HoverCardContent>
- </HoverCardPortal>
- </HoverCardRoot>
- </template>
- </MapboxDefaultMarker>
+ :photo="photo"
+ :is-selected="photo.id === currentPhotoId"
+ @click="onMarkerPinClick"
+ @close="onMarkerPinClose"
+ />
</MapboxMap>
</motion.div>
</div>
</template>
-<style scoped></style>
+<style scoped>
+.mapboxgl-ctrl-logo {
+ display: none !important;
+}
+
+.mapboxgl-ctrl-attrib {
+ display: none !important;
+}
+</style>
diff --git a/nuxt.config.ts b/nuxt.config.ts
index 1df0ce13..8ea9bd32 100644
--- a/nuxt.config.ts
+++ b/nuxt.config.ts
@@ -3,7 +3,7 @@ import tailwindcss from '@tailwindcss/vite'
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
compatibilityDate: '2025-07-15',
- devtools: { enabled: true },
+ devtools: { enabled: false },
modules: [
'reka-ui/nuxt',