From 1f192e58f2e7272625f122a7d7ee80e9ac949436 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Thu, 19 Aug 2021 20:41:32 +0900 Subject: [PATCH] map: fixed move to marker --- lib/widgets/common/map/google/map.dart | 12 ++++++------ lib/widgets/common/map/leaflet/map.dart | 7 ++----- lib/widgets/map/map_page.dart | 14 +++++++++----- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/widgets/common/map/google/map.dart b/lib/widgets/common/map/google/map.dart index 56d00a5a9..3e3eb32c9 100644 --- a/lib/widgets/common/map/google/map.dart +++ b/lib/widgets/common/map/google/map.dart @@ -151,16 +151,16 @@ class _EntryGoogleMapState extends State with WidgetsBindingObse animation: _markerBitmapChangeNotifier, builder: (context, child) { final markers = {}; - final onEntryTap = widget.onMarkerTap; geoEntryByMarkerKey.forEach((markerKey, geoEntry) { final bytes = _markerBitmaps[markerKey]; if (bytes != null) { - final latLng = LatLng(geoEntry.latitude!, geoEntry.longitude!); + final point = LatLng(geoEntry.latitude!, geoEntry.longitude!); markers.add(Marker( markerId: MarkerId(geoEntry.markerId!), + consumeTapEvents: true, icon: BitmapDescriptor.fromBytes(bytes), - position: latLng, - onTap: onEntryTap != null ? () => onEntryTap(geoEntry) : null, + position: point, + onTap: () => widget.onMarkerTap?.call(geoEntry), )); } }); @@ -241,11 +241,11 @@ class _EntryGoogleMapState extends State with WidgetsBindingObse await controller.animateCamera(CameraUpdate.zoomBy(amount)); } - Future _moveTo(LatLng latLng) async { + Future _moveTo(LatLng point) async { final controller = _googleMapController; if (controller == null) return; - await controller.animateCamera(CameraUpdate.newLatLng(latLng)); + await controller.animateCamera(CameraUpdate.newLatLng(point)); } // `LatLng` used by `google_maps_flutter` is not the one from `latlong2` package diff --git a/lib/widgets/common/map/leaflet/map.dart b/lib/widgets/common/map/leaflet/map.dart index 6241e4ab0..8384f86f8 100644 --- a/lib/widgets/common/map/leaflet/map.dart +++ b/lib/widgets/common/map/leaflet/map.dart @@ -60,7 +60,7 @@ class _EntryLeafletMapState extends State with TickerProviderSt bool get interactive => widget.interactive; // duration should match the uncustomizable Google Maps duration - static const _cameraAnimationDuration = Duration(milliseconds: 400); + static const _cameraAnimationDuration = Duration(milliseconds: 600); @override void initState() { @@ -123,10 +123,7 @@ class _EntryLeafletMapState extends State with TickerProviderSt return Marker( point: latLng, builder: (context) => GestureDetector( - onTap: () { - widget.onMarkerTap?.call(geoEntry); - _moveTo(latLng); - }, + onTap: () => widget.onMarkerTap?.call(geoEntry), child: widget.markerBuilder(markerKey), ), width: markerSize.width, diff --git a/lib/widgets/map/map_page.dart b/lib/widgets/map/map_page.dart index c94a9a868..61776eb2d 100644 --- a/lib/widgets/map/map_page.dart +++ b/lib/widgets/map/map_page.dart @@ -77,7 +77,12 @@ class _MapPageState extends State { onMarkerTap: (markerEntries) { if (markerEntries.isEmpty) return; final entry = markerEntries.first; - _selectedIndexNotifier.value = entries.indexOf(entry); + final index = entries.indexOf(entry); + if (_selectedIndexNotifier.value != index) { + _selectedIndexNotifier.value = index; + } else { + _moveToEntry(entry); + } }, ), ), @@ -100,8 +105,7 @@ class _MapPageState extends State { ); } - void _onThumbnailIndexChange() { - final position = widget.entries[_selectedIndexNotifier.value].latLng!; - _debouncer(() => _mapController.moveTo(position)); - } + void _onThumbnailIndexChange() => _moveToEntry(widget.entries[_selectedIndexNotifier.value]); + + void _moveToEntry(AvesEntry entry) => _debouncer(() => _mapController.moveTo(entry.latLng!)); }