Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renaming
  • Loading branch information
Chris Yang committed May 31, 2022
commit f23fcbeb0a0910afb5959c4354ace09fabaa2c59
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ @interface FLTGoogleMapJSONConversionsTests : XCTestCase

@implementation FLTGoogleMapJSONConversionsTests

- (void)testLocationFromLatlong {
- (void)testLocationFromLatLong {
NSArray<NSNumber *> *latlong = @[ @1, @2 ];
CLLocationCoordinate2D location = [FLTGoogleMapJSONConversions locationFromLatlong:latlong];
CLLocationCoordinate2D location = [FLTGoogleMapJSONConversions locationFromLatLong:latlong];
XCTAssertEqual(location.latitude, 1);
XCTAssertEqual(location.longitude, 2);
}
Expand Down Expand Up @@ -50,9 +50,9 @@ - (void)testColorFromRGBA {
XCTAssertEqualWithAccuracy(alpha, 1 / 255.0, accuracy);
}

- (void)testPointsFromLatlongs {
- (void)testPointsFromLatLongs {
NSArray<NSArray *> *latlongs = @[ @[ @1, @2 ], @[ @(3), @(4) ] ];
NSArray<CLLocation *> *locations = [FLTGoogleMapJSONConversions pointsFromLatlongs:latlongs];
NSArray<CLLocation *> *locations = [FLTGoogleMapJSONConversions pointsFromLatLongs:latlongs];
XCTAssertEqual(locations.count, 2);
XCTAssertEqual(locations[0].coordinate.latitude, 1);
XCTAssertEqual(locations[0].coordinate.longitude, 2);
Expand Down Expand Up @@ -144,12 +144,12 @@ - (void)testPointFromDictionary {
XCTAssertEqualWithAccuracy(point.y, 2, accuracy);
}

- (void)testCoordinateBoundsFromLatlongs {
- (void)testCoordinateBoundsFromLatLongs {
NSArray<NSNumber *> *latlong1 = @[ @1, @2 ];
NSArray<NSNumber *> *latlong2 = @[ @(3), @(4) ];

GMSCoordinateBounds *bounds =
[FLTGoogleMapJSONConversions coordinateBoundsFromLatlongs:@[ latlong1, latlong2 ]];
[FLTGoogleMapJSONConversions coordinateBoundsFromLatLongs:@[ latlong1, latlong2 ]];

const CGFloat accuracy = 0.001;
XCTAssertEqualWithAccuracy(bounds.southWest.latitude, 1, accuracy);
Expand Down Expand Up @@ -191,7 +191,7 @@ - (void)testCameraUpdateFromChannelValueNewCameraPosition {
// verified.
//
// The code in below test uses the 2nd approach.
- (void)skip_testCameraUpdateFromChannelValueNewLatlong {
- (void)skip_testCameraUpdateFromChannelValueNewLatLong {
NSArray *channelValue = @[ @"newLatLng", @[ @1, @2 ] ];

GMSCameraUpdate *update = [FLTGoogleMapJSONConversions cameraUpdateFromChannelValue:channelValue];
Expand All @@ -211,7 +211,7 @@ - (void)testCameraUpdateFromChannelValueNewLatLngBounds {
NSArray<NSNumber *> *latlong1 = @[ @1, @2 ];
NSArray<NSNumber *> *latlong2 = @[ @(3), @(4) ];
GMSCoordinateBounds *bounds =
[FLTGoogleMapJSONConversions coordinateBoundsFromLatlongs:@[ latlong1, latlong2 ]];
[FLTGoogleMapJSONConversions coordinateBoundsFromLatLongs:@[ latlong1, latlong2 ]];

NSArray *channelValue = @[ @"newLatLngBounds", @[ latlong1, latlong2 ], @20 ];
id classMockCameraUpdate = OCMClassMock([GMSCameraUpdate class]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ NS_ASSUME_NONNULL_BEGIN

@interface FLTGoogleMapJSONConversions : NSObject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The file should be named FLTGoogleMapJSONConversions.h.

(Or even better, the name should stay the same and all of these should become C functions—since "classes" that are just class methods are an abomination IMO—at which point the name should be the same. But I know many ObjC developers like this style so I'm not going to die on that hill today.)


+ (CLLocationCoordinate2D)locationFromLatlong:(NSArray *)latlong;
+ (CLLocationCoordinate2D)locationFromLatLong:(NSArray *)latlong;
+ (CGPoint)pointFromArray:(NSArray *)array;
+ (NSArray *)arrayFromLocation:(CLLocationCoordinate2D)location;
+ (UIColor *)colorFromRGBA:(NSNumber *)data;
+ (NSArray<CLLocation *> *)pointsFromLatlongs:(NSArray *)data;
+ (NSArray<CLLocation *> *)pointsFromLatLongs:(NSArray *)data;
+ (NSArray<NSArray<CLLocation *> *> *)holesFromPointsArray:(NSArray *)data;
+ (nullable NSDictionary<NSString *, id> *)dictionaryFromPosition:
(nullable GMSCameraPosition *)position;
+ (NSDictionary<NSString *, NSNumber *> *)dictionaryFromPoint:(CGPoint)point;
+ (nullable NSDictionary *)dictionaryFromCoordinateBounds:(nullable GMSCoordinateBounds *)bounds;
+ (nullable GMSCameraPosition *)cameraPostionFromDictionary:(nullable NSDictionary *)channelValue;
+ (CGPoint)pointFromDictionary:(NSDictionary *)dictionary;
+ (GMSCoordinateBounds *)coordinateBoundsFromLatlongs:(NSArray *)latlongs;
+ (GMSCoordinateBounds *)coordinateBoundsFromLatLongs:(NSArray *)latlongs;
+ (GMSMapViewType)mapViewTypeFromTypeValue:(NSNumber *)value;
+ (nullable GMSCameraUpdate *)cameraUpdateFromChannelValue:(NSArray *)channelValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@implementation FLTGoogleMapJSONConversions

+ (CLLocationCoordinate2D)locationFromLatlong:(NSArray *)latlong {
+ (CLLocationCoordinate2D)locationFromLatLong:(NSArray *)latlong {
return CLLocationCoordinate2DMake([latlong[0] doubleValue], [latlong[1] doubleValue]);
}

Expand All @@ -26,7 +26,7 @@ + (UIColor *)colorFromRGBA:(NSNumber *)numberColor {
alpha:((float)((value & 0xFF000000) >> 24)) / 255.0];
}

+ (NSArray<CLLocation *> *)pointsFromLatlongs:(NSArray *)data {
+ (NSArray<CLLocation *> *)pointsFromLatLongs:(NSArray *)data {
NSMutableArray *points = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < [data count]; i++) {
NSNumber *latitude = data[i][0];
Expand All @@ -42,7 +42,7 @@ + (UIColor *)colorFromRGBA:(NSNumber *)numberColor {
+ (NSArray<NSArray<CLLocation *> *> *)holesFromPointsArray:(NSArray *)data {
NSMutableArray<NSArray<CLLocation *> *> *holes = [[[NSMutableArray alloc] init] init];
for (unsigned i = 0; i < [data count]; i++) {
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatlongs:data[i]];
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatLongs:data[i]];
[holes addObject:points];
}

Expand Down Expand Up @@ -83,7 +83,7 @@ + (nullable GMSCameraPosition *)cameraPostionFromDictionary:(nullable NSDictiona
return nil;
}
return [GMSCameraPosition
cameraWithTarget:[FLTGoogleMapJSONConversions locationFromLatlong:data[@"target"]]
cameraWithTarget:[FLTGoogleMapJSONConversions locationFromLatLong:data[@"target"]]
zoom:[data[@"zoom"] floatValue]
bearing:[data[@"bearing"] doubleValue]
viewingAngle:[data[@"tilt"] doubleValue]];
Expand All @@ -95,10 +95,10 @@ + (CGPoint)pointFromDictionary:(NSDictionary *)dictionary {
return CGPointMake(x, y);
}

+ (GMSCoordinateBounds *)coordinateBoundsFromLatlongs:(NSArray *)latlongs {
+ (GMSCoordinateBounds *)coordinateBoundsFromLatLongs:(NSArray *)latlongs {
return [[GMSCoordinateBounds alloc]
initWithCoordinate:[FLTGoogleMapJSONConversions locationFromLatlong:latlongs[0]]
coordinate:[FLTGoogleMapJSONConversions locationFromLatlong:latlongs[1]]];
initWithCoordinate:[FLTGoogleMapJSONConversions locationFromLatLong:latlongs[0]]
coordinate:[FLTGoogleMapJSONConversions locationFromLatLong:latlongs[1]]];
}

+ (GMSMapViewType)mapViewTypeFromTypeValue:(NSNumber *)typeValue {
Expand All @@ -113,14 +113,14 @@ + (nullable GMSCameraUpdate *)cameraUpdateFromChannelValue:(NSArray *)channelVal
setCamera:[FLTGoogleMapJSONConversions cameraPostionFromDictionary:channelValue[1]]];
} else if ([update isEqualToString:@"newLatLng"]) {
return [GMSCameraUpdate
setTarget:[FLTGoogleMapJSONConversions locationFromLatlong:channelValue[1]]];
setTarget:[FLTGoogleMapJSONConversions locationFromLatLong:channelValue[1]]];
} else if ([update isEqualToString:@"newLatLngBounds"]) {
return [GMSCameraUpdate
fitBounds:[FLTGoogleMapJSONConversions coordinateBoundsFromLatlongs:channelValue[1]]
fitBounds:[FLTGoogleMapJSONConversions coordinateBoundsFromLatLongs:channelValue[1]]
withPadding:[channelValue[2] doubleValue]];
} else if ([update isEqualToString:@"newLatLngZoom"]) {
return
[GMSCameraUpdate setTarget:[FLTGoogleMapJSONConversions locationFromLatlong:channelValue[1]]
[GMSCameraUpdate setTarget:[FLTGoogleMapJSONConversions locationFromLatLong:channelValue[1]]
zoom:[channelValue[2] floatValue]];
} else if ([update isEqualToString:@"scrollBy"]) {
return [GMSCameraUpdate scrollByX:[channelValue[1] doubleValue]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#import "FLTGoogleMapTileOverlayController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@interface FLTGoogleMapTileOverlayController ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#import "GoogleMapCircleController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@interface FLTGoogleMapCircleController ()

Expand Down Expand Up @@ -77,7 +77,7 @@ - (void)interpretCircleOptions:(NSDictionary *)data {

NSArray *center = data[@"center"];
if (center && center != (id)[NSNull null]) {
[self setCenter:[FLTGoogleMapJSONConversions locationFromLatlong:center]];
[self setCenter:[FLTGoogleMapJSONConversions locationFromLatLong:center]];
}

NSNumber *radius = data[@"radius"];
Expand Down Expand Up @@ -182,7 +182,7 @@ - (void)didTapCircleWithIdentifier:(NSString *)identifier {

+ (CLLocationCoordinate2D)getPosition:(NSDictionary *)circle {
NSArray *center = circle[@"center"];
return [FLTGoogleMapJSONConversions locationFromLatlong:center];
return [FLTGoogleMapJSONConversions locationFromLatLong:center];
}

+ (CLLocationDistance)getRadius:(NSDictionary *)circle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#import "GoogleMapController.h"
#import "FLTGoogleMapTileOverlayController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

#pragma mark - Conversion of JSON-like values sent via platform channels. Forward declarations.

Expand Down Expand Up @@ -186,7 +186,7 @@ - (void)onMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
} else if ([call.method isEqualToString:@"map#getScreenCoordinate"]) {
if (self.mapView != nil) {
CLLocationCoordinate2D location =
[FLTGoogleMapJSONConversions locationFromLatlong:call.arguments];
[FLTGoogleMapJSONConversions locationFromLatLong:call.arguments];
CGPoint point = [self.mapView.projection pointForCoordinate:location];
result([FLTGoogleMapJSONConversions dictionaryFromPoint:point]);
} else {
Expand Down Expand Up @@ -556,7 +556,7 @@ - (void)interpretMapOptions:(NSDictionary *)data {
[self
setCameraTargetBounds:cameraTargetBounds.count > 0 && cameraTargetBounds[0] != [NSNull null]
? [FLTGoogleMapJSONConversions
coordinateBoundsFromLatlongs:cameraTargetBounds.firstObject]
coordinateBoundsFromLatLongs:cameraTargetBounds.firstObject]
: nil];
}
NSNumber *compassEnabled = data[@"compassEnabled"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#import "GoogleMapMarkerController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@interface FLTGoogleMapMarkerController ()

Expand Down Expand Up @@ -120,7 +120,7 @@ - (void)interpretMarkerOptions:(NSDictionary *)data
[self interpretInfoWindow:data];
NSArray *position = data[@"position"];
if (position && position != (id)[NSNull null]) {
[self setPosition:[FLTGoogleMapJSONConversions locationFromLatlong:position]];
[self setPosition:[FLTGoogleMapJSONConversions locationFromLatLong:position]];
}
NSNumber *rotation = data[@"rotation"];
if (rotation && rotation != (id)[NSNull null]) {
Expand Down Expand Up @@ -381,7 +381,7 @@ - (void)isInfoWindowShownForMarkerWithIdentifier:(NSString *)identifier

+ (CLLocationCoordinate2D)getPosition:(NSDictionary *)marker {
NSArray *position = marker[@"position"];
return [FLTGoogleMapJSONConversions locationFromLatlong:position];
return [FLTGoogleMapJSONConversions locationFromLatLong:position];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#import "GoogleMapPolygonController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@interface FLTGoogleMapPolygonController ()

Expand Down Expand Up @@ -90,7 +90,7 @@ - (void)interpretPolygonOptions:(NSDictionary *)data

NSArray *points = data[@"points"];
if (points && points != (id)[NSNull null]) {
[self setPoints:[FLTGoogleMapJSONConversions pointsFromLatlongs:points]];
[self setPoints:[FLTGoogleMapJSONConversions pointsFromLatLongs:points]];
}

NSArray *holes = data[@"holes"];
Expand Down Expand Up @@ -195,7 +195,7 @@ - (bool)hasPolygonWithIdentifier:(NSString *)identifier {

+ (GMSMutablePath *)getPath:(NSDictionary *)polygon {
NSArray *pointArray = polygon[@"points"];
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatlongs:pointArray];
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatLongs:pointArray];
GMSMutablePath *path = [GMSMutablePath path];
for (CLLocation *location in points) {
[path addCoordinate:location.coordinate];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#import "GoogleMapPolylineController.h"
#import "JsonConversions.h"
#import "FLTGoogleMapJSONConversions.h"

@interface FLTGoogleMapPolylineController ()

Expand Down Expand Up @@ -78,7 +78,7 @@ - (void)interpretPolylineOptions:(NSDictionary *)data

NSArray *points = data[@"points"];
if (points && points != (id)[NSNull null]) {
[self setPoints:[FLTGoogleMapJSONConversions pointsFromLatlongs:points]];
[self setPoints:[FLTGoogleMapJSONConversions pointsFromLatLongs:points]];
}

NSNumber *strokeColor = data[@"color"];
Expand Down Expand Up @@ -173,7 +173,7 @@ - (bool)hasPolylineWithIdentifier:(NSString *)identifier {
}
+ (GMSMutablePath *)getPath:(NSDictionary *)polyline {
NSArray *pointArray = polyline[@"points"];
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatlongs:pointArray];
NSArray<CLLocation *> *points = [FLTGoogleMapJSONConversions pointsFromLatLongs:pointArray];
GMSMutablePath *path = [GMSMutablePath path];
for (CLLocation *location in points) {
[path addCoordinate:location.coordinate];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#import <Foundation/Foundation.h>
#import <google_maps_flutter/FLTGoogleMapTileOverlayController.h>
#import <google_maps_flutter/FLTGoogleMapsPlugin.h>
#import <google_maps_flutter/JsonConversions.h>
#import <google_maps_flutter/FLTGoogleMapJSONConversions.h>

FOUNDATION_EXPORT double google_maps_flutterVersionNumber;
FOUNDATION_EXPORT const unsigned char google_maps_flutterVersionString[];