Minor fixes

This commit is contained in:
Neeraj Gupta 2023-06-14 17:04:33 +05:30
parent eecf26522d
commit 4325641b14
2 changed files with 26 additions and 34 deletions

View file

@ -8,7 +8,6 @@ import 'package:flutter_map/flutter_map.dart';
import "package:latlong2/latlong.dart";
import "package:logging/logging.dart";
import "package:photos/models/file.dart";
import "package:photos/models/location/location.dart";
import "package:photos/theme/ente_theme.dart";
import "package:photos/ui/common/loading_widget.dart";
import "package:photos/ui/map/image_marker.dart";
@ -76,34 +75,29 @@ class _MapScreenState extends State<MapScreen> {
late double minLat, maxLat, minLon, maxLon;
final List<ImageMarker> tempMarkers = [];
bool hasAnyLocation = false;
await Future.forEach<File>(files, (file) async {
final rand = Random();
file.location = Location(
latitude: 10.786971 * rand.nextDouble() * 0.1,
longitude: 78.688241 * rand.nextDouble() * 0.1,
);
// if (file.hasLocation) {
if (!hasAnyLocation) {
minLat = file.location!.latitude!;
minLon = file.location!.longitude!;
maxLat = file.location!.latitude!;
maxLon = file.location!.longitude!;
hasAnyLocation = true;
} else {
minLat = min(minLat, file.location!.latitude!);
minLon = min(minLon, file.location!.longitude!);
maxLat = max(maxLat, file.location!.latitude!);
maxLon = max(maxLon, file.location!.longitude!);
for (final file in files) {
if (file.hasLocation) {
if (!hasAnyLocation) {
minLat = file.location!.latitude!;
minLon = file.location!.longitude!;
maxLat = file.location!.latitude!;
maxLon = file.location!.longitude!;
hasAnyLocation = true;
} else {
minLat = min(minLat, file.location!.latitude!);
minLon = min(minLon, file.location!.longitude!);
maxLat = max(maxLat, file.location!.latitude!);
maxLon = max(maxLon, file.location!.longitude!);
}
tempMarkers.add(
ImageMarker(
latitude: file.location!.latitude!,
longitude: file.location!.longitude!,
imageFile: file,
),
);
}
tempMarkers.add(
ImageMarker(
latitude: file.location!.latitude!,
longitude: file.location!.longitude!,
imageFile: file,
),
);
// }
});
}
if (hasAnyLocation) {
center = LatLng(
@ -176,12 +170,12 @@ class _MapScreenState extends State<MapScreen> {
final SendPort sendPort = message.sendPort;
try {
final List<File> images = [];
imageMarkers.forEach((imageMarker) async {
for (var imageMarker in imageMarkers) {
final point = LatLng(imageMarker.latitude, imageMarker.longitude);
if (bounds.contains(point)) {
images.add(imageMarker.imageFile);
}
});
}
sendPort.send(images);
} catch (e) {
sendPort.send(e.toString());

View file

@ -1,4 +1,5 @@
import "dart:async";
import "package:flutter/material.dart";
import "package:flutter_map/flutter_map.dart";
import "package:flutter_map_marker_cluster/flutter_map_marker_cluster.dart";
@ -43,6 +44,7 @@ class _MapViewState extends State<MapView> {
@override
void initState() {
super.initState();
debugPrint("minZoom ${widget.minZoom} and maxZoom ${widget.maxZoom}");
// widget.controller.move(widget.center, widget.initialZoom);
}
@ -64,10 +66,6 @@ class _MapViewState extends State<MapView> {
minZoom: widget.minZoom,
maxZoom: widget.maxZoom,
enableMultiFingerGestureRace: true,
maxBounds: LatLngBounds(
LatLng(-90, -180),
LatLng(90, 180),
),
zoom: widget.initialZoom,
onPositionChanged: (position, hasGesture) {
if (position.bounds != null) {