use more fitting floating action button, cleanup
All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m24s
All checks were successful
Build and release APK / Build APK (pull_request) Successful in 5m24s
This commit is contained in:
85
frontend/lib/modules/current_trip_map.dart
Normal file
85
frontend/lib/modules/current_trip_map.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
import 'dart:collection';
|
||||
|
||||
import 'package:anyway/constants.dart';
|
||||
import 'package:anyway/modules/themed_marker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:anyway/structs/landmark.dart';
|
||||
import 'package:anyway/structs/trip.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:widget_to_marker/widget_to_marker.dart';
|
||||
|
||||
|
||||
class MapWidget extends StatefulWidget {
|
||||
|
||||
final Trip? trip;
|
||||
|
||||
MapWidget({
|
||||
this.trip
|
||||
});
|
||||
|
||||
@override
|
||||
State<MapWidget> createState() => _MapWidgetState();
|
||||
}
|
||||
|
||||
class _MapWidgetState extends State<MapWidget> {
|
||||
late GoogleMapController mapController;
|
||||
|
||||
CameraPosition _cameraPosition = CameraPosition(
|
||||
target: LatLng(48.8566, 2.3522),
|
||||
zoom: 11.0,
|
||||
);
|
||||
Set<Marker> mapMarkers = <Marker>{};
|
||||
|
||||
|
||||
void _onMapCreated(GoogleMapController controller) async {
|
||||
mapController = controller;
|
||||
List<double>? newLocation = widget.trip?.landmarks.firstOrNull?.location;
|
||||
if (newLocation != null) {
|
||||
CameraUpdate update = CameraUpdate.newLatLng(LatLng(newLocation[0], newLocation[1]));
|
||||
controller.moveCamera(update);
|
||||
}
|
||||
setMapMarkers();
|
||||
}
|
||||
|
||||
void _onCameraIdle() {
|
||||
// print(mapController.getLatLng(ScreenCoordinate(x: 0, y: 0)));
|
||||
}
|
||||
|
||||
|
||||
void setMapMarkers() async {
|
||||
List<Landmark> landmarks = widget.trip?.landmarks.toList() ?? [];
|
||||
Set<Marker> newMarkers = <Marker>{};
|
||||
for (int i = 0; i < landmarks.length; i++) {
|
||||
Landmark landmark = landmarks[i];
|
||||
List<double> location = landmark.location;
|
||||
Marker marker = Marker(
|
||||
markerId: MarkerId(landmark.uuid),
|
||||
position: LatLng(location[0], location[1]),
|
||||
icon: await ThemedMarker(landmark: landmark, position: i).toBitmapDescriptor(
|
||||
logicalSize: const Size(150, 150),
|
||||
imageSize: const Size(150, 150)
|
||||
),
|
||||
);
|
||||
newMarkers.add(marker);
|
||||
}
|
||||
setState(() {
|
||||
mapMarkers = newMarkers;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
widget.trip?.addListener(setMapMarkers);
|
||||
return GoogleMap(
|
||||
onMapCreated: _onMapCreated,
|
||||
initialCameraPosition: _cameraPosition,
|
||||
onCameraIdle: _onCameraIdle,
|
||||
// onLongPress: ,
|
||||
markers: mapMarkers,
|
||||
cloudMapId: MAP_ID,
|
||||
mapToolbarEnabled: false,
|
||||
zoomControlsEnabled: false,
|
||||
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user