5
5
#import " GoogleMapController.h"
6
6
#import " FLTGoogleMapJSONConversions.h"
7
7
#import " FLTGoogleMapTileOverlayController.h"
8
+ #import " messages.g.h"
8
9
9
10
#pragma mark - Conversion of JSON-like values sent via platform channels. Forward declarations.
10
11
@@ -56,6 +57,33 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
56
57
57
58
@end
58
59
60
+ #pragma mark -
61
+
62
+ // / Implementation of the Pigeon maps inspector API.
63
+ // /
64
+ // / This is a separate object from the maps controller because the Pigeon API registration keeps a
65
+ // / strong reference to the implementor, but as the FlutterPlatformView, the lifetime of the
66
+ // / FLTGoogleMapController instance is what needs to trigger Pigeon unregistration, so can't be
67
+ // / the target of the registration.
68
+ @interface FGMMapInspector : NSObject <FGMMapsInspectorApi>
69
+ - (instancetype )initWithMapController : (nonnull FLTGoogleMapController *)controller
70
+ messenger : (NSObject <FlutterBinaryMessenger> *)messenger
71
+ pigeonSuffix : (NSString *)suffix ;
72
+ @end
73
+
74
+ // / Private declarations.
75
+ // This is separate in case the above is made public in the future (e.g., for unit testing).
76
+ @interface FGMMapInspector ()
77
+ // / The map controller this inspector corresponds to.
78
+ @property (nonatomic , weak ) FLTGoogleMapController *controller;
79
+ // / The messenger this instance was registered with by Pigeon.
80
+ @property (nonatomic , copy ) NSObject <FlutterBinaryMessenger> *messenger;
81
+ // / The suffix this instance was registered under with Pigeon.
82
+ @property (nonatomic , copy ) NSString *pigeonSuffix;
83
+ @end
84
+
85
+ #pragma mark -
86
+
59
87
@interface FLTGoogleMapController ()
60
88
61
89
@property (nonatomic , strong ) GMSMapView *mapView;
@@ -72,6 +100,8 @@ @interface FLTGoogleMapController ()
72
100
// creation time and there's no mechanism to return non-fatal error details during platform view
73
101
// initialization.
74
102
@property (nonatomic , copy ) NSString *styleError;
103
+ // The inspector API implementation, separate to avoid lifetime extension.
104
+ @property (nonatomic , strong ) FGMMapInspector *inspector;
75
105
76
106
@end
77
107
@@ -114,9 +144,7 @@ - (instancetype)initWithMapView:(GMSMapView *_Nonnull)mapView
114
144
binaryMessenger: registrar.messenger];
115
145
__weak __typeof__ (self) weakSelf = self;
116
146
[_channel setMethodCallHandler: ^(FlutterMethodCall *call, FlutterResult result) {
117
- if (weakSelf) {
118
- [weakSelf onMethodCall: call result: result];
119
- }
147
+ [weakSelf onMethodCall: call result: result];
120
148
}];
121
149
_mapView.delegate = weakSelf;
122
150
_mapView.paddingAdjustmentBehavior = kGMSMapViewPaddingAdjustmentBehaviorNever ;
@@ -158,10 +186,22 @@ - (instancetype)initWithMapView:(GMSMapView *_Nonnull)mapView
158
186
}
159
187
160
188
[_mapView addObserver: self forKeyPath: @" frame" options: 0 context: nil ];
189
+
190
+ NSString *suffix = [NSString stringWithFormat: @" %lld " , viewId];
191
+ _inspector = [[FGMMapInspector alloc ] initWithMapController: self
192
+ messenger: registrar.messenger
193
+ pigeonSuffix: suffix];
194
+ SetUpFGMMapsInspectorApiWithSuffix (registrar.messenger , _inspector, suffix);
161
195
}
162
196
return self;
163
197
}
164
198
199
+ - (void )dealloc {
200
+ // Unregister the API implementations so that they can be released; the registration created an
201
+ // owning reference.
202
+ SetUpFGMMapsInspectorApiWithSuffix (_inspector.messenger , nil , _inspector.pigeonSuffix );
203
+ }
204
+
165
205
- (UIView *)view {
166
206
return self.mapView ;
167
207
}
@@ -356,41 +396,8 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
356
396
id rawTileOverlayId = call.arguments [@" tileOverlayId" ];
357
397
[self .tileOverlaysController clearTileCacheWithIdentifier: rawTileOverlayId];
358
398
result (nil );
359
- } else if ([call.method isEqualToString: @" map#isCompassEnabled" ]) {
360
- NSNumber *isCompassEnabled = @(self.mapView .settings .compassButton );
361
- result (isCompassEnabled);
362
- } else if ([call.method isEqualToString: @" map#isMapToolbarEnabled" ]) {
363
- NSNumber *isMapToolbarEnabled = @NO ;
364
- result (isMapToolbarEnabled);
365
- } else if ([call.method isEqualToString: @" map#getMinMaxZoomLevels" ]) {
366
- NSArray *zoomLevels = @[ @(self .mapView.minZoom), @(self .mapView.maxZoom) ];
367
- result (zoomLevels);
368
399
} else if ([call.method isEqualToString: @" map#getZoomLevel" ]) {
369
400
result (@(self.mapView .camera .zoom ));
370
- } else if ([call.method isEqualToString: @" map#isZoomGesturesEnabled" ]) {
371
- NSNumber *isZoomGesturesEnabled = @(self.mapView .settings .zoomGestures );
372
- result (isZoomGesturesEnabled);
373
- } else if ([call.method isEqualToString: @" map#isZoomControlsEnabled" ]) {
374
- NSNumber *isZoomControlsEnabled = @NO ;
375
- result (isZoomControlsEnabled);
376
- } else if ([call.method isEqualToString: @" map#isTiltGesturesEnabled" ]) {
377
- NSNumber *isTiltGesturesEnabled = @(self.mapView .settings .tiltGestures );
378
- result (isTiltGesturesEnabled);
379
- } else if ([call.method isEqualToString: @" map#isRotateGesturesEnabled" ]) {
380
- NSNumber *isRotateGesturesEnabled = @(self.mapView .settings .rotateGestures );
381
- result (isRotateGesturesEnabled);
382
- } else if ([call.method isEqualToString: @" map#isScrollGesturesEnabled" ]) {
383
- NSNumber *isScrollGesturesEnabled = @(self.mapView .settings .scrollGestures );
384
- result (isScrollGesturesEnabled);
385
- } else if ([call.method isEqualToString: @" map#isMyLocationButtonEnabled" ]) {
386
- NSNumber *isMyLocationButtonEnabled = @(self.mapView .settings .myLocationButton );
387
- result (isMyLocationButtonEnabled);
388
- } else if ([call.method isEqualToString: @" map#isTrafficEnabled" ]) {
389
- NSNumber *isTrafficEnabled = @(self.mapView .trafficEnabled );
390
- result (isTrafficEnabled);
391
- } else if ([call.method isEqualToString: @" map#isBuildingsEnabled" ]) {
392
- NSNumber *isBuildingsEnabled = @(self.mapView .buildingsEnabled );
393
- result (isBuildingsEnabled);
394
401
} else if ([call.method isEqualToString: @" map#setStyle" ]) {
395
402
id mapStyle = [call arguments ];
396
403
self.styleError = [self setMapStyle: (mapStyle == [NSNull null ] ? nil : mapStyle)];
@@ -401,9 +408,6 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
401
408
}
402
409
} else if ([call.method isEqualToString: @" map#getStyleError" ]) {
403
410
result (self.styleError );
404
- } else if ([call.method isEqualToString: @" map#getTileOverlayInfo" ]) {
405
- NSString *rawTileOverlayId = call.arguments [@" tileOverlayId" ];
406
- result ([self .tileOverlaysController tileOverlayInfoWithIdentifier: rawTileOverlayId]);
407
411
} else {
408
412
result (FlutterMethodNotImplemented);
409
413
}
@@ -659,3 +663,81 @@ - (void)interpretMapOptions:(NSDictionary *)data {
659
663
}
660
664
661
665
@end
666
+
667
+ #pragma mark -
668
+
669
+ @implementation FGMMapInspector
670
+
671
+ - (instancetype )initWithMapController : (nonnull FLTGoogleMapController *)controller
672
+ messenger : (NSObject <FlutterBinaryMessenger> *)messenger
673
+ pigeonSuffix : (NSString *)suffix {
674
+ self = [super init ];
675
+ if (self) {
676
+ _controller = controller;
677
+ _messenger = messenger;
678
+ _pigeonSuffix = suffix;
679
+ }
680
+ return self;
681
+ }
682
+
683
+ - (nullable NSNumber *)areBuildingsEnabledWithError :
684
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
685
+ return @(self.controller .mapView .buildingsEnabled );
686
+ }
687
+
688
+ - (nullable NSNumber *)areRotateGesturesEnabledWithError :
689
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
690
+ return @(self.controller .mapView .settings .rotateGestures );
691
+ }
692
+
693
+ - (nullable NSNumber *)areScrollGesturesEnabledWithError :
694
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
695
+ return @(self.controller .mapView .settings .scrollGestures );
696
+ }
697
+
698
+ - (nullable NSNumber *)areTiltGesturesEnabledWithError :
699
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
700
+ return @(self.controller .mapView .settings .tiltGestures );
701
+ }
702
+
703
+ - (nullable NSNumber *)areZoomGesturesEnabledWithError :
704
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
705
+ return @(self.controller .mapView .settings .zoomGestures );
706
+ }
707
+
708
+ - (nullable FGMPlatformTileLayer *)
709
+ getInfoForTileOverlayWithIdentifier:(nonnull NSString *)tileOverlayId
710
+ error : (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
711
+ GMSTileLayer *layer =
712
+ [self .controller.tileOverlaysController tileOverlayWithIdentifier: tileOverlayId].layer ;
713
+ if (!layer) {
714
+ return nil ;
715
+ }
716
+ return [FGMPlatformTileLayer makeWithVisible: (layer.map != nil )
717
+ fadeIn: layer.fadeIn
718
+ opacity: layer.opacity
719
+ zIndex: layer.zIndex];
720
+ }
721
+
722
+ - (nullable NSNumber *)isCompassEnabledWithError :
723
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
724
+ return @(self.controller .mapView .settings .compassButton );
725
+ }
726
+
727
+ - (nullable NSNumber *)isMyLocationButtonEnabledWithError :
728
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
729
+ return @(self.controller .mapView .settings .myLocationButton );
730
+ }
731
+
732
+ - (nullable NSNumber *)isTrafficEnabledWithError :
733
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
734
+ return @(self.controller .mapView .trafficEnabled );
735
+ }
736
+
737
+ - (nullable FGMPlatformZoomRange *)zoomRange :
738
+ (FlutterError *_Nullable __autoreleasing *_Nonnull)error {
739
+ return [FGMPlatformZoomRange makeWithMin: self .controller.mapView.minZoom
740
+ max: self .controller.mapView.maxZoom];
741
+ }
742
+
743
+ @end
0 commit comments