Skip to content

Commit 8c00f43

Browse files
Refactor update methods, and expose for testing
1 parent c8ba0cc commit 8c00f43

17 files changed

+297
-298
lines changed

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FGMGroundOverlayController.m

Lines changed: 34 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
#import "FGMGroundOverlayController.h"
6+
#import "FGMGroundOverlayController_Test.h"
67

78
#import "FGMImageUtils.h"
89
#import "FLTGoogleMapJSONConversions.h"
@@ -34,67 +35,44 @@ - (void)removeGroundOverlay {
3435
self.groundOverlay.map = nil;
3536
}
3637

37-
- (void)setConsumeTapEvents:(BOOL)consumes {
38-
self.groundOverlay.tappable = consumes;
39-
}
40-
41-
- (void)setVisible:(BOOL)visible {
42-
self.groundOverlay.map = visible ? self.mapView : nil;
43-
}
44-
45-
- (void)setZIndex:(int)zIndex {
46-
self.groundOverlay.zIndex = zIndex;
47-
}
48-
49-
- (void)setAnchor:(CGPoint)anchor {
50-
self.groundOverlay.anchor = anchor;
51-
}
52-
53-
- (void)setBearing:(CLLocationDirection)bearing {
54-
self.groundOverlay.bearing = bearing;
55-
}
56-
57-
- (void)setTransparency:(float)transparency {
58-
float opacity = 1.0 - transparency;
59-
self.groundOverlay.opacity = opacity;
60-
}
61-
62-
- (void)setPositionFromBounds:(GMSCoordinateBounds *)bounds {
63-
self.groundOverlay.bounds = bounds;
64-
}
65-
66-
- (void)setPositionFromCoordinates:(CLLocationCoordinate2D)coordinates {
67-
self.groundOverlay.position = coordinates;
68-
}
69-
70-
- (void)setIcon:(UIImage *)icon {
71-
self.groundOverlay.icon = icon;
72-
}
73-
7438
- (void)updateFromPlatformGroundOverlay:(FGMPlatformGroundOverlay *)groundOverlay
7539
registrar:(NSObject<FlutterPluginRegistrar> *)registrar
7640
screenScale:(CGFloat)screenScale {
77-
[self setConsumeTapEvents:groundOverlay.clickable];
78-
[self setZIndex:(int)groundOverlay.zIndex];
79-
[self setAnchor:CGPointMake(groundOverlay.anchor.x, groundOverlay.anchor.y)];
80-
UIImage *image = FGMIconFromBitmap(groundOverlay.image, registrar, screenScale);
81-
[self setIcon:image];
82-
[self setBearing:groundOverlay.bearing];
83-
[self setTransparency:groundOverlay.transparency];
84-
if ([self isCreatedWithBounds]) {
85-
[self setPositionFromBounds:[[GMSCoordinateBounds alloc]
86-
initWithCoordinate:CLLocationCoordinate2DMake(
87-
groundOverlay.bounds.northeast.latitude,
88-
groundOverlay.bounds.northeast.longitude)
89-
coordinate:CLLocationCoordinate2DMake(
90-
groundOverlay.bounds.southwest.latitude,
91-
groundOverlay.bounds.southwest
92-
.longitude)]];
41+
[FGMGroundOverlayController updateGroundOverlay:self.groundOverlay
42+
fromPlatformGroundOverlay:groundOverlay
43+
withMapView:self.mapView
44+
registrar:registrar
45+
screenScale:screenScale
46+
usingBounds:self.createdWithBounds];
47+
}
48+
49+
+ (void)updateGroundOverlay:(GMSGroundOverlay *)groundOverlay
50+
fromPlatformGroundOverlay:(FGMPlatformGroundOverlay *)platformGroundOverlay
51+
withMapView:(GMSMapView *)mapView
52+
registrar:(NSObject<FlutterPluginRegistrar> *)registrar
53+
screenScale:(CGFloat)screenScale
54+
usingBounds:(BOOL)useBounds {
55+
groundOverlay.tappable = platformGroundOverlay.clickable;
56+
groundOverlay.zIndex = (int)platformGroundOverlay.zIndex;
57+
groundOverlay.anchor =
58+
CGPointMake(platformGroundOverlay.anchor.x, platformGroundOverlay.anchor.y);
59+
UIImage *image = FGMIconFromBitmap(platformGroundOverlay.image, registrar, screenScale);
60+
groundOverlay.icon = image;
61+
groundOverlay.bearing = platformGroundOverlay.bearing;
62+
groundOverlay.opacity = 1.0 - platformGroundOverlay.transparency;
63+
if (useBounds) {
64+
groundOverlay.bounds = [[GMSCoordinateBounds alloc]
65+
initWithCoordinate:CLLocationCoordinate2DMake(
66+
platformGroundOverlay.bounds.northeast.latitude,
67+
platformGroundOverlay.bounds.northeast.longitude)
68+
coordinate:CLLocationCoordinate2DMake(
69+
platformGroundOverlay.bounds.southwest.latitude,
70+
platformGroundOverlay.bounds.southwest.longitude)];
9371
} else {
94-
[self setPositionFromCoordinates:CLLocationCoordinate2DMake(groundOverlay.position.latitude,
95-
groundOverlay.position.longitude)];
72+
groundOverlay.position = CLLocationCoordinate2DMake(platformGroundOverlay.position.latitude,
73+
platformGroundOverlay.position.longitude);
9674
}
97-
[self setVisible:groundOverlay.visible];
75+
groundOverlay.map = platformGroundOverlay.visible ? mapView : nil;
9876
}
9977

10078
@end

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FGMGroundOverlayController_Test.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,15 @@
1515
registrar:(NSObject<FlutterPluginRegistrar> *)registrar
1616
screenScale:(CGFloat)screenScale;
1717

18+
/// Updates the underlying GMSGroundOverlay with the properties from the given
19+
/// FGMPlatformGroundOverlay.
20+
///
21+
/// Setting the ground overlay to visible will set its map to the given mapView.
22+
+ (void)updateGroundOverlay:(GMSGroundOverlay *)groundOverlay
23+
fromPlatformGroundOverlay:(FGMPlatformGroundOverlay *)groundOverlay
24+
withMapView:(GMSMapView *)mapView
25+
registrar:(NSObject<FlutterPluginRegistrar> *)registrar
26+
screenScale:(CGFloat)screenScale
27+
usingBounds:(BOOL)useBounds;
28+
1829
@end

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapHeatmapController.m

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
// found in the LICENSE file.
44

55
#import "FLTGoogleMapHeatmapController.h"
6-
#import "FLTGoogleMapJSONConversions.h"
6+
#import "FLTGoogleMapHeatmapController_Test.h"
7+
78
@import GoogleMapsUtils;
89

10+
#import "FLTGoogleMapJSONConversions.h"
11+
912
@interface FLTGoogleMapHeatmapController ()
1013

1114
/// The heatmap tile layer this controller handles.
@@ -25,9 +28,9 @@ - (instancetype)initWithHeatmapTileLayer:(GMUHeatmapTileLayer *)heatmapTileLayer
2528
_heatmapTileLayer = heatmapTileLayer;
2629
_mapView = mapView;
2730

28-
[FLTGoogleMapHeatmapController interpretHeatmapOptions:_heatmapTileLayer
29-
mapView:_mapView
30-
options:options];
31+
[FLTGoogleMapHeatmapController updateHeatmap:_heatmapTileLayer
32+
fromOptions:options
33+
withMapView:_mapView];
3134
}
3235
return self;
3336
}
@@ -41,14 +44,16 @@ - (void)clearTileCache {
4144
}
4245

4346
- (void)interpretHeatmapOptions:(NSDictionary<NSString *, id> *)data {
44-
[FLTGoogleMapHeatmapController interpretHeatmapOptions:_heatmapTileLayer
45-
mapView:_mapView
46-
options:data];
47+
[FLTGoogleMapHeatmapController updateHeatmap:_heatmapTileLayer
48+
fromOptions:data
49+
withMapView:_mapView];
4750
}
4851

49-
+ (void)interpretHeatmapOptions:(GMUHeatmapTileLayer *)heatmapTileLayer
50-
mapView:(GMSMapView *)mapView
51-
options:(NSDictionary<NSString *, id> *)options {
52+
+ (void)updateHeatmap:(GMUHeatmapTileLayer *)heatmapTileLayer
53+
fromOptions:(NSDictionary<NSString *, id> *)options
54+
withMapView:(GMSMapView *)mapView {
55+
// TODO(stuartmorgan): Migrate this to Pigeon. See
56+
// https://github.com/flutter/flutter/issues/117907
5257
id weightedData = options[kHeatmapDataKey];
5358
if ([weightedData isKindOfClass:[NSArray class]]) {
5459
heatmapTileLayer.weightedData =
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "FLTGoogleMapHeatmapController.h"
6+
7+
/// Internal APIs exposed for unit testing
8+
@interface FLTGoogleMapHeatmapController (Test)
9+
10+
/// Updates the underlying GMUHeatmapTileLayer with the properties from the given options.
11+
///
12+
/// Setting the heatmap to visible will set its map to the given mapView.
13+
+ (void)updateHeatmap:(GMUHeatmapTileLayer *)heatmapTileLayer
14+
fromOptions:(NSDictionary<NSString *, id> *)options
15+
withMapView:(GMSMapView *)mapView;
16+
17+
@end

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/FLTGoogleMapTileOverlayController.m

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// found in the LICENSE file.
44

55
#import "FLTGoogleMapTileOverlayController.h"
6+
#import "FLTGoogleMapTileOverlayController_Test.h"
7+
68
#import "FLTGoogleMapJSONConversions.h"
79

810
@interface FLTGoogleMapTileOverlayController ()
@@ -21,8 +23,9 @@ - (instancetype)initWithTileOverlay:(FGMPlatformTileOverlay *)tileOverlay
2123
if (self) {
2224
_layer = tileLayer;
2325
_mapView = mapView;
24-
// TODO(stuartmorgan: Refactor to avoid this call to an instance method in init.
25-
[self updateFromPlatformTileOverlay:tileOverlay];
26+
[FLTGoogleMapTileOverlayController updateTileLayer:tileLayer
27+
fromPlatformTileOverlay:tileOverlay
28+
withMapView:mapView];
2629
}
2730
return self;
2831
}
@@ -35,33 +38,20 @@ - (void)clearTileCache {
3538
[self.layer clearTileCache];
3639
}
3740

38-
- (void)setFadeIn:(BOOL)fadeIn {
39-
self.layer.fadeIn = fadeIn;
40-
}
41-
42-
- (void)setTransparency:(float)transparency {
43-
float opacity = 1.0 - transparency;
44-
self.layer.opacity = opacity;
45-
}
46-
47-
- (void)setVisible:(BOOL)visible {
48-
self.layer.map = visible ? self.mapView : nil;
49-
}
50-
51-
- (void)setZIndex:(int)zIndex {
52-
self.layer.zIndex = zIndex;
53-
}
54-
55-
- (void)setTileSize:(NSInteger)tileSize {
56-
self.layer.tileSize = tileSize;
57-
}
58-
5941
- (void)updateFromPlatformTileOverlay:(FGMPlatformTileOverlay *)overlay {
60-
[self setVisible:overlay.visible];
61-
[self setTransparency:overlay.transparency];
62-
[self setZIndex:(int)overlay.zIndex];
63-
[self setFadeIn:overlay.fadeIn];
64-
[self setTileSize:overlay.tileSize];
42+
[FLTGoogleMapTileOverlayController updateTileLayer:self.layer
43+
fromPlatformTileOverlay:overlay
44+
withMapView:self.mapView];
45+
}
46+
47+
+ (void)updateTileLayer:(GMSTileLayer *)tileLayer
48+
fromPlatformTileOverlay:(FGMPlatformTileOverlay *)platformOverlay
49+
withMapView:(GMSMapView *)mapView {
50+
tileLayer.map = platformOverlay.visible ? mapView : nil;
51+
tileLayer.opacity = 1.0 - platformOverlay.transparency;
52+
tileLayer.zIndex = (int)platformOverlay.zIndex;
53+
tileLayer.fadeIn = platformOverlay.fadeIn;
54+
tileLayer.tileSize = platformOverlay.tileSize;
6555
}
6656

6757
@end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "FLTGoogleMapTileOverlayController.h"
6+
7+
/// Internal APIs exposed for unit testing
8+
@interface FLTGoogleMapTileOverlayController (Test)
9+
10+
/// Updates the underlying GMSTileLayer with the properties from the given FGMPlatformTileOverlay.
11+
///
12+
/// Setting the tile overlay to visible will set its map to the given mapView.
13+
+ (void)updateTileLayer:(GMSTileLayer *)tileLayer
14+
fromPlatformTileOverlay:(FGMPlatformTileOverlay *)platformOverlay
15+
withMapView:(GMSMapView *)mapView;
16+
17+
@end

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#import "messages.g.h"
99

10+
NS_ASSUME_NONNULL_BEGIN
11+
1012
// Defines circle controllable by Flutter.
1113
@interface FLTGoogleMapCircleController : NSObject
1214
- (instancetype)initCircleWithPlatformCircle:(FGMPlatformCircle *)circle
@@ -24,3 +26,5 @@
2426
- (void)didTapCircleWithIdentifier:(NSString *)identifier;
2527
- (bool)hasCircleWithIdentifier:(NSString *)identifier;
2628
@end
29+
30+
NS_ASSUME_NONNULL_END

packages/google_maps_flutter/google_maps_flutter_ios/ios/Classes/GoogleMapCircleController.m

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// found in the LICENSE file.
44

55
#import "GoogleMapCircleController.h"
6+
#import "GoogleMapCircleController_Test.h"
7+
68
#import "FLTGoogleMapJSONConversions.h"
79

810
@interface FLTGoogleMapCircleController ()
@@ -22,8 +24,9 @@ - (instancetype)initCircleWithPlatformCircle:(FGMPlatformCircle *)circle
2224
radius:circle.radius];
2325
_mapView = mapView;
2426
_circle.userData = @[ circle.circleId ];
25-
// TODO(stuartmorgan: Refactor to avoid this call to an instance method in init.
26-
[self updateFromPlatformCircle:circle];
27+
[FLTGoogleMapCircleController updateCircle:_circle
28+
fromPlatformCircle:circle
29+
withMapView:mapView];
2730
}
2831
return self;
2932
}
@@ -32,41 +35,23 @@ - (void)removeCircle {
3235
self.circle.map = nil;
3336
}
3437

35-
- (void)setConsumeTapEvents:(BOOL)consumes {
36-
self.circle.tappable = consumes;
37-
}
38-
- (void)setVisible:(BOOL)visible {
39-
self.circle.map = visible ? self.mapView : nil;
40-
}
41-
- (void)setZIndex:(int)zIndex {
42-
self.circle.zIndex = zIndex;
43-
}
44-
- (void)setCenter:(CLLocationCoordinate2D)center {
45-
self.circle.position = center;
46-
}
47-
- (void)setRadius:(CLLocationDistance)radius {
48-
self.circle.radius = radius;
49-
}
50-
51-
- (void)setStrokeColor:(UIColor *)color {
52-
self.circle.strokeColor = color;
53-
}
54-
- (void)setStrokeWidth:(CGFloat)width {
55-
self.circle.strokeWidth = width;
56-
}
57-
- (void)setFillColor:(UIColor *)color {
58-
self.circle.fillColor = color;
59-
}
60-
6138
- (void)updateFromPlatformCircle:(FGMPlatformCircle *)platformCircle {
62-
[self setConsumeTapEvents:platformCircle.consumeTapEvents];
63-
[self setVisible:platformCircle.visible];
64-
[self setZIndex:platformCircle.zIndex];
65-
[self setCenter:FGMGetCoordinateForPigeonLatLng(platformCircle.center)];
66-
[self setRadius:platformCircle.radius];
67-
[self setStrokeColor:FGMGetColorForRGBA(platformCircle.strokeColor)];
68-
[self setStrokeWidth:platformCircle.strokeWidth];
69-
[self setFillColor:FGMGetColorForRGBA(platformCircle.fillColor)];
39+
[FLTGoogleMapCircleController updateCircle:self.circle
40+
fromPlatformCircle:platformCircle
41+
withMapView:self.mapView];
42+
}
43+
44+
+ (void)updateCircle:(GMSCircle *)circle
45+
fromPlatformCircle:(FGMPlatformCircle *)platformCircle
46+
withMapView:(GMSMapView *)mapView {
47+
circle.tappable = platformCircle.consumeTapEvents;
48+
circle.map = platformCircle.visible ? mapView : nil;
49+
circle.zIndex = platformCircle.zIndex;
50+
circle.position = FGMGetCoordinateForPigeonLatLng(platformCircle.center);
51+
circle.radius = platformCircle.radius;
52+
circle.strokeColor = FGMGetColorForRGBA(platformCircle.strokeColor);
53+
circle.strokeWidth = platformCircle.strokeWidth;
54+
circle.fillColor = FGMGetColorForRGBA(platformCircle.fillColor);
7055
}
7156

7257
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 The Flutter Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#import "GoogleMapCircleController.h"
6+
7+
NS_ASSUME_NONNULL_BEGIN
8+
9+
/// Private methods exposed for testing.
10+
@interface FLTGoogleMapCircleController (Test)
11+
12+
/// Updates the underlying GMSCircle with the properties from the given FGMPlatformCircle.
13+
///
14+
/// Setting the circle to visible will set its map to the given mapView.
15+
+ (void)updateCircle:(GMSCircle *)circle
16+
fromPlatformCircle:(FGMPlatformCircle *)platformCircle
17+
withMapView:(GMSMapView *)mapView;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)