Mark the place the map is pointed at, and make following work
Choosing a town moved the camera and then left the reader to work out which of the settlements now on screen was the one they asked for. A town has no precise position, so the map now marks its centre: a white disc under a coloured dot, drawn as a style layer so the native renderer keeps it pinned through every pan and zoom. The radar frames are inserted below it, because a band of rain must not paint over the one thing that says which town this is. A searched municipality becomes a PointTarget rather than being thrown away as "the whole region". It is marked, the recentre button returns to it, and the chip names it - but it is never persisted, so looking something up no longer costs the user the place their app opens on. That was a real defect: searching went through select(FreeTarget), which wrote null over the stored preference. Following the device was broken outright. MapLibre reports a camera animation the app started exactly as it reports the user grabbing the map, so engaging follow and then animating to the position cancelled the follow it had just started; the resulting FreeTarget then re-framed the whole region. Follow now moves the camera first and switches tracking on second, and FreeTarget no longer moves the camera as a reaction to the state changing - framing the region is an action, so panning away while following keeps the view the user panned to. Verified on the emulator with a fix in Turin: a searched town is marked and saveable, the app reopens on it with the marker in place, following centres on the blue dot, and panning stops the chase without yanking the map away. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/region/geo.dart';
|
||||
import 'saved_place.dart';
|
||||
import 'saved_places.dart';
|
||||
|
||||
@@ -13,6 +14,12 @@ sealed class MapTarget {
|
||||
/// The value persisted as the preferred target, or null if it is not a
|
||||
/// sensible thing to reopen on.
|
||||
String? get storageValue;
|
||||
|
||||
/// The point the map draws a marker on for this target, or null for none.
|
||||
///
|
||||
/// On the interface rather than in the map widget so that adding a target
|
||||
/// without deciding what it looks like on the map stops compiling.
|
||||
GeoPoint? get markedPoint;
|
||||
}
|
||||
|
||||
/// Follow the device: the blue dot stays centred until the user pans away.
|
||||
@@ -22,6 +29,11 @@ class FollowUser extends MapTarget {
|
||||
@override
|
||||
String? get storageValue => 'follow';
|
||||
|
||||
/// None: the blue dot marks the real position, and a pin on top of it would
|
||||
/// say the same thing twice, less precisely.
|
||||
@override
|
||||
GeoPoint? get markedPoint => null;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is FollowUser;
|
||||
|
||||
@@ -38,6 +50,9 @@ class PlaceTarget extends MapTarget {
|
||||
@override
|
||||
String? get storageValue => 'place:${place.id}';
|
||||
|
||||
@override
|
||||
GeoPoint? get markedPoint => place.point;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is PlaceTarget && other.place.id == place.id;
|
||||
@@ -46,6 +61,34 @@ class PlaceTarget extends MapTarget {
|
||||
int get hashCode => place.id.hashCode;
|
||||
}
|
||||
|
||||
/// A point the user has gone to look at without keeping it.
|
||||
///
|
||||
/// What a search produces. The map centres on it and marks it, and the recentre
|
||||
/// button comes back to it, but it is never persisted as what the app reopens
|
||||
/// on: looking something up is not the same commitment as saving a place, and
|
||||
/// the place the user chose to open on should survive a search.
|
||||
class PointTarget extends MapTarget {
|
||||
const PointTarget({required this.point, required this.label});
|
||||
|
||||
final GeoPoint point;
|
||||
|
||||
/// What to call it on screen, and the name it takes if the user saves it.
|
||||
final String label;
|
||||
|
||||
@override
|
||||
String? get storageValue => null;
|
||||
|
||||
@override
|
||||
GeoPoint? get markedPoint => point;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is PointTarget && other.point == point && other.label == label;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(point, label);
|
||||
}
|
||||
|
||||
/// The whole region, and wherever the user has panned to.
|
||||
///
|
||||
/// Also what following degrades to the moment the user drags the map: the
|
||||
@@ -57,6 +100,9 @@ class FreeTarget extends MapTarget {
|
||||
@override
|
||||
String? get storageValue => null;
|
||||
|
||||
@override
|
||||
GeoPoint? get markedPoint => null;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is FreeTarget;
|
||||
|
||||
@@ -157,11 +203,23 @@ class MapTargetController extends Notifier<MapTarget> {
|
||||
}
|
||||
|
||||
/// Selects [target] and remembers it as what to reopen on.
|
||||
///
|
||||
/// Not for [PointTarget]: a searched point is transient, and persisting it
|
||||
/// would clear the place the user chose to open on. Use [previewPoint].
|
||||
Future<void> select(MapTarget target) async {
|
||||
assert(
|
||||
target is! PointTarget,
|
||||
'a searched point is transient - use previewPoint',
|
||||
);
|
||||
state = target;
|
||||
await ref.read(preferredTargetStoreProvider).save(target.storageValue);
|
||||
}
|
||||
|
||||
/// Points the map at [point] without changing what it reopens on.
|
||||
void previewPoint({required GeoPoint point, required String label}) {
|
||||
state = PointTarget(point: point, label: label);
|
||||
}
|
||||
|
||||
/// Drops out of following without changing what the app reopens on.
|
||||
///
|
||||
/// Called when the user drags the map while it is chasing them: they want to
|
||||
|
||||
Reference in New Issue
Block a user