π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Fix TripLayout super cluster first location positioning
anandbaburajan84ae04a8f0f0
diff --git a/web/apps/photos/src/components/TripLayout/TripMap.tsx b/web/apps/photos/src/components/TripLayout/TripMap.tsxindex 796cc1ad0e..0f31055f14 100644--- a/web/apps/photos/src/components/TripLayout/TripMap.tsx+++ b/web/apps/photos/src/components/TripLayout/TripMap.tsx@@ -34,6 +34,16 @@ interface TripMapProps {targetZoom: number | null;mapRef: import("leaflet").Map | null;scrollProgress: number;+ superClusterInfo?: {+ superClusters: {+ lat: number;+ lng: number;+ clusterCount: number;+ clustersInvolved: number[];+ image: string;+ }[];+ clusterToSuperClusterMap: Map<number, number>;+ };setMapRef: (map: import("leaflet").Map | null) => void;setCurrentZoom: (zoom: number) => void;setTargetZoom: (zoom: number | null) => void;@@ -53,6 +63,7 @@ export const TripMap: React.FC<TripMapProps> = ({targetZoom,mapRef,scrollProgress,+ superClusterInfo,setMapRef,setCurrentZoom,setTargetZoom,@@ -92,7 +103,7 @@ export const TripMap: React.FC<TripMapProps> = ({<MapContainerWrapper hasPhotoData={hasPhotoData}>{hasPhotoData ? (<StyledMapContainer- center={getMapCenter(photoClusters, journeyData)}+ center={getMapCenter(photoClusters, journeyData, superClusterInfo)}zoom={isTouchDevice? Math.max(1, optimalZoom - 2)diff --git a/web/apps/photos/src/components/TripLayout/index.tsx b/web/apps/photos/src/components/TripLayout/index.tsxindex 5cf60956d1..c952655c97 100644--- a/web/apps/photos/src/components/TripLayout/index.tsx+++ b/web/apps/photos/src/components/TripLayout/index.tsx@@ -209,7 +209,14 @@ export const TripLayout: React.FC<TripLayoutProps> = ({);setPhotoClusters(sortedClusters);- setOptimalZoom(optimalZoomLevel);++ // Check if first location is in a super cluster and adjust initial zoom+ const firstLocationInSuperCluster = clusterToSuperClusterMap.has(0);+ const initialZoom = firstLocationInSuperCluster+ ? (isTouchDevice ? 15 : 14) // Super cluster zoom level+ : optimalZoomLevel;++ setOptimalZoom(initialZoom);setSuperClusterInfo({superClusters,clusterToSuperClusterMap,@@ -341,6 +348,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({targetZoom={targetZoom}mapRef={mapRef}scrollProgress={scrollProgress}+ superClusterInfo={superClusterInfo}setMapRef={setMapRef}setCurrentZoom={setCurrentZoom}setTargetZoom={setTargetZoom}@@ -558,6 +566,7 @@ export const TripLayout: React.FC<TripLayoutProps> = ({targetZoom={targetZoom}mapRef={mapRef}scrollProgress={scrollProgress}+ superClusterInfo={superClusterInfo}setMapRef={setMapRef}setCurrentZoom={setCurrentZoom}setTargetZoom={setTargetZoom}diff --git a/web/apps/photos/src/components/TripLayout/mapHelpers.ts b/web/apps/photos/src/components/TripLayout/mapHelpers.tsindex 4df27c6e79..916b3091d0 100644--- a/web/apps/photos/src/components/TripLayout/mapHelpers.ts+++ b/web/apps/photos/src/components/TripLayout/mapHelpers.ts@@ -506,6 +506,16 @@ export const detectScreenCollisions = (export const getMapCenter = (photoClusters: JourneyPoint[][],journeyData: JourneyPoint[],+ superClusterInfo?: {+ superClusters: {+ lat: number;+ lng: number;+ clusterCount: number;+ clustersInvolved: number[];+ image: string;+ }[];+ clusterToSuperClusterMap: Map<number, number>;+ },): [number, number] => {// If no clusters yet, check journey dataif (photoClusters.length === 0) {@@ -523,6 +533,20 @@ export const getMapCenter = (const firstLng =firstCluster.reduce((sum, p) => sum + p.lng, 0) / firstCluster.length;+ // Check if first location is in a super cluster - apply positioning for super cluster zoom level+ const firstLocationInSuperCluster = superClusterInfo?.clusterToSuperClusterMap.has(0);+ if (firstLocationInSuperCluster) {+ // For super cluster first location, apply positioning calculated for super cluster zoom level+ const isMobile = typeof window !== "undefined" && window.innerWidth <= 768;+ const superClusterZoom = isMobile ? 15 : 14;+ const [positionedLat, positionedLng] = getLocationPositionAtZoom(+ firstLat,+ firstLng,+ superClusterZoom,+ );+ return [positionedLat, positionedLng];+ }+// Position first location at 20% from right edge (80% from left)// At zoom level 10, each pixel represents approximately 152.87 meters// On mobile, timeline is at bottom so full width is available; on desktop, timeline takes up 50% of screen widthdiff --git a/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts b/web/apps/photos/src/components/TripLayout/utils/scrollUtils.tsindex 886e0cdedd..104ece8e6d 100644--- a/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts+++ b/web/apps/photos/src/components/TripLayout/utils/scrollUtils.ts@@ -159,6 +159,7 @@ export const handleTimelineScroll = ({// Check if this is a distant location (>500km from previous)let isDistantLocation = false;+ const isFirstLocationEver = previousActiveLocationIndex === -1;if (previousActiveLocationIndex !== -1 &&previousActiveLocationIndex !== currentActiveLocationIndex@@ -195,7 +196,17 @@ export const handleTimelineScroll = ({try {// Handle super cluster zoom logic - check distant locations first!- if (isInSuperCluster && !wasInSuperCluster && isDistantLocation) {+ if (isInSuperCluster && !wasInSuperCluster && isFirstLocationEver) {+ // First location ever and it's in a super cluster - directly zoom to super cluster level+ const superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clusters+ const [zoomAwareLat, zoomAwareLng] = getLocationPositionAtZoom(+ targetCluster.lat,+ targetCluster.lng,+ superClusterZoom,+ );+ setTargetZoom(superClusterZoom);+ mapRef.setView([zoomAwareLat, zoomAwareLng], superClusterZoom);+ } else if (isInSuperCluster && !wasInSuperCluster && isDistantLocation) {// Entering super cluster from distant location - full zoom out β pan β zoom inconst superClusterZoom = isTouchDevice ? 15 : 14; // Higher zoom on mobile to break apart clustersconst intermediateZoom = isTouchDevice ? 2 : 4; // Extreme zoom out for distant locations