@@ -37,8 +37,9 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
37
37
static final LatLng center = const LatLng (- 33.86711 , 151.1947171 );
38
38
39
39
late AppleMapController controller;
40
+ Uint8List ? _imageBytes;
40
41
Map <AnnotationId , Annotation > annotations = < AnnotationId , Annotation > {};
41
- late AnnotationId selectedAnnotation ;
42
+ late AnnotationId selectedAnnotationId ;
42
43
int _annotationIdCounter = 1 ;
43
44
BitmapDescriptor ? _annotationIcon;
44
45
late BitmapDescriptor _iconFromBytes;
@@ -59,10 +60,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
59
60
setState (() {
60
61
if (annotations.containsKey (tappedAnnotation)) {
61
62
final Annotation resetOld =
62
- annotations[selectedAnnotation ]! .copyWith ();
63
- annotations[selectedAnnotation ] = resetOld;
63
+ annotations[selectedAnnotationId ]! .copyWith ();
64
+ annotations[selectedAnnotationId ] = resetOld;
64
65
}
65
- selectedAnnotation = annotationId;
66
+ selectedAnnotationId = annotationId;
66
67
});
67
68
}
68
69
}
@@ -91,6 +92,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
91
92
center.latitude + sin (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
92
93
center.longitude + cos (_annotationIdCounter * pi / 6.0 ) / 20.0 ,
93
94
),
95
+ zIndex: annotationCount.toDouble (),
94
96
infoWindow: InfoWindow (
95
97
title: annotationIdVal,
96
98
anchor: Offset (0.5 , 0.0 ),
@@ -108,21 +110,21 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
108
110
109
111
void _remove () {
110
112
setState (() {
111
- if (annotations.containsKey (selectedAnnotation )) {
112
- annotations.remove (selectedAnnotation );
113
+ if (annotations.containsKey (selectedAnnotationId )) {
114
+ annotations.remove (selectedAnnotationId );
113
115
}
114
116
});
115
117
}
116
118
117
119
void _changePosition () {
118
- final Annotation annotation = annotations[selectedAnnotation ]! ;
120
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
119
121
final LatLng current = annotation.position;
120
122
final Offset offset = Offset (
121
123
center.latitude - current.latitude,
122
124
center.longitude - current.longitude,
123
125
);
124
126
setState (() {
125
- annotations[selectedAnnotation ] = annotation.copyWith (
127
+ annotations[selectedAnnotationId ] = annotation.copyWith (
126
128
positionParam: LatLng (
127
129
center.latitude + offset.dy,
128
130
center.longitude + offset.dx,
@@ -132,20 +134,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
132
134
}
133
135
134
136
Future <void > _toggleDraggable () async {
135
- final Annotation annotation = annotations[selectedAnnotation ]! ;
137
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
136
138
setState (() {
137
- annotations[selectedAnnotation ] = annotation.copyWith (
139
+ annotations[selectedAnnotationId ] = annotation.copyWith (
138
140
draggableParam: ! annotation.draggable,
139
141
);
140
142
});
141
143
}
142
144
143
145
Future <void > _changeInfo () async {
144
- final Annotation annotation = annotations[selectedAnnotation ]! ;
146
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
145
147
final String newSnippet = annotation.infoWindow.snippet! +
146
148
(annotation.infoWindow.snippet! .length % 10 == 0 ? '\n ' : '*' );
147
149
setState (() {
148
- annotations[selectedAnnotation ] = annotation.copyWith (
150
+ annotations[selectedAnnotationId ] = annotation.copyWith (
149
151
infoWindowParam: annotation.infoWindow.copyWith (
150
152
snippetParam: newSnippet,
151
153
),
@@ -154,19 +156,19 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
154
156
}
155
157
156
158
Future <void > _changeAlpha () async {
157
- final Annotation annotation = annotations[selectedAnnotation ]! ;
159
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
158
160
final double current = annotation.alpha;
159
161
setState (() {
160
- annotations[selectedAnnotation ] = annotation.copyWith (
162
+ annotations[selectedAnnotationId ] = annotation.copyWith (
161
163
alphaParam: current < 0.1 ? 1.0 : current * 0.75 ,
162
164
);
163
165
});
164
166
}
165
167
166
168
Future <void > _toggleVisible () async {
167
- final Annotation annotation = annotations[selectedAnnotation ]! ;
169
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
168
170
setState (() {
169
- annotations[selectedAnnotation ] = annotation.copyWith (
171
+ annotations[selectedAnnotationId ] = annotation.copyWith (
170
172
visibleParam: ! annotation.visible,
171
173
);
172
174
});
@@ -190,17 +192,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
190
192
}
191
193
192
194
Future <void > _showInfoWindow () async {
193
- final Annotation annotation = annotations[selectedAnnotation ]! ;
195
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
194
196
await this .controller.showMarkerInfoWindow (annotation.annotationId);
195
197
}
196
198
197
199
Future <void > _hideInfoWindow () async {
198
- final Annotation annotation = annotations[selectedAnnotation ]! ;
200
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
199
201
this .controller.hideMarkerInfoWindow (annotation.annotationId);
200
202
}
201
203
202
204
Future <bool > _isInfoWindowShown () async {
203
- final Annotation annotation = annotations[selectedAnnotation ]! ;
205
+ final Annotation annotation = annotations[selectedAnnotationId ]! ;
204
206
print (
205
207
'Is InfowWindow visible: ${await this .controller .isMarkerInfoWindowShown (annotation .annotationId )}' );
206
208
return (await this
@@ -219,10 +221,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
219
221
.asUint8List ());
220
222
}
221
223
224
+ Future <void > _changeZIndex (AnnotationId annotationId) async {
225
+ final Annotation annotation = annotations[annotationId]! ;
226
+ final double current = annotation.zIndex;
227
+ setState (() {
228
+ annotations[annotationId] = annotation.copyWith (
229
+ zIndexParam: current >= 12.0 ? 0.0 : current + 1.0 ,
230
+ );
231
+ });
232
+ }
233
+
222
234
@override
223
235
Widget build (BuildContext context) {
224
236
_createAnnotationImageFromAsset (context, _devicePixelRatio);
225
- _getBytesFromAsset ('assets/red_square .png' , 40 );
237
+ _getBytesFromAsset ('assets/creator .png' , 160 );
226
238
return SafeArea (
227
239
child: Column (
228
240
children: < Widget > [
@@ -293,6 +305,25 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
293
305
child: const Text ('hide infoWindow' ),
294
306
onPressed: _hideInfoWindow,
295
307
),
308
+ TextButton (
309
+ child: const Text ('change zIndex' ),
310
+ onPressed: () => _changeZIndex (selectedAnnotationId),
311
+ ),
312
+ TextButton (
313
+ child: Text ('Take a snapshot' ),
314
+ onPressed: () async {
315
+ final imageBytes = await this .controller.takeSnapshot ();
316
+ setState (() {
317
+ _imageBytes = imageBytes;
318
+ });
319
+ },
320
+ ),
321
+ Container (
322
+ decoration: BoxDecoration (color: Colors .blueGrey[50 ]),
323
+ height: 180 ,
324
+ child:
325
+ _imageBytes != null ? Image .memory (_imageBytes! ) : null ,
326
+ ),
296
327
],
297
328
),
298
329
)
0 commit comments