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(explore-map): 添加聚类标记,优化地图标记显示

Timothy Yinf1e7b39f6681
diff --git a/app/components/ThumbImage.vue b/app/components/ThumbImage.vue
index c4d6af99..7ee0efb4 100644
--- a/app/components/ThumbImage.vue
+++ b/app/components/ThumbImage.vue
@@ -63,9 +63,9 @@ const onError = () => {
:style="style"
>
<ThumbHash
- v-if="thumbhash && !isLoaded"
+ v-if="thumbhash"
:thumbhash="thumbhash"
- class="absolute inset-0 scale-110 blur-sm"
+ class="absolute inset-0 scale-110 blur-sm -z-10"
/>
<img
diff --git a/app/components/map/ClusterPin.vue b/app/components/map/ClusterPin.vue
new file mode 100644
index 00000000..fe30cec2
--- /dev/null
+++ b/app/components/map/ClusterPin.vue
@@ -0,0 +1,281 @@
+<script lang="ts" setup>
+import { motion } from 'motion-v'
+import ThumbImage from '../ThumbImage.vue'
+import { twMerge } from 'tailwind-merge'
+import type { ClusterPoint } from '~~/shared/types/map'
+
+const props = withDefaults(
+ defineProps<{
+ clusterPoint: ClusterPoint
+ isSelected?: boolean
+ clusterCount?: number
+ }>(),
+ {
+ isSelected: false,
+ clusterCount: 6,
+ },
+)
+
+const emit = defineEmits<{
+ click: [clusterPoint: ClusterPoint]
+ close: []
+}>()
+
+const dayjs = useDayjs()
+
+const onClick = () => {
+ emit('click', props.clusterPoint)
+}
+
+const clusteredPhotos = computed(
+ () => props.clusterPoint.properties.clusteredPhotos || [],
+)
+const pointCount = computed(
+ () => props.clusterPoint.properties.point_count || 1,
+)
+const representativePhoto = computed(
+ () => props.clusterPoint.properties.marker!,
+)
+</script>
+
+<template>
+ <MapboxDefaultMarker
+ :key="`cluster-${representativePhoto.id}`"
+ :marker-id="`cluster-${representativePhoto.id}`"
+ :lnglat="props.clusterPoint.geometry.coordinates"
+ :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"
+ >
+ <div
+ v-if="isSelected"
+ class="bg-primary/30 absolute -inset-1 animate-pulse rounded-full"
+ />
+
+ <!-- Background image -->
+ <div class="absolute inset-0 overflow-hidden rounded-full">
+ <ThumbImage
+ :src="representativePhoto.thumbnailUrl!"
+ :alt="
+ representativePhoto.title || `聚类 ${representativePhoto.id}`
+ "
+ :thumbhash="representativePhoto.thumbnailHash"
+ :threshold="0.1"
+ root-margin="100px"
+ class="h-full w-full object-cover opacity-40"
+ />
+ <div
+ class="from-blue/60 to-purple/80 dark:from-blue/70 dark:to-purple/90 absolute inset-0 bg-gradient-to-br"
+ />
+ </div>
+
+ <!-- Cluster marker -->
+ <div
+ :class="
+ twMerge(
+ 'relative size-12 flex flex-col 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"
+ />
+
+ <!-- Cluster count -->
+ <span
+ class="text-white text-sm font-bold drop-shadow leading-none"
+ >
+ {{ pointCount }}
+ </span>
+
+ <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>
+
+ <!-- Cluster preview -->
+ <div class="relative overflow-hidden p-3 space-y-3">
+ <div class="flex items-center justify-between">
+ <h3 class="text-sm font-semibold">
+ 附近有 {{ clusteredPhotos.length }} 张照片
+ </h3>
+ <div class="text-muted text-[10px]">点击图片查看详情</div>
+ </div>
+ <!-- Show grid of photos for cluster -->
+ <div class="grid grid-cols-3 gap-2 h-full">
+ <motion.div
+ v-for="(photo, index) in clusteredPhotos.slice(
+ 0,
+ clusterCount,
+ )"
+ :key="photo.id"
+ :initial="{ opacity: 0, scale: 0.5 }"
+ :animate="{ opacity: 1, scale: 1 }"
+ :transition="{
+ delay: index * 0.05,
+ type: 'spring',
+ duration: 0.4,
+ bounce: 0,
+ }"
+ class="relative overflow-hidden rounded group"
+ >
+ <NuxtLink
+ class="block w-full h-full"
+ :to="`/${photo.id}`"
+ target="_blank"
+ rel="noopener"
+ >
+ <ThumbImage
+ :src="photo.thumbnailUrl!"
+ :alt="photo.title || `照片 ${photo.id}`"
+ :thumbhash="photo.thumbnailHash"
+ :threshold="0.1"
+ root-margin="200px"
+ class="w-full aspect-square object-cover"
+ />
+ </NuxtLink>
+ <!-- Hover overlay -->
+ <div
+ class="absolute inset-0 bg-black/20 duration-300 flex justify-center items-center opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer pointer-events-none"
+ >
+ <div
+ class="rounded-full bg-black/50 p-2 backdrop-blur-sm flex justify-center items-center"
+ >
+ <Icon name="tabler:external-link" />
+ </div>
+ </div>
+ <!-- Show +N overlay for the last image if there are more -->
+ <div
+ v-if="
+ index === clusterCount - 1 &&
+ clusteredPhotos.length > clusterCount
+ "
+ class="absolute inset-0 bg-black/60 flex items-center justify-center cursor-pointer pointer-events-none"
+ >
+ <span class="text-white text-lg font-bold">
+ +{{ clusteredPhotos.length - clusterCount }}
+ </span>
+ </div>
+ </motion.div>
+ </div>
+
+ <div class="relative space-y-1">
+ <!-- cities -->
+ <div
+ v-if="
+ clusteredPhotos.length &&
+ clusteredPhotos.some((p) => p.city)
+ "
+ class="flex items-center gap-1 text-xs text-muted font-medium mt-2"
+ >
+ <Icon
+ name="tabler:map-pin"
+ class="size-4"
+ />
+ <span class="truncate">
+ {{
+ clusteredPhotos
+ .map((p) => p.city)
+ .filter((v, i, a) => v && a.indexOf(v) === i)
+ .join(', ')
+ }}
+ </span>
+ </div>
+ <!-- taken date range -->
+ <div
+ v-if="
+ clusteredPhotos.length &&
+ clusteredPhotos.some((p) => p.dateTaken)
+ "
+ class="flex items-center gap-1 text-xs text-muted font-medium mt-2"
+ >
+ <Icon
+ name="tabler:calendar-week"
+ class="size-4"
+ />
+ <span class="truncate">
+ {{
+ (() => {
+ const dates = clusteredPhotos
+ .map((p) => p.dateTaken)
+ .filter(Boolean)
+ .sort()
+ if (dates.length === 0) return ''
+ if (dates.length === 1)
+ return dayjs(dates[0]).format('YYYY年MM月DD日')
+ return `${dayjs(dates[0]).format('YYYY年MM月DD日')} - ${dayjs(dates[dates.length - 1]).format('YYYY年MM月DD日')}`
+ })()
+ }}
+ </span>
+ </div>
+ </div>
+ </div>
+ </motion.div>
+ </HoverCardContent>
+ </AnimatePresence>
+ </HoverCardPortal>
+ </HoverCardRoot>
+ </template>
+ </MapboxDefaultMarker>
+</template>
+
+<style scoped></style>
diff --git a/app/components/map/MarkerPhotoPin.vue b/app/components/map/SinglePhotoPin.vue
similarity index 78%
rename from app/components/map/MarkerPhotoPin.vue
rename to app/components/map/SinglePhotoPin.vue
index 6ae2d075..a48a71db 100644
--- a/app/components/map/MarkerPhotoPin.vue
+++ b/app/components/map/SinglePhotoPin.vue
@@ -2,10 +2,11 @@
import { motion } from 'motion-v'
import ThumbImage from '../ThumbImage.vue'
import { twMerge } from 'tailwind-merge'
+import type { ClusterPoint } from '~~/shared/types/map'
-withDefaults(
+const props = withDefaults(
defineProps<{
- photo: Photo
+ clusterPoint: ClusterPoint
isSelected?: boolean
}>(),
{
@@ -14,22 +15,24 @@ withDefaults(
)
const emit = defineEmits<{
- click: [photo: Photo]
+ click: [clusterPoint: ClusterPoint]
close: []
}>()
const dayjs = useDayjs()
-const onClick = (photo: Photo) => {
- emit('click', photo)
+const onClick = () => {
+ emit('click', props.clusterPoint)
}
+
+const marker = computed(() => props.clusterPoint.properties.marker!)
</script>
<template>
<MapboxDefaultMarker
- :key="photo.id"
- :marker-id="`photo-${photo.id}`"
- :lnglat="[photo.longitude, photo.latitude]"
+ :key="`single-${marker.id}`"
+ :marker-id="`single-${marker.id}`"
+ :lnglat="props.clusterPoint.geometry.coordinates"
:options="{}"
>
<template #marker>
@@ -51,7 +54,7 @@ const onClick = (photo: Photo) => {
stiffness: 400,
damping: 30,
}"
- @click="onClick(photo)"
+ @click="onClick"
>
<div
v-if="isSelected"
@@ -60,9 +63,9 @@ const onClick = (photo: Photo) => {
<div class="absolute inset-0 overflow-hidden rounded-full">
<ThumbImage
- :src="photo.thumbnailUrl!"
- :alt="photo.title || `照片 ${photo.id}`"
- :thumbhash="photo.thumbnailHash"
+ :src="marker.thumbnailUrl!"
+ :alt="marker.title || `照片 ${marker.id}`"
+ :thumbhash="marker.thumbnailHash"
:threshold="0.1"
root-margin="100px"
class="h-full w-full object-cover opacity-40"
@@ -72,7 +75,7 @@ const onClick = (photo: Photo) => {
/>
</div>
- <!-- main -->
+ <!-- Single photo marker -->
<div
:class="
twMerge(
@@ -131,11 +134,13 @@ const onClick = (photo: Photo) => {
class="size-5"
/>
</MapGlassButton>
+
+ <!-- Single photo preview -->
<div class="relative h-36 overflow-hidden">
<ThumbImage
- :src="photo.thumbnailUrl!"
- :alt="photo.title || `照片 ${photo.id}`"
- :thumbhash="photo.thumbnailHash"
+ :src="marker.thumbnailUrl!"
+ :alt="marker.title || `照片 ${marker.id}`"
+ :thumbhash="marker.thumbnailHash"
:threshold="0.1"
root-margin="200px"
class="w-full h-full object-cover"
@@ -144,13 +149,13 @@ const onClick = (photo: Photo) => {
<div class="relative px-3 py-2 space-y-1">
<!-- Header -->
<NuxtLink
- :to="`/${photo.id}`"
+ :to="`/${marker.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}` }}
+ {{ marker.title || `照片 ${marker.id}` }}
</h3>
<Icon
name="tabler:external-link"
@@ -161,19 +166,19 @@ const onClick = (photo: Photo) => {
<!-- Metadata -->
<div class="space-y-1">
<div
- v-if="photo.city || photo.exif?.DateTimeOriginal"
+ v-if="marker.city || marker.exif?.DateTimeOriginal"
class="flex items-center gap-1 text-xs text-muted font-medium mb-2"
>
- <div v-if="photo.city">
+ <div v-if="marker.city">
<span class="truncate">
- {{ photo.city }}
+ {{ marker.city }}
</span>
</div>
<span>·</span>
- <div v-if="photo.exif?.DateTimeOriginal">
+ <div v-if="marker.exif?.DateTimeOriginal">
<span class="truncate">
{{
- dayjs(photo.exif.DateTimeOriginal).format(
+ dayjs(marker.exif.DateTimeOriginal).format(
'YY年MM月DD日',
)
}}
@@ -182,7 +187,7 @@ const onClick = (photo: Photo) => {
</div>
<!-- Camera -->
<div
- v-if="photo.exif?.Make || photo.exif?.Model"
+ v-if="marker.exif?.Make || marker.exif?.Model"
class="flex items-center gap-1 text-xs text-muted"
>
<Icon
@@ -191,7 +196,7 @@ const onClick = (photo: Photo) => {
/>
<span class="truncate">
{{
- [photo.exif?.Make, photo.exif?.Model]
+ [marker.exif?.Make, marker.exif?.Model]
.filter(Boolean)
.join(' ')
}}
@@ -199,7 +204,7 @@ const onClick = (photo: Photo) => {
</div>
<!-- Latlng -->
<div
- v-if="photo.exif?.GPSLatitude || photo.exif?.GPSLongitude"
+ v-if="marker.exif?.GPSLatitude || marker.exif?.GPSLongitude"
class="flex items-center gap-1 text-xs text-muted"
>
<Icon
@@ -208,20 +213,20 @@ const onClick = (photo: Photo) => {
/>
<span class="truncate font-mono">
{{
- photo.exif?.GPSLatitude
- ? `${Math.abs(Number(photo.exif?.GPSLatitude)).toFixed(4)}°${photo.exif?.GPSLatitudeRef}`
+ marker.exif?.GPSLatitude
+ ? `${Math.abs(Number(marker.exif?.GPSLatitude)).toFixed(4)}°${marker.exif?.GPSLatitudeRef}`
: '未知'
}},
{{
- photo.exif?.GPSLongitude
- ? `${Math.abs(Number(photo.exif?.GPSLongitude)).toFixed(4)}°${photo.exif?.GPSLongitudeRef}`
+ marker.exif?.GPSLongitude
+ ? `${Math.abs(Number(marker.exif?.GPSLongitude)).toFixed(4)}°${marker.exif?.GPSLongitudeRef}`
: '未知'
}}
</span>
</div>
<!-- Altitude -->
<div
- v-if="photo.exif?.GPSAltitude"
+ v-if="marker.exif?.GPSAltitude"
class="flex items-center gap-1 text-xs text-muted"
>
<Icon
@@ -230,7 +235,7 @@ const onClick = (photo: Photo) => {
/>
<span class="truncate font-mono">
{{
- `${photo.exif.GPSAltitudeRef === 'Below Sea Level' ? '-' : ''}${Math.abs(Number(photo.exif.GPSAltitude)).toFixed(1)}m`
+ `${marker.exif.GPSAltitudeRef === 'Below Sea Level' ? '-' : ''}${Math.abs(Number(marker.exif.GPSAltitude)).toFixed(1)}m`
}}
</span>
</div>
diff --git a/app/pages/explore.vue b/app/pages/explore.vue
index d5a8f722..4b7382d2 100644
--- a/app/pages/explore.vue
+++ b/app/pages/explore.vue
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import { motion } from 'motion-v'
+import { clusterMarkers, photosToMarkers } from '~/utils/clustering'
useHead({
title: '地图探索',
@@ -21,10 +22,30 @@ const photosWithLocation = computed(() => {
)
})
-const currentPhotoId = ref<string | null>(null)
+const currentClusterPointId = ref<string | null>(null)
const mapInstance = ref<any>(null)
+const currentZoom = ref<number>(4)
-watch(currentPhotoId, (newId) => {
+// Convert photos to markers and apply clustering
+const clusteredMarkers = computed(() => {
+ const markers = photosToMarkers(photosWithLocation.value)
+ return clusterMarkers(markers, currentZoom.value)
+})
+
+// Separate clusters and single markers
+const clusterGroups = computed(() => {
+ return clusteredMarkers.value.filter(
+ (point) => point.properties.cluster === true,
+ )
+})
+
+const singleMarkers = computed(() => {
+ return clusteredMarkers.value.filter(
+ (point) => point.properties.cluster !== true,
+ )
+})
+
+watch(currentClusterPointId, (newId) => {
if (newId) {
router.replace({ query: { ...route.query, photoId: newId } })
} else {
@@ -75,35 +96,75 @@ const mapViewState = computed(() => {
}
})
-const onMarkerPinClick = (photo: Photo) => {
- if (photo.id === currentPhotoId.value) {
- currentPhotoId.value = null
+const onMarkerPinClick = (clusterPoint: any) => {
+ // If it's a cluster, zoom to the cluster area
+ if (clusterPoint.properties.cluster === true) {
+ const clusteredPhotos = clusterPoint.properties.clusteredPhotos || []
+ if (clusteredPhotos.length > 0 && mapInstance.value) {
+ // Calculate bounds for all photos in the cluster
+ const lats = clusteredPhotos.map((p: any) => p.latitude)
+ const lngs = clusteredPhotos.map((p: any) => p.longitude)
+
+ const minLat = Math.min(...lats)
+ const maxLat = Math.max(...lats)
+ const minLng = Math.min(...lngs)
+ const maxLng = Math.max(...lngs)
+
+ // Add some padding
+ const padding = 0.001
+
+ mapInstance.value.fitBounds(
+ [
+ [minLng - padding, minLat - padding],
+ [maxLng + padding, maxLat + padding],
+ ],
+ {
+ padding: 50,
+ duration: 1000,
+ },
+ )
+ }
return
}
- currentPhotoId.value = photo.id
+
+ // Handle single photo selection
+ if (clusterPoint.properties.marker?.id === currentClusterPointId.value) {
+ currentClusterPointId.value = null
+ return
+ }
+ currentClusterPointId.value = clusterPoint.properties.marker?.id || null
}
const onMarkerPinClose = () => {
- currentPhotoId.value = null
+ currentClusterPointId.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
+ currentClusterPointId.value = photoId
nextTick(() => {
map.flyTo({
center: [photo.longitude, photo.latitude],
- zoom: 8,
+ zoom: 15,
essential: true,
+ duration: 2000,
})
})
}
}
+
+ currentZoom.value = map.getZoom()
}
+
+const onMapZoom = useThrottleFn(() => {
+ if (!mapInstance.value) return
+ currentZoom.value = mapInstance.value.getZoom()
+}, 100)
</script>
<template>
@@ -119,7 +180,7 @@ const onMapLoaded = (map: any) => {
</MapGlassButton>
<motion.div
- :initial="{ opacity: 0, scale: 1.1 }"
+ :initial="{ opacity: 0, scale: 1.08 }"
:animate="{ opacity: 1, scale: 1 }"
:transition="{ duration: 0.6, delay: 0.1 }"
class="w-full h-full"
@@ -137,15 +198,32 @@ const onMapLoaded = (map: any) => {
colorThemes: 'faded',
},
},
+ attributionControl: false,
language: 'zh-Hans',
}"
@load="onMapLoaded"
+ @zoom="onMapZoom"
>
- <LazyMapMarkerPhotoPin
- v-for="photo in photosWithLocation"
- :key="photo.id"
- :photo="photo"
- :is-selected="photo.id === currentPhotoId"
+ <!-- Cluster pins -->
+ <LazyMapClusterPin
+ v-for="clusterPoint in clusterGroups"
+ :key="`cluster-${clusterPoint.properties.marker?.id}`"
+ :cluster-point="clusterPoint"
+ :is-selected="
+ clusterPoint.properties.marker?.id === currentClusterPointId
+ "
+ @click="onMarkerPinClick"
+ @close="onMarkerPinClose"
+ />
+
+ <!-- Single photo pins -->
+ <LazyMapSinglePhotoPin
+ v-for="clusterPoint in singleMarkers"
+ :key="`single-${clusterPoint.properties.marker?.id}`"
+ :cluster-point="clusterPoint"
+ :is-selected="
+ clusterPoint.properties.marker?.id === currentClusterPointId
+ "
@click="onMarkerPinClick"
@close="onMarkerPinClose"
/>
@@ -154,7 +232,7 @@ const onMapLoaded = (map: any) => {
</div>
</template>
-<style scoped>
+<style>
.mapboxgl-ctrl-logo {
display: none !important;
}
diff --git a/app/utils/clustering.ts b/app/utils/clustering.ts
new file mode 100644
index 00000000..866b0b6a
--- /dev/null
+++ b/app/utils/clustering.ts
@@ -0,0 +1,110 @@
+import type { PhotoMarker, ClusterPoint } from '~~/shared/types/map'
+
+/**
+ * Simple clustering algorithm for small datasets
+ * @param markers Array of photo markers to cluster
+ * @param zoom Current zoom level
+ * @returns Array of cluster points
+ */
+export function clusterMarkers(
+ markers: PhotoMarker[],
+ zoom: number,
+): ClusterPoint[] {
+ if (markers.length === 0) return []
+
+ // At high zoom levels, don't cluster
+ if (zoom >= 15) {
+ return markers.map((marker) => ({
+ type: 'Feature' as const,
+ properties: { marker },
+ geometry: {
+ type: 'Point' as const,
+ coordinates: [marker.longitude, marker.latitude],
+ },
+ }))
+ }
+
+ const clusters: ClusterPoint[] = []
+ const processed = new Set<string>()
+
+ const threshold = Math.max(0.001, 0.01 / Math.pow(2, zoom - 10))
+
+ for (const marker of markers) {
+ if (processed.has(marker.id)) continue
+
+ const nearby = [marker]
+ processed.add(marker.id)
+
+ // Find nearby markers
+ for (const other of markers) {
+ if (processed.has(other.id)) continue
+
+ const distance = Math.sqrt(
+ Math.pow(marker.longitude - other.longitude, 2) +
+ Math.pow(marker.latitude - other.latitude, 2),
+ )
+
+ if (distance < threshold) {
+ nearby.push(other)
+ processed.add(other.id)
+ }
+ }
+
+ if (nearby.length === 1) {
+ // Single marker
+ clusters.push({
+ type: 'Feature',
+ properties: { marker },
+ geometry: {
+ type: 'Point',
+ coordinates: [marker.longitude, marker.latitude],
+ },
+ })
+ } else {
+ // Cluster
+ const centerLng =
+ nearby.reduce((sum, m) => sum + m.longitude, 0) / nearby.length
+ const centerLat =
+ nearby.reduce((sum, m) => sum + m.latitude, 0) / nearby.length
+
+ clusters.push({
+ type: 'Feature',
+ properties: {
+ cluster: true,
+ point_count: nearby.length,
+ point_count_abbreviated: nearby.length.toString(),
+ marker: nearby[0], // Representative marker for the cluster
+ clusteredPhotos: nearby, // All photos in the cluster
+ },
+ geometry: {
+ type: 'Point',
+ coordinates: [centerLng, centerLat],
+ },
+ })
+ }
+ }
+
+ return clusters
+}
+
+export function photosToMarkers(photos: Photo[]): PhotoMarker[] {
+ return photos
+ .filter(
+ (photo) =>
+ photo.latitude !== null &&
+ photo.longitude !== null &&
+ photo.latitude !== undefined &&
+ photo.longitude !== undefined,
+ )
+ .map((photo) => ({
+ id: photo.id,
+ latitude: photo.latitude!,
+ longitude: photo.longitude!,
+ title: photo.title || undefined,
+ thumbnailUrl: photo.thumbnailUrl || undefined,
+ thumbnailHash: photo.thumbnailHash || undefined,
+ dateTaken: photo.dateTaken || undefined,
+ city: photo.city || undefined,
+ exif: photo.exif || undefined,
+ }))
+}
diff --git a/shared/types/map.ts b/shared/types/map.ts
new file mode 100644
index 00000000..586e376e
--- /dev/null
+++ b/shared/types/map.ts
@@ -0,0 +1,26 @@
+export interface PhotoMarker {
+ id: string
+ latitude: number
+ longitude: number
+ title?: string
+ thumbnailUrl?: string
+ thumbnailHash?: string
+ dateTaken?: string
+ city?: string
+ exif?: any
+}
+
+export interface ClusterPoint {
+ type: 'Feature'
+ properties: {
+ marker?: PhotoMarker
+ cluster?: boolean
+ point_count?: number
+ point_count_abbreviated?: string
+ clusteredPhotos?: PhotoMarker[]
+ }
+ geometry: {
+ type: 'Point'
+ coordinates: [number, number]
+ }
+}