Skip to content

Commit 8b4e07e

Browse files
committed
feat: Annotation zIndex + Map Snapshots
1 parent c248e1a commit 8b4e07e

38 files changed

+1003
-315
lines changed

android/.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>apple_maps_flutter</name>
4+
<comment>Project apple_maps_flutter created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>0</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
28+
</projectDescription>

example/android/.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1601924530843</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
28+
</projectDescription>

example/android/app/.project

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>app</name>
4+
<comment>Project app created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
<filteredResources>
18+
<filter>
19+
<id>1601924530855</id>
20+
<name></name>
21+
<type>30</type>
22+
<matcher>
23+
<id>org.eclipse.core.resources.regexFilterMatcher</id>
24+
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
25+
</matcher>
26+
</filter>
27+
</filteredResources>
28+
</projectDescription>

example/assets/creator.png

284 KB
Loading

example/ios/Flutter/AppFrameworkInfo.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<key>CFBundleVersion</key>
2222
<string>1.0</string>
2323
<key>MinimumOSVersion</key>
24-
<string>8.0</string>
24+
<string>9.0</string>
2525
</dict>
2626
</plist>

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ EXTERNAL SOURCES:
1515

1616
SPEC CHECKSUMS:
1717
apple_maps_flutter: c59725efea39e13e703cde52a1d2b14866ad68a8
18-
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
18+
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
1919

2020
PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c
2121

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 46;
6+
objectVersion = 50;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -156,7 +156,7 @@
156156
97C146E61CF9000F007C117D /* Project object */ = {
157157
isa = PBXProject;
158158
attributes = {
159-
LastUpgradeCheck = 1020;
159+
LastUpgradeCheck = 1300;
160160
ORGANIZATIONNAME = "";
161161
TargetAttributes = {
162162
97C146ED1CF9000F007C117D = {

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1020"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

example/lib/place_annotation.dart

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
3737
static final LatLng center = const LatLng(-33.86711, 151.1947171);
3838

3939
late AppleMapController controller;
40+
Uint8List? _imageBytes;
4041
Map<AnnotationId, Annotation> annotations = <AnnotationId, Annotation>{};
41-
late AnnotationId selectedAnnotation;
42+
late AnnotationId selectedAnnotationId;
4243
int _annotationIdCounter = 1;
4344
BitmapDescriptor? _annotationIcon;
4445
late BitmapDescriptor _iconFromBytes;
@@ -59,10 +60,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
5960
setState(() {
6061
if (annotations.containsKey(tappedAnnotation)) {
6162
final Annotation resetOld =
62-
annotations[selectedAnnotation]!.copyWith();
63-
annotations[selectedAnnotation] = resetOld;
63+
annotations[selectedAnnotationId]!.copyWith();
64+
annotations[selectedAnnotationId] = resetOld;
6465
}
65-
selectedAnnotation = annotationId;
66+
selectedAnnotationId = annotationId;
6667
});
6768
}
6869
}
@@ -91,6 +92,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
9192
center.latitude + sin(_annotationIdCounter * pi / 6.0) / 20.0,
9293
center.longitude + cos(_annotationIdCounter * pi / 6.0) / 20.0,
9394
),
95+
zIndex: annotationCount.toDouble(),
9496
infoWindow: InfoWindow(
9597
title: annotationIdVal,
9698
anchor: Offset(0.5, 0.0),
@@ -108,21 +110,21 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
108110

109111
void _remove() {
110112
setState(() {
111-
if (annotations.containsKey(selectedAnnotation)) {
112-
annotations.remove(selectedAnnotation);
113+
if (annotations.containsKey(selectedAnnotationId)) {
114+
annotations.remove(selectedAnnotationId);
113115
}
114116
});
115117
}
116118

117119
void _changePosition() {
118-
final Annotation annotation = annotations[selectedAnnotation]!;
120+
final Annotation annotation = annotations[selectedAnnotationId]!;
119121
final LatLng current = annotation.position;
120122
final Offset offset = Offset(
121123
center.latitude - current.latitude,
122124
center.longitude - current.longitude,
123125
);
124126
setState(() {
125-
annotations[selectedAnnotation] = annotation.copyWith(
127+
annotations[selectedAnnotationId] = annotation.copyWith(
126128
positionParam: LatLng(
127129
center.latitude + offset.dy,
128130
center.longitude + offset.dx,
@@ -132,20 +134,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
132134
}
133135

134136
Future<void> _toggleDraggable() async {
135-
final Annotation annotation = annotations[selectedAnnotation]!;
137+
final Annotation annotation = annotations[selectedAnnotationId]!;
136138
setState(() {
137-
annotations[selectedAnnotation] = annotation.copyWith(
139+
annotations[selectedAnnotationId] = annotation.copyWith(
138140
draggableParam: !annotation.draggable,
139141
);
140142
});
141143
}
142144

143145
Future<void> _changeInfo() async {
144-
final Annotation annotation = annotations[selectedAnnotation]!;
146+
final Annotation annotation = annotations[selectedAnnotationId]!;
145147
final String newSnippet = annotation.infoWindow.snippet! +
146148
(annotation.infoWindow.snippet!.length % 10 == 0 ? '\n' : '*');
147149
setState(() {
148-
annotations[selectedAnnotation] = annotation.copyWith(
150+
annotations[selectedAnnotationId] = annotation.copyWith(
149151
infoWindowParam: annotation.infoWindow.copyWith(
150152
snippetParam: newSnippet,
151153
),
@@ -154,19 +156,19 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
154156
}
155157

156158
Future<void> _changeAlpha() async {
157-
final Annotation annotation = annotations[selectedAnnotation]!;
159+
final Annotation annotation = annotations[selectedAnnotationId]!;
158160
final double current = annotation.alpha;
159161
setState(() {
160-
annotations[selectedAnnotation] = annotation.copyWith(
162+
annotations[selectedAnnotationId] = annotation.copyWith(
161163
alphaParam: current < 0.1 ? 1.0 : current * 0.75,
162164
);
163165
});
164166
}
165167

166168
Future<void> _toggleVisible() async {
167-
final Annotation annotation = annotations[selectedAnnotation]!;
169+
final Annotation annotation = annotations[selectedAnnotationId]!;
168170
setState(() {
169-
annotations[selectedAnnotation] = annotation.copyWith(
171+
annotations[selectedAnnotationId] = annotation.copyWith(
170172
visibleParam: !annotation.visible,
171173
);
172174
});
@@ -190,17 +192,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
190192
}
191193

192194
Future<void> _showInfoWindow() async {
193-
final Annotation annotation = annotations[selectedAnnotation]!;
195+
final Annotation annotation = annotations[selectedAnnotationId]!;
194196
await this.controller.showMarkerInfoWindow(annotation.annotationId);
195197
}
196198

197199
Future<void> _hideInfoWindow() async {
198-
final Annotation annotation = annotations[selectedAnnotation]!;
200+
final Annotation annotation = annotations[selectedAnnotationId]!;
199201
this.controller.hideMarkerInfoWindow(annotation.annotationId);
200202
}
201203

202204
Future<bool> _isInfoWindowShown() async {
203-
final Annotation annotation = annotations[selectedAnnotation]!;
205+
final Annotation annotation = annotations[selectedAnnotationId]!;
204206
print(
205207
'Is InfowWindow visible: ${await this.controller.isMarkerInfoWindowShown(annotation.annotationId)}');
206208
return (await this
@@ -219,10 +221,20 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
219221
.asUint8List());
220222
}
221223

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+
222234
@override
223235
Widget build(BuildContext context) {
224236
_createAnnotationImageFromAsset(context, _devicePixelRatio);
225-
_getBytesFromAsset('assets/red_square.png', 40);
237+
_getBytesFromAsset('assets/creator.png', 160);
226238
return SafeArea(
227239
child: Column(
228240
children: <Widget>[
@@ -293,6 +305,25 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
293305
child: const Text('hide infoWindow'),
294306
onPressed: _hideInfoWindow,
295307
),
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+
),
296327
],
297328
),
298329
)

example/lib/place_circle.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:typed_data';
6+
57
import 'package:apple_maps_flutter/apple_maps_flutter.dart';
68
// ignore_for_file: public_member_api_docs
79

@@ -33,6 +35,8 @@ class PlaceCircleBodyState extends State<PlaceCircleBody> {
3335
int _circleIdCounter = 1;
3436
CircleId? selectedCircle;
3537

38+
Uint8List? _imageBytes;
39+
3640
// Values when toggling circle color
3741
int fillColorsIndex = 0;
3842
int strokeColorsIndex = 0;
@@ -182,6 +186,22 @@ class PlaceCircleBodyState extends State<PlaceCircleBody> {
182186
child: const Text('change fill color'),
183187
onPressed: (selectedCircle == null) ? null : _changeFillColor,
184188
),
189+
TextButton(
190+
child: Text('Take a snapshot'),
191+
onPressed: () async {
192+
final imageBytes = await this
193+
.controller
194+
.takeSnapshot(SnapshotOptions(showOverlays: true));
195+
setState(() {
196+
_imageBytes = imageBytes;
197+
});
198+
},
199+
),
200+
Container(
201+
decoration: BoxDecoration(color: Colors.blueGrey[50]),
202+
height: 180,
203+
child: _imageBytes != null ? Image.memory(_imageBytes!) : null,
204+
),
185205
],
186206
),
187207
],

0 commit comments

Comments
 (0)