-
Notifications
You must be signed in to change notification settings - Fork 8
/
add.dart
46 lines (41 loc) · 1.11 KB
/
add.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:universe/universe.dart';
class AddMarkerMap extends StatefulWidget {
const AddMarkerMap({super.key});
@override
State<AddMarkerMap> createState() => _AddMarkerMapState();
}
class _AddMarkerMapState extends State<AddMarkerMap> {
final _mapKey = UniqueKey();
List<Marker> markers = [];
@override
Widget build(BuildContext context) {
return U.OpenStreetMap(
key: _mapKey,
center: [51.555158, -0.108343],
zoom: 15,
showLocator: true,
markers: U.MarkerLayer(
markers,
// long press the marker to remove it
onLongPress: (position, latlng) {
if (latlng is LatLng && mounted) {
setState(() {
markers.removeWhere((marker) => marker.latlng == latlng);
});
}
},
),
// tap to add marker
onTap: (latlng) {
if (mounted) {
setState(() {
Marker marker = U.Marker(latlng, data: latlng);
markers.add(marker);
});
}
},
);
}
}