Skip to content

Commit 01e3ea4

Browse files
committed
refactor: Annotations refactored + features added
- Handling of multiline infoWindow snippets added - InfoWindow onTap added - reuse of the annotation views added
1 parent abef771 commit 01e3ea4

File tree

10 files changed

+268
-85
lines changed

10 files changed

+268
-85
lines changed

example/ios/Flutter/.last_build_id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4352f65289e7fa16502be59af107b44a
1+
15bc9e2f5da4e082f1b5a1ced9ac010e

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@
381381
"$(PROJECT_DIR)/Flutter",
382382
);
383383
MARKETING_VERSION = 0.0.4;
384-
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
384+
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
385385
PRODUCT_NAME = "$(TARGET_NAME)";
386386
PROVISIONING_PROFILE_SPECIFIER = "";
387387
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -517,7 +517,7 @@
517517
"$(PROJECT_DIR)/Flutter",
518518
);
519519
MARKETING_VERSION = 0.0.4;
520-
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
520+
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
521521
PRODUCT_NAME = "$(TARGET_NAME)";
522522
PROVISIONING_PROFILE_SPECIFIER = "";
523523
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
@@ -550,7 +550,7 @@
550550
"$(PROJECT_DIR)/Flutter",
551551
);
552552
MARKETING_VERSION = 0.0.4;
553-
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
553+
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
554554
PRODUCT_NAME = "$(TARGET_NAME)";
555555
PROVISIONING_PROFILE_SPECIFIER = "";
556556
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";

example/lib/place_annotation.dart

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
3737
Map<AnnotationId, Annotation> annotations = <AnnotationId, Annotation>{};
3838
AnnotationId selectedAnnotation;
3939
int _annotationIdCounter = 1;
40+
BitmapDescriptor _annotationIcon;
4041

4142
void _onMapCreated(AppleMapController controller) {
4243
this.controller = controller;
@@ -52,8 +53,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
5253
if (tappedAnnotation != null) {
5354
setState(() {
5455
if (annotations.containsKey(selectedAnnotation)) {
55-
final Annotation resetOld = annotations[selectedAnnotation]
56-
.copyWith(iconParam: BitmapDescriptor.defaultAnnotation);
56+
final Annotation resetOld =
57+
annotations[selectedAnnotation].copyWith();
5758
annotations[selectedAnnotation] = resetOld;
5859
}
5960
selectedAnnotation = annotationId;
@@ -76,12 +77,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
7677
annotationId: annotationId,
7778
icon: iconType == 'marker'
7879
? BitmapDescriptor.markerAnnotation
79-
: BitmapDescriptor.defaultAnnotation,
80+
: iconType == 'pin'
81+
? BitmapDescriptor.defaultAnnotation
82+
: _annotationIcon,
8083
position: LatLng(
8184
center.latitude + sin(_annotationIdCounter * pi / 6.0) / 20.0,
8285
center.longitude + cos(_annotationIdCounter * pi / 6.0) / 20.0,
8386
),
84-
infoWindow: InfoWindow(title: annotationIdVal, snippet: '*'),
87+
infoWindow: InfoWindow(
88+
title: annotationIdVal,
89+
snippet: '*',
90+
onTap: () => print('InfowWindow of id: $annotationId tapped.')),
8591
onTap: () {
8692
_onAnnotationTapped(annotationId);
8793
},
@@ -128,7 +134,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
128134

129135
Future<void> _changeInfo() async {
130136
final Annotation annotation = annotations[selectedAnnotation];
131-
final String newSnippet = annotation.infoWindow.snippet + '*';
137+
final String newSnippet = annotation.infoWindow.snippet +
138+
(annotation.infoWindow.snippet.length % 10 == 0 ? '\n' : '*');
132139
setState(() {
133140
annotations[selectedAnnotation] = annotation.copyWith(
134141
infoWindowParam: annotation.infoWindow.copyWith(
@@ -157,8 +164,44 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
157164
});
158165
}
159166

167+
Future<void> _createAnnotationImageFromAsset(BuildContext context) async {
168+
if (_annotationIcon == null) {
169+
final ImageConfiguration imageConfiguration =
170+
createLocalImageConfiguration(context);
171+
BitmapDescriptor.fromAssetImage(
172+
imageConfiguration, 'assets/red_square.png')
173+
.then(_updateBitmap);
174+
}
175+
}
176+
177+
void _updateBitmap(BitmapDescriptor bitmap) {
178+
setState(() {
179+
_annotationIcon = bitmap;
180+
});
181+
}
182+
183+
Future<void> _showInfoWindow() async {
184+
final Annotation annotation = annotations[selectedAnnotation];
185+
await this.controller.showMarkerInfoWindow(annotation.annotationId);
186+
}
187+
188+
Future<void> _hideInfoWindow() async {
189+
final Annotation annotation = annotations[selectedAnnotation];
190+
this.controller.hideMarkerInfoWindow(annotation.annotationId);
191+
}
192+
193+
Future<bool> _isInfoWindowShown() async {
194+
final Annotation annotation = annotations[selectedAnnotation];
195+
print(
196+
'Is InfowWindow visible: ${await this.controller.isMarkerInfoWindowShown(annotation.annotationId)}');
197+
return await this
198+
.controller
199+
.isMarkerInfoWindowShown(annotation.annotationId);
200+
}
201+
160202
@override
161203
Widget build(BuildContext context) {
204+
_createAnnotationImageFromAsset(context);
162205
return Column(
163206
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
164207
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -194,6 +237,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
194237
child: const Text('add markerAnnotation'),
195238
onPressed: () => _add('marker'),
196239
),
240+
FlatButton(
241+
child: const Text('add customAnnotation'),
242+
onPressed: () => _add('customAnnotation'),
243+
),
197244
FlatButton(
198245
child: const Text('remove'),
199246
onPressed: _remove,
@@ -202,6 +249,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
202249
child: const Text('change info'),
203250
onPressed: _changeInfo,
204251
),
252+
FlatButton(
253+
child: const Text('infoWindow is shown?s'),
254+
onPressed: _isInfoWindowShown,
255+
),
205256
],
206257
),
207258
Column(
@@ -222,6 +273,14 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
222273
child: const Text('toggle visible'),
223274
onPressed: _toggleVisible,
224275
),
276+
FlatButton(
277+
child: const Text('show infoWindow'),
278+
onPressed: _showInfoWindow,
279+
),
280+
FlatButton(
281+
child: const Text('hide infoWindow'),
282+
onPressed: _hideInfoWindow,
283+
),
225284
],
226285
),
227286
],

0 commit comments

Comments
 (0)