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:
@@ -24,6 +24,7 @@ import '../timeline/radar_timeline.dart';
|
||||
import '../timeline/timeline_bar.dart';
|
||||
import 'map_overlay_controls.dart';
|
||||
import 'map_style.dart';
|
||||
import 'place_marker.dart';
|
||||
import 'radar_overlay.dart';
|
||||
|
||||
/// The radar map: base map, animated precipitation overlay, timeline.
|
||||
@@ -101,6 +102,7 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
|
||||
MapLibreMapController? _controller;
|
||||
RadarOverlay? _overlay;
|
||||
PlaceMarker? _marker;
|
||||
AppLifecycleListener? _lifecycle;
|
||||
|
||||
/// Whether the map may draw the blue dot.
|
||||
@@ -126,6 +128,7 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
void dispose() {
|
||||
_lifecycle?.dispose();
|
||||
unawaited(_overlay?.detach());
|
||||
unawaited(_marker?.detach());
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -166,16 +169,26 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Puts the camera where the current target says it should be.
|
||||
/// Puts the camera and the marker where the current target says they belong.
|
||||
///
|
||||
/// Deliberately leaves the camera alone for [FreeTarget]. That state is also
|
||||
/// what following degrades to the instant the user drags the map, and
|
||||
/// re-framing the whole region there would throw away the very pan they just
|
||||
/// made. Framing the region is an action - [_selectRegion], the opening view,
|
||||
/// the recentre button - never a reaction to the state changing.
|
||||
Future<void> _applyTarget(MapTarget target) async {
|
||||
await _marker?.show(target.markedPoint);
|
||||
|
||||
switch (target) {
|
||||
case FollowUser():
|
||||
// The native tracking mode does the following; nothing to animate.
|
||||
break;
|
||||
case PlaceTarget(:final place):
|
||||
await _centreOn(place.point, zoom: placeZoom);
|
||||
case PointTarget(:final point):
|
||||
await _centreOn(point, zoom: placeZoom);
|
||||
case FreeTarget():
|
||||
await _frameRegion();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,8 +216,21 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
}
|
||||
|
||||
setState(() => _locationEnabled = true);
|
||||
|
||||
// Move the camera first, switch tracking on second. MapLibre reports a
|
||||
// camera animation the app started exactly the way it reports the user
|
||||
// grabbing the map - as tracking dismissed - so engaging follow and then
|
||||
// animating to the position drops straight back out of following. Doing it
|
||||
// in this order leaves nothing to dismiss.
|
||||
await _centreOn(point, zoom: placeZoom);
|
||||
if (!mounted) return;
|
||||
await ref.read(mapTargetProvider.notifier).select(const FollowUser());
|
||||
if (mounted) await _centreOn(point, zoom: placeZoom);
|
||||
}
|
||||
|
||||
/// Shows the whole region, as a choice rather than as a side effect.
|
||||
Future<void> _selectRegion() async {
|
||||
await ref.read(mapTargetProvider.notifier).select(const FreeTarget());
|
||||
if (mounted) await _frameRegion();
|
||||
}
|
||||
|
||||
Future<void> _openSearch() async {
|
||||
@@ -214,10 +240,14 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
if (result == null || !mounted) return;
|
||||
|
||||
// A searched point is somewhere the user is looking, not somewhere they
|
||||
// have committed to, so it moves the camera without becoming the target.
|
||||
// Saving it is one tap away if they want it to stick.
|
||||
await ref.read(mapTargetProvider.notifier).select(const FreeTarget());
|
||||
await _centreOn(result.point, zoom: placeZoom);
|
||||
// have committed to: it gets marked and centred, but what the app reopens
|
||||
// on is left alone. Saving it is one tap away if they want it to stick.
|
||||
ref
|
||||
.read(mapTargetProvider.notifier)
|
||||
.previewPoint(point: result.point, label: result.label);
|
||||
// Applied here rather than left to the listener, which does not fire when
|
||||
// the same point is searched twice running.
|
||||
await _applyTarget(ref.read(mapTargetProvider));
|
||||
if (!mounted) return;
|
||||
|
||||
final l10n = AppLocalizations.of(context);
|
||||
@@ -282,14 +312,33 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
|
||||
Future<void> _onMapCreated(MapLibreMapController controller) async {
|
||||
_controller = controller;
|
||||
await _applyTarget(ref.read(mapTargetProvider));
|
||||
|
||||
final target = ref.read(mapTargetProvider);
|
||||
await _applyTarget(target);
|
||||
// The opening view when there is no place to open on. Nothing else frames
|
||||
// the region now that a state change no longer does.
|
||||
if (target is FreeTarget) await _frameRegion();
|
||||
}
|
||||
|
||||
Future<void> _onStyleLoaded() async {
|
||||
final controller = _controller;
|
||||
if (controller == null) return;
|
||||
|
||||
_overlay = RadarOverlay(map: controller, bounds: widget.region.bounds);
|
||||
// The marker's layers are created first and the radar is inserted below
|
||||
// them, so the frames can never cover the marker however late they arrive.
|
||||
final marker = PlaceMarker(
|
||||
map: controller,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
);
|
||||
_marker = marker;
|
||||
await marker.attach();
|
||||
await marker.show(ref.read(mapTargetProvider).markedPoint);
|
||||
|
||||
_overlay = RadarOverlay(
|
||||
map: controller,
|
||||
bounds: widget.region.bounds,
|
||||
belowLayerId: PlaceMarker.haloLayerId,
|
||||
);
|
||||
await _showFrame(ref.read(radarTimelineProvider).currentFrame);
|
||||
}
|
||||
|
||||
@@ -381,6 +430,7 @@ class _RegionMapState extends ConsumerState<_RegionMap> {
|
||||
child: TargetSelector(
|
||||
region: widget.region,
|
||||
onFollowRequested: () => unawaited(_requestFollow()),
|
||||
onRegionRequested: () => unawaited(_selectRegion()),
|
||||
onSearch: () => unawaited(_openSearch()),
|
||||
onManagePlaces: () => unawaited(_openPlaces()),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user