Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCanape committed Feb 12, 2024
1 parent 0388b6b commit e206e97
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class CurrentLocationMap extends HookConsumerWidget {
child: LocationMap(
points: points,
markers: markers,
currentPosition: LatLng(currentLatitude, currentLongitude),
mapController: provider.mapController ?? MapController(),
));
}, loading: () {
Expand Down
57 changes: 33 additions & 24 deletions lib/presentation/common/location/widgets/location_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,55 @@ import 'package:latlong2/latlong.dart';

import '../../core/utils/color_utils.dart';
import '../../core/utils/map_utils.dart';
import '../../core/utils/ui_utils.dart';

/// Widget that displays a map with markers and polylines representing locations.
class LocationMap extends HookConsumerWidget {
final List<LatLng> points;
final List<Marker> markers;
final MapController? mapController;
final LatLng? currentPosition;

const LocationMap(
{super.key,
required this.points,
required this.markers,
required this.mapController});
required this.mapController,
this.currentPosition});

@override
Widget build(BuildContext context, WidgetRef ref) {
final center = MapUtils.getCenterOfMap(points);
final zoomLevel = MapUtils.getZoomLevel(points, center);

return SizedBox(
height: 500,
child: FlutterMap(
key: ValueKey(MediaQuery.of(context).orientation),
mapController: mapController,
options: MapOptions(
initialCenter: points.isNotEmpty ? center : const LatLng(0, 0),
initialZoom: zoomLevel,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
PolylineLayer(
polylines: [
Polyline(
points: points, strokeWidth: 4, color: ColorUtils.blueGrey),
],
),
MarkerLayer(markers: markers),
],
),
);
return points.isNotEmpty || currentPosition != null
? SizedBox(
height: 500,
child: FlutterMap(
key: ValueKey(MediaQuery.of(context).orientation),
mapController: mapController,
options: MapOptions(
initialCenter: points.isNotEmpty
? center
: currentPosition ?? const LatLng(0, 0),
initialZoom: zoomLevel,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
PolylineLayer(
polylines: [
Polyline(
points: points,
strokeWidth: 4,
color: ColorUtils.blueGrey),
],
),
MarkerLayer(markers: markers),
],
),
)
: Center(child: UIUtils.loader);
}
}

0 comments on commit e206e97

Please sign in to comment.