From 31306cfb7c1603627a54cd543707eead9bddb4e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Assis=20Neves?= Date: Sat, 24 Dec 2022 10:57:15 -0300 Subject: [PATCH 1/3] Add more map types --- example/test_driver/test_widgets.dart | 2 +- ios/Classes/MapView/FlutterMapView.swift | 3 +++ lib/src/apple_map.dart | 1 + lib/src/ui.dart | 6 ++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/example/test_driver/test_widgets.dart b/example/test_driver/test_widgets.dart index d2c27fd..5656c9f 100644 --- a/example/test_driver/test_widgets.dart +++ b/example/test_driver/test_widgets.dart @@ -8,5 +8,5 @@ import 'package:flutter/widgets.dart'; Future pumpWidget(Widget widget) { runApp(widget); - return WidgetsBinding.instance!.endOfFrame; + return WidgetsBinding.instance.endOfFrame; } diff --git a/ios/Classes/MapView/FlutterMapView.swift b/ios/Classes/MapView/FlutterMapView.swift index 628d533..63028a1 100644 --- a/ios/Classes/MapView/FlutterMapView.swift +++ b/ios/Classes/MapView/FlutterMapView.swift @@ -27,6 +27,9 @@ class FlutterMapView: MKMapView, UIGestureRecognizerDelegate { MKMapType.standard, MKMapType.satellite, MKMapType.hybrid, + MKMapType.satelliteFlyover, + MKMapType.hybridFlyover, + MKMapType.mutedStandard, ] let userTrackingModes: Array = [ diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index 5ca5191..b487c25 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -400,6 +400,7 @@ class _AppleMapOptions { addIfNonNull('myLocationEnabled', myLocationEnabled); addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled); addIfNonNull('padding', _serializePadding(padding)); + print('optionsMap: $optionsMap'); return optionsMap; } diff --git a/lib/src/ui.dart b/lib/src/ui.dart index d650a2a..2b6cd3e 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -14,6 +14,12 @@ enum MapType { /// Hybrid tiles (satellite images with some labels/overlays) hybrid, + + satelliteFlyover, + + hybridFlyover, + + mutedStandard, } enum TrackingMode { From cebd9225affd6d5043b608aa03d3d279a0e66ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Assis=20Neves?= Date: Sat, 24 Dec 2022 11:07:01 -0300 Subject: [PATCH 2/3] add map types comments --- lib/src/apple_map.dart | 1 - lib/src/ui.dart | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/apple_map.dart b/lib/src/apple_map.dart index b487c25..5ca5191 100644 --- a/lib/src/apple_map.dart +++ b/lib/src/apple_map.dart @@ -400,7 +400,6 @@ class _AppleMapOptions { addIfNonNull('myLocationEnabled', myLocationEnabled); addIfNonNull('myLocationButtonEnabled', myLocationButtonEnabled); addIfNonNull('padding', _serializePadding(padding)); - print('optionsMap: $optionsMap'); return optionsMap; } diff --git a/lib/src/ui.dart b/lib/src/ui.dart index 2b6cd3e..57eaaa3 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -15,10 +15,13 @@ enum MapType { /// Hybrid tiles (satellite images with some labels/overlays) hybrid, + // A satellite image of the area with flyover data where available. satelliteFlyover, + // A hybrid satellite image with flyover data where available. hybridFlyover, + // A street map where MapKit emphasizes your data over the underlying map details. mutedStandard, } From 29501b6a79b28e6e13fcec43a876033d1278bf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Assis=20Neves?= Date: Fri, 30 Dec 2022 10:00:56 -0300 Subject: [PATCH 3/3] Allow to take snapshot of different map types --- example/lib/snapshot.dart | 8 ++++++-- ios/Classes/MapView/AppleMapController.swift | 1 + ios/Classes/models/SnapshotOptions.swift | 12 ++++++++++++ lib/src/snapshot_options.dart | 6 +++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/example/lib/snapshot.dart b/example/lib/snapshot.dart index b16f808..670cd31 100644 --- a/example/lib/snapshot.dart +++ b/example/lib/snapshot.dart @@ -11,7 +11,7 @@ import 'package:flutter/material.dart'; import 'package:apple_maps_flutter/apple_maps_flutter.dart'; const CameraPosition _kInitialPosition = - CameraPosition(target: LatLng(-33.852, 151.211), zoom: 11.0); + CameraPosition(target: LatLng(-33.852, 151.211), zoom: 2.0); class SnapshotPage extends ExamplePage { SnapshotPage() @@ -44,12 +44,16 @@ class _SnapshotBodyState extends State<_SnapshotBody> { child: AppleMap( onMapCreated: onMapCreated, initialCameraPosition: _kInitialPosition, + mapType: MapType.hybridFlyover, ), ), TextButton( child: Text('Take a snapshot'), onPressed: () async { - final imageBytes = await _mapController?.takeSnapshot(); + final imageBytes = + await _mapController?.takeSnapshot(SnapshotOptions( + mapType: MapType.hybridFlyover, + )); setState(() { _imageBytes = imageBytes; }); diff --git a/ios/Classes/MapView/AppleMapController.swift b/ios/Classes/MapView/AppleMapController.swift index 300f647..47b497d 100644 --- a/ios/Classes/MapView/AppleMapController.swift +++ b/ios/Classes/MapView/AppleMapController.swift @@ -315,6 +315,7 @@ extension AppleMapController { snapShotOptions.scale = UIScreen.main.scale snapShotOptions.showsBuildings = options.showBuildings snapShotOptions.showsPointsOfInterest = options.showPointsOfInterest + snapShotOptions.mapType = options.mapType // Set MKMapSnapShotOptions to MKMapSnapShotter. snapShot = MKMapSnapshotter(options: snapShotOptions) diff --git a/ios/Classes/models/SnapshotOptions.swift b/ios/Classes/models/SnapshotOptions.swift index faaf071..8356a63 100644 --- a/ios/Classes/models/SnapshotOptions.swift +++ b/ios/Classes/models/SnapshotOptions.swift @@ -6,17 +6,29 @@ // import Foundation +import MapKit class SnapshotOptions { let showBuildings: Bool let showPointsOfInterest: Bool let showAnnotations: Bool let showOverlays: Bool + let mapType : MKMapType init(options: Dictionary) { self.showBuildings = options["showBuildings"] as? Bool ?? true self.showPointsOfInterest = options["showPointsOfInterest"] as? Bool ?? true self.showAnnotations = options["showAnnotations"] as? Bool ?? true self.showOverlays = options["showOverlays"] as? Bool ?? true + self.mapType = mapTypes[options["mapType"] as? Int ?? 0] } + + let mapTypes: Array = [ + MKMapType.standard, + MKMapType.satellite, + MKMapType.hybrid, + MKMapType.satelliteFlyover, + MKMapType.hybridFlyover, + MKMapType.mutedStandard, + ] } diff --git a/lib/src/snapshot_options.dart b/lib/src/snapshot_options.dart index 222c46d..441ad7e 100644 --- a/lib/src/snapshot_options.dart +++ b/lib/src/snapshot_options.dart @@ -6,18 +6,21 @@ class SnapshotOptions { this.showPointsOfInterest = true, this.showAnnotations = true, this.showOverlays = true, + this.mapType = MapType.standard, }); final bool showBuildings; final bool showPointsOfInterest; final bool showAnnotations; final bool showOverlays; + final MapType mapType; - dynamic _toMap() => { + dynamic _toMap() => { 'showBuildings': showBuildings, 'showPointsOfInterest': showPointsOfInterest, 'showAnnotations': showAnnotations, 'showOverlays': showOverlays, + 'mapType': mapType.index, }; @visibleForTesting @@ -30,6 +33,7 @@ class SnapshotOptions { showPointsOfInterest: json['showPointsOfInterest'], showAnnotations: json['showAnnotations'], showOverlays: json['showOverlays'], + mapType: MapType.values[json['mapType']], ); }