Skip to content

Commit

Permalink
refactor: Annotations refactored + features added
Browse files Browse the repository at this point in the history
 - Handling of multiline infoWindow snippets added
 - InfoWindow onTap added
 - reuse of the annotation views added
  • Loading branch information
LuisThein committed Oct 18, 2020
1 parent abef771 commit 01e3ea4
Show file tree
Hide file tree
Showing 10 changed files with 268 additions and 85 deletions.
2 changes: 1 addition & 1 deletion example/ios/Flutter/.last_build_id
@@ -1 +1 @@
4352f65289e7fa16502be59af107b44a
15bc9e2f5da4e082f1b5a1ced9ac010e
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Expand Up @@ -381,7 +381,7 @@
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -517,7 +517,7 @@
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down Expand Up @@ -550,7 +550,7 @@
"$(PROJECT_DIR)/Flutter",
);
MARKETING_VERSION = 0.0.4;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample3;
PRODUCT_BUNDLE_IDENTIFIER = de.luisthein.appleMapsFlutterExample4;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
Expand Down
69 changes: 64 additions & 5 deletions example/lib/place_annotation.dart
Expand Up @@ -37,6 +37,7 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
Map<AnnotationId, Annotation> annotations = <AnnotationId, Annotation>{};
AnnotationId selectedAnnotation;
int _annotationIdCounter = 1;
BitmapDescriptor _annotationIcon;

void _onMapCreated(AppleMapController controller) {
this.controller = controller;
Expand All @@ -52,8 +53,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
if (tappedAnnotation != null) {
setState(() {
if (annotations.containsKey(selectedAnnotation)) {
final Annotation resetOld = annotations[selectedAnnotation]
.copyWith(iconParam: BitmapDescriptor.defaultAnnotation);
final Annotation resetOld =
annotations[selectedAnnotation].copyWith();
annotations[selectedAnnotation] = resetOld;
}
selectedAnnotation = annotationId;
Expand All @@ -76,12 +77,17 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
annotationId: annotationId,
icon: iconType == 'marker'
? BitmapDescriptor.markerAnnotation
: BitmapDescriptor.defaultAnnotation,
: iconType == 'pin'
? BitmapDescriptor.defaultAnnotation
: _annotationIcon,
position: LatLng(
center.latitude + sin(_annotationIdCounter * pi / 6.0) / 20.0,
center.longitude + cos(_annotationIdCounter * pi / 6.0) / 20.0,
),
infoWindow: InfoWindow(title: annotationIdVal, snippet: '*'),
infoWindow: InfoWindow(
title: annotationIdVal,
snippet: '*',
onTap: () => print('InfowWindow of id: $annotationId tapped.')),
onTap: () {
_onAnnotationTapped(annotationId);
},
Expand Down Expand Up @@ -128,7 +134,8 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {

Future<void> _changeInfo() async {
final Annotation annotation = annotations[selectedAnnotation];
final String newSnippet = annotation.infoWindow.snippet + '*';
final String newSnippet = annotation.infoWindow.snippet +
(annotation.infoWindow.snippet.length % 10 == 0 ? '\n' : '*');
setState(() {
annotations[selectedAnnotation] = annotation.copyWith(
infoWindowParam: annotation.infoWindow.copyWith(
Expand Down Expand Up @@ -157,8 +164,44 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
});
}

Future<void> _createAnnotationImageFromAsset(BuildContext context) async {
if (_annotationIcon == null) {
final ImageConfiguration imageConfiguration =
createLocalImageConfiguration(context);
BitmapDescriptor.fromAssetImage(
imageConfiguration, 'assets/red_square.png')
.then(_updateBitmap);
}
}

void _updateBitmap(BitmapDescriptor bitmap) {
setState(() {
_annotationIcon = bitmap;
});
}

Future<void> _showInfoWindow() async {
final Annotation annotation = annotations[selectedAnnotation];
await this.controller.showMarkerInfoWindow(annotation.annotationId);
}

Future<void> _hideInfoWindow() async {
final Annotation annotation = annotations[selectedAnnotation];
this.controller.hideMarkerInfoWindow(annotation.annotationId);
}

Future<bool> _isInfoWindowShown() async {
final Annotation annotation = annotations[selectedAnnotation];
print(
'Is InfowWindow visible: ${await this.controller.isMarkerInfoWindowShown(annotation.annotationId)}');
return await this
.controller
.isMarkerInfoWindowShown(annotation.annotationId);
}

@override
Widget build(BuildContext context) {
_createAnnotationImageFromAsset(context);
return Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand Down Expand Up @@ -194,6 +237,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
child: const Text('add markerAnnotation'),
onPressed: () => _add('marker'),
),
FlatButton(
child: const Text('add customAnnotation'),
onPressed: () => _add('customAnnotation'),
),
FlatButton(
child: const Text('remove'),
onPressed: _remove,
Expand All @@ -202,6 +249,10 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
child: const Text('change info'),
onPressed: _changeInfo,
),
FlatButton(
child: const Text('infoWindow is shown?s'),
onPressed: _isInfoWindowShown,
),
],
),
Column(
Expand All @@ -222,6 +273,14 @@ class PlaceAnnotationBodyState extends State<PlaceAnnotationBody> {
child: const Text('toggle visible'),
onPressed: _toggleVisible,
),
FlatButton(
child: const Text('show infoWindow'),
onPressed: _showInfoWindow,
),
FlatButton(
child: const Text('hide infoWindow'),
onPressed: _hideInfoWindow,
),
],
),
],
Expand Down

0 comments on commit 01e3ea4

Please sign in to comment.