-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathannotations_mixed_page.dart
105 lines (99 loc) · 3.24 KB
/
annotations_mixed_page.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:maplibre/maplibre.dart';
@immutable
class AnnotationsMixedPage extends StatefulWidget {
const AnnotationsMixedPage({super.key});
static const location = '/annotations/mixed';
@override
State<AnnotationsMixedPage> createState() => _AnnotationsMixedPageState();
}
class _AnnotationsMixedPageState extends State<AnnotationsMixedPage> {
final _random = Random.secure();
final _circlePoints = <Point>[
Point(coordinates: Position(9.17, 47.68)),
Point(coordinates: Position(9.17, 48)),
Point(coordinates: Position(9, 48)),
Point(coordinates: Position(9.5, 48)),
];
Color _circleColor = Colors.orange.withOpacity(0.5);
PolylineAnnotationLayer? _polylineLayer;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Mixed Annotations')),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(8),
child: Wrap(
spacing: 8,
alignment: WrapAlignment.center,
children: [
OutlinedButton(
onPressed: () {
setState(() {
_circleColor =
Color(_random.nextInt(0xFFFFFF) + 0x7F000000);
});
},
child: const Text(
'Change color',
textAlign: TextAlign.center,
),
),
OutlinedButton(
onPressed: () {
setState(() {
if (_polylineLayer == null) {
_polylineLayer = PolylineAnnotationLayer(
polylines: [
LineString(
coordinates: [
Position(9.17, 47.68),
Position(9.5, 48),
Position(9, 48),
],
),
],
);
} else {
_polylineLayer = null;
}
});
},
child: const Text(
'Toggle 2nd layer',
textAlign: TextAlign.center,
),
),
],
),
),
Expanded(
child: MapLibreMap(
options: MapOptions(zoom: 7, center: Position(9.17, 47.68)),
onEvent: (event) {
if (event case MapEventClick()) {
setState(() {
_circlePoints.add(Point(coordinates: event.point));
});
}
},
layers: [
CircleAnnotationLayer(
points: _circlePoints,
color: _circleColor,
radius: 20,
strokeColor: Colors.red,
strokeWidth: 2,
),
if (_polylineLayer case final AnnotationLayer layer) layer,
],
),
),
],
),
);
}
}