-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[google_maps_flutter] Add marker clustering support - iOS implementat…
…ion (#6186) This PR introduces support for marker clustering for iOS platform An example usabe is available in the example application at ./packages/google_maps_flutter/google_maps_flutter_ios/example/ios12 on the page `Manage clustering` This is prequel PR for: #4319 and sequel PR for: #6158 Containing only changes to `google_maps_flutter_ios` package. Follow up PR will hold the app-facing plugin implementation. Linked issue: flutter/flutter#26863
- Loading branch information
Showing
32 changed files
with
1,585 additions
and
96 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/google_maps_flutter/google_maps_flutter_ios/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 2.12.0 | ||
|
||
* Adds support for marker clustering. | ||
|
||
## 2.11.0 | ||
|
||
* Adds support for heatmap layers. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...google_maps_flutter_ios/example/ios14/ios/RunnerTests/FGMClusterManagersControllerTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
@import google_maps_flutter_ios; | ||
@import google_maps_flutter_ios.Test; | ||
@import XCTest; | ||
@import GoogleMaps; | ||
|
||
#import <Flutter/Flutter.h> | ||
#import <OCMock/OCMock.h> | ||
#import "PartiallyMockedMapView.h" | ||
|
||
@interface FGMClusterManagersControllerTests : XCTestCase | ||
@end | ||
|
||
@implementation FGMClusterManagersControllerTests | ||
|
||
- (void)testClustering { | ||
NSObject<FlutterPluginRegistrar> *registrar = OCMProtocolMock(@protocol(FlutterPluginRegistrar)); | ||
CGRect frame = CGRectMake(0, 0, 100, 100); | ||
|
||
GMSMapViewOptions *mapViewOptions = [[GMSMapViewOptions alloc] init]; | ||
mapViewOptions.frame = frame; | ||
mapViewOptions.camera = [[GMSCameraPosition alloc] initWithLatitude:0 longitude:0 zoom:0]; | ||
|
||
PartiallyMockedMapView *mapView = [[PartiallyMockedMapView alloc] initWithOptions:mapViewOptions]; | ||
|
||
id handler = OCMClassMock([FGMMapsCallbackApi class]); | ||
|
||
FGMClusterManagersController *clusterManagersController = | ||
[[FGMClusterManagersController alloc] initWithMapView:mapView callbackHandler:handler]; | ||
|
||
FLTMarkersController *markersController = | ||
[[FLTMarkersController alloc] initWithMapView:mapView | ||
callbackHandler:handler | ||
clusterManagersController:clusterManagersController | ||
registrar:registrar]; | ||
|
||
// Add cluster managers. | ||
NSString *clusterManagerId = @"cm"; | ||
FGMPlatformClusterManager *clusterManagerToAdd = | ||
[FGMPlatformClusterManager makeWithIdentifier:clusterManagerId]; | ||
[clusterManagersController addClusterManagers:@[ clusterManagerToAdd ]]; | ||
|
||
// Add cluster managers in JSON format. | ||
NSString *JSONClusterManagerId = @"json_cm"; | ||
NSDictionary *JSONclusterManagerToAdd = @{@"clusterManagerId" : JSONClusterManagerId}; | ||
[clusterManagersController addJSONClusterManagers:@[ JSONclusterManagerToAdd ]]; | ||
|
||
// Verify that cluster managers are available | ||
GMUClusterManager *clusterManager = | ||
[clusterManagersController clusterManagerWithIdentifier:clusterManagerId]; | ||
XCTAssertNotNil(clusterManager, @"Cluster Manager should not be nil"); | ||
GMUClusterManager *JSONClusterManager = | ||
[clusterManagersController clusterManagerWithIdentifier:JSONClusterManagerId]; | ||
XCTAssertNotNil(JSONClusterManager, @"Cluster Manager should not be nil"); | ||
|
||
// Add markers | ||
NSString *markerId1 = @"m1"; | ||
NSString *markerId2 = @"m2"; | ||
|
||
FGMPlatformMarker *marker1 = [FGMPlatformMarker makeWithJson:@{ | ||
@"markerId" : markerId1, | ||
@"position" : @[ @0, @0 ], | ||
@"clusterManagerId" : clusterManagerId | ||
}]; | ||
NSDictionary *marker2 = | ||
@{@"markerId" : markerId2, @"position" : @[ @0, @0 ], @"clusterManagerId" : clusterManagerId}; | ||
|
||
[markersController addMarkers:@[ marker1 ]]; | ||
[markersController addJSONMarkers:@[ marker2 ]]; | ||
|
||
FlutterError *error = nil; | ||
|
||
// Invoke clustering | ||
[clusterManagersController invokeClusteringForEachClusterManager]; | ||
|
||
// Verify that the markers were added to the cluster manager | ||
NSArray<FGMPlatformCluster *> *clusters1 = | ||
[clusterManagersController clustersWithIdentifier:clusterManagerId error:&error]; | ||
XCTAssertNil(error, @"Error should be nil"); | ||
for (FGMPlatformCluster *cluster in clusters1) { | ||
NSString *cmId = cluster.clusterManagerId; | ||
XCTAssertNotNil(cmId, @"Cluster Manager Identifier should not be nil"); | ||
if ([cmId isEqualToString:clusterManagerId]) { | ||
NSArray *markerIds = cluster.markerIds; | ||
XCTAssertEqual(markerIds.count, 2, @"Cluster should contain two marker"); | ||
XCTAssertTrue([markerIds containsObject:markerId1], @"Cluster should contain markerId1"); | ||
XCTAssertTrue([markerIds containsObject:markerId2], @"Cluster should contain markerId2"); | ||
return; | ||
} | ||
} | ||
|
||
[markersController removeMarkersWithIdentifiers:@[ markerId2 ]]; | ||
|
||
// Verify that the marker2 is removed from the clusterManager | ||
NSArray<FGMPlatformCluster *> *clusters2 = | ||
[clusterManagersController clustersWithIdentifier:clusterManagerId error:&error]; | ||
XCTAssertNil(error, @"Error should be nil"); | ||
|
||
for (FGMPlatformCluster *cluster in clusters2) { | ||
NSString *cmId = cluster.clusterManagerId; | ||
XCTAssertNotNil(cmId, @"Cluster Manager ID should not be nil"); | ||
if ([cmId isEqualToString:clusterManagerId]) { | ||
NSArray *markerIds = cluster.markerIds; | ||
XCTAssertEqual(markerIds.count, 1, @"Cluster should contain one marker"); | ||
XCTAssertTrue([markerIds containsObject:markerId1], @"Cluster should contain markerId1"); | ||
return; | ||
} | ||
} | ||
|
||
[markersController removeMarkersWithIdentifiers:@[ markerId1 ]]; | ||
|
||
// Verify that all markers are removed from clusterManager | ||
NSArray<FGMPlatformCluster *> *clusters3 = | ||
[clusterManagersController clustersWithIdentifier:clusterManagerId error:&error]; | ||
XCTAssertNil(error, @"Error should be nil"); | ||
XCTAssertEqual(clusters3.count, 0, @"Cluster Manager should not contain any clusters"); | ||
|
||
// Remove cluster manager | ||
[clusterManagersController removeClusterManagersWithIdentifiers:@[ clusterManagerId ]]; | ||
|
||
// Verify that the cluster manager is removed | ||
clusterManager = [clusterManagersController clusterManagerWithIdentifier:clusterManagerId]; | ||
XCTAssertNil(clusterManager, @"Cluster Manager should be nil"); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.