76 lines
2.1 KiB
Dart
76 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:google_maps_flutter/google_maps_flutter.dart' as gmaps;
|
|
import '../../core/theme/map_style.dart';
|
|
import 'map_provider_interface.dart';
|
|
|
|
class GoogleMapProvider implements AppMapProvider {
|
|
gmaps.GoogleMapController? _controller;
|
|
|
|
@override
|
|
AppMapType get type => AppMapType.googleMaps;
|
|
|
|
@override
|
|
String get name => 'Google Maps';
|
|
|
|
@override
|
|
Widget buildMapView({
|
|
required BuildContext context,
|
|
required AppLatLng center,
|
|
required double zoom,
|
|
required List<AppMapMarker> markers,
|
|
required List<AppPolyline> polylines,
|
|
required bool isFollowMode,
|
|
required MapConfig config,
|
|
required ValueChanged<AppLatLng>? onPositionChanged,
|
|
required VoidCallback? onUserInteraction,
|
|
}) {
|
|
final target = gmaps.LatLng(center.latitude, center.longitude);
|
|
|
|
if (isFollowMode && _controller != null) {
|
|
_controller!.animateCamera(
|
|
gmaps.CameraUpdate.newLatLngZoom(target, zoom),
|
|
);
|
|
}
|
|
|
|
final gMarkers = markers.map((m) {
|
|
return gmaps.Marker(
|
|
markerId: gmaps.MarkerId(m.id),
|
|
position: gmaps.LatLng(m.position.latitude, m.position.longitude),
|
|
rotation: m.heading,
|
|
onTap: m.onTap,
|
|
);
|
|
}).toSet();
|
|
|
|
final gPolylines = polylines.map((p) {
|
|
return gmaps.Polyline(
|
|
polylineId: gmaps.PolylineId(p.id),
|
|
points: p.points.map((pt) => gmaps.LatLng(pt.latitude, pt.longitude)).toList(),
|
|
color: p.color,
|
|
width: p.width.toInt(),
|
|
);
|
|
}).toSet();
|
|
|
|
return gmaps.GoogleMap(
|
|
initialCameraPosition: gmaps.CameraPosition(
|
|
target: target,
|
|
zoom: zoom,
|
|
),
|
|
markers: gMarkers,
|
|
polylines: gPolylines,
|
|
style: darkMapStyle,
|
|
myLocationEnabled: false,
|
|
zoomControlsEnabled: false,
|
|
compassEnabled: false,
|
|
onMapCreated: (controller) {
|
|
_controller = controller;
|
|
},
|
|
onCameraMoveStarted: () {
|
|
onUserInteraction?.call();
|
|
},
|
|
onCameraMove: (position) {
|
|
onPositionChanged?.call(AppLatLng(position.target.latitude, position.target.longitude));
|
|
},
|
|
);
|
|
}
|
|
}
|