diff options
Diffstat (limited to 'platform/darwin/test/MGLDocumentationExampleTests.swift')
-rw-r--r-- | platform/darwin/test/MGLDocumentationExampleTests.swift | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift index 028ee2e856..b59d297f97 100644 --- a/platform/darwin/test/MGLDocumentationExampleTests.swift +++ b/platform/darwin/test/MGLDocumentationExampleTests.swift @@ -374,7 +374,7 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { return MGLDocumentationExampleTests.styleURL } } - + //#-example-code let camera = MGLMapCamera(lookingAtCenter: CLLocationCoordinate2D(latitude: 37.7184, longitude: -122.4365), altitude: 100, pitch: 20, heading: 0) @@ -394,6 +394,61 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { wait(for: [expectation], timeout: 5) } + func testMGLCluster() { + + enum ExampleError: Error { + case unexpectedFeatureType + case featureIsNotACluster + } + + let geoJSON: [String: Any] = [ + "type" : "Feature", + "geometry" : [ + "coordinates" : [ + -77.00896639534831, + 38.87031006108791, + 0.0 + ], + "type" : "Point" + ], + "properties" : [ + "cluster" : true, + "cluster_id" : 123, + "point_count" : 4567, + ] + ] + + let clusterShapeData = try! JSONSerialization.data(withJSONObject: geoJSON, options: []) + + do { + //#-example-code + let shape = try! MGLShape(data: clusterShapeData, encoding: String.Encoding.utf8.rawValue) + + guard let pointFeature = shape as? MGLPointFeature else { + throw ExampleError.unexpectedFeatureType + } + + // Check for cluster conformance + guard let cluster = pointFeature as? MGLCluster else { + throw ExampleError.featureIsNotACluster + } + + // Currently the only supported class that conforms to `MGLCluster` is + // `MGLPointFeatureCluster` + guard cluster is MGLPointFeatureCluster else { + throw ExampleError.unexpectedFeatureType + } + + //#-end-example-code + + XCTAssert(cluster.clusterIdentifier == 123) + XCTAssert(cluster.clusterPointCount == 4567) + } + catch let error { + XCTFail("Example failed with thrown error: \(error)") + } + } + // For testMGLMapView(). func myCustomFunction() {} } |