map: fixed move to marker

This commit is contained in:
Thibault Deckers 2021-08-19 20:41:32 +09:00
parent 2d1c350772
commit 1f192e58f2
3 changed files with 17 additions and 16 deletions

View file

@ -151,16 +151,16 @@ class _EntryGoogleMapState extends State<EntryGoogleMap> with WidgetsBindingObse
animation: _markerBitmapChangeNotifier,
builder: (context, child) {
final markers = <Marker>{};
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<EntryGoogleMap> with WidgetsBindingObse
await controller.animateCamera(CameraUpdate.zoomBy(amount));
}
Future<void> _moveTo(LatLng latLng) async {
Future<void> _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

View file

@ -60,7 +60,7 @@ class _EntryLeafletMapState extends State<EntryLeafletMap> 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<EntryLeafletMap> 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,

View file

@ -77,7 +77,12 @@ class _MapPageState extends State<MapPage> {
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<MapPage> {
);
}
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!));
}