Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Restore photo map cluster tap-to-zoom

Neeraj Guptac63353bc6fba
diff --git a/mobile/apps/photos/lib/ui/map/image_marker.dart b/mobile/apps/photos/lib/ui/map/image_marker.dart
index 98105ae414..a72c3c46a0 100644
--- a/mobile/apps/photos/lib/ui/map/image_marker.dart
+++ b/mobile/apps/photos/lib/ui/map/image_marker.dart
@@ -1,3 +1,4 @@
+import "package:flutter_map/flutter_map.dart";
import 'package:photos/models/file/file.dart';
class ImageMarker {
@@ -5,11 +6,13 @@ class ImageMarker {
final double latitude;
final double longitude;
final int imageCount;
+ final LatLngBounds? clusterBounds;
ImageMarker({
required this.imageFile,
required this.latitude,
required this.longitude,
this.imageCount = 1,
+ this.clusterBounds,
});
}
diff --git a/mobile/apps/photos/lib/ui/map/map_isolate.dart b/mobile/apps/photos/lib/ui/map/map_isolate.dart
index 2cf008da2f..21b36139aa 100644
--- a/mobile/apps/photos/lib/ui/map/map_isolate.dart
+++ b/mobile/apps/photos/lib/ui/map/map_isolate.dart
@@ -20,13 +20,24 @@ class MapMarkerGroup {
final double latitude;
final double longitude;
final int imageCount;
+ final double north;
+ final double south;
+ final double east;
+ final double west;
const MapMarkerGroup({
required this.imageIndex,
required this.latitude,
required this.longitude,
required this.imageCount,
+ required this.north,
+ required this.south,
+ required this.east,
+ required this.west,
});
+
+ LatLngBounds get bounds =>
+ LatLngBounds.unsafe(north: north, south: south, east: east, west: west);
}
class _ProjectedMarkerGroup {
@@ -36,6 +47,10 @@ class _ProjectedMarkerGroup {
final double x;
final double y;
int imageCount = 1;
+ double north;
+ double south;
+ double east;
+ double west;
_ProjectedMarkerGroup({
required this.imageIndex,
@@ -43,14 +58,29 @@ class _ProjectedMarkerGroup {
required this.longitude,
required this.x,
required this.y,
- });
+ }) : north = latitude,
+ south = latitude,
+ east = longitude,
+ west = longitude;
MapMarkerGroup toMarkerGroup() => MapMarkerGroup(
imageIndex: imageIndex,
latitude: latitude,
longitude: longitude,
imageCount: imageCount,
+ north: north,
+ south: south,
+ east: east,
+ west: west,
);
+
+ void add(MapPoint point) {
+ imageCount++;
+ north = max(north, point.latitude);
+ south = min(south, point.latitude);
+ east = max(east, point.longitude);
+ west = min(west, point.longitude);
+ }
}
class _ProjectedMapPoint {
@@ -188,7 +218,7 @@ void mapWorker(MapWorkerInit init) {
}
if (closestGroup != null) {
- closestGroup.imageCount++;
+ closestGroup.add(point);
return;
}
diff --git a/mobile/apps/photos/lib/ui/map/map_marker.dart b/mobile/apps/photos/lib/ui/map/map_marker.dart
index f30bb2637c..58449c0ea4 100644
--- a/mobile/apps/photos/lib/ui/map/map_marker.dart
+++ b/mobile/apps/photos/lib/ui/map/map_marker.dart
@@ -10,24 +10,33 @@ Marker mapMarker(
ImageMarker imageMarker,
ValueKey<int> key, {
Size markerSize = MapView.defaultMarkerSize,
+ VoidCallback? onTap,
}) {
+ final markerChild = Stack(
+ children: [
+ MarkerImage(
+ file: imageMarker.imageFile,
+ seperator:
+ (MapView.defaultMarkerSize.height + 10) -
+ (MapView.defaultMarkerSize.height - markerSize.height),
+ ),
+ if (imageMarker.imageCount > 1)
+ MapGalleryTileBadge(size: imageMarker.imageCount),
+ ],
+ );
+
return Marker(
alignment: Alignment.topCenter,
key: key,
width: markerSize.width,
height: markerSize.height,
point: LatLng(imageMarker.latitude, imageMarker.longitude),
- child: Stack(
- children: [
- MarkerImage(
- file: imageMarker.imageFile,
- seperator:
- (MapView.defaultMarkerSize.height + 10) -
- (MapView.defaultMarkerSize.height - markerSize.height),
- ),
- if (imageMarker.imageCount > 1)
- MapGalleryTileBadge(size: imageMarker.imageCount),
- ],
- ),
+ child: onTap == null
+ ? markerChild
+ : GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: onTap,
+ child: markerChild,
+ ),
);
}
diff --git a/mobile/apps/photos/lib/ui/map/map_screen.dart b/mobile/apps/photos/lib/ui/map/map_screen.dart
index 8c6daa56b5..99f0c21a54 100644
--- a/mobile/apps/photos/lib/ui/map/map_screen.dart
+++ b/mobile/apps/photos/lib/ui/map/map_screen.dart
@@ -218,6 +218,7 @@ class _MapScreenState extends State<MapScreen> {
latitude: group.latitude,
longitude: group.longitude,
imageCount: group.imageCount,
+ clusterBounds: group.imageCount > 1 ? group.bounds : null,
),
)
.toList(growable: false);
diff --git a/mobile/apps/photos/lib/ui/map/map_view.dart b/mobile/apps/photos/lib/ui/map/map_view.dart
index ca6327a774..618a9856f2 100644
--- a/mobile/apps/photos/lib/ui/map/map_view.dart
+++ b/mobile/apps/photos/lib/ui/map/map_view.dart
@@ -203,10 +203,22 @@ class _MapViewState extends State<MapView> {
List<Marker> _buildMarkers() {
return List<Marker>.generate(widget.imageMarkers.length, (index) {
final imageMarker = widget.imageMarkers[index];
+ final clusterBounds = imageMarker.clusterBounds;
return mapMarker(
imageMarker,
ValueKey(index),
markerSize: widget.markerSize,
+ onTap: clusterBounds == null
+ ? null
+ : () {
+ widget.controller.fitCamera(
+ CameraFit.bounds(
+ bounds: clusterBounds,
+ padding: const EdgeInsets.all(80),
+ maxZoom: widget.maxZoom,
+ ),
+ );
+ },
);
});
}