Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Updated documentation and associated test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rex committed Nov 26, 2018
1 parent 2fdcf17 commit 58b1dc7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
13 changes: 11 additions & 2 deletions platform/darwin/src/MGLCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@ FOUNDATION_EXTERN MGL_EXPORT const NSUInteger MGLClusterIdentifierInvalid;
example:
```swift
if let cluster = feature as? MGLCluster {
...
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
}
print("Approximate number of points in cluster: \(cluster.clusterPointCountAbbreviation)")
```
*/
MGL_EXPORT
Expand Down
54 changes: 53 additions & 1 deletion platform/darwin/test/MGLDocumentationExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -394,6 +394,58 @@ 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,
"point_count_abbreviated" : "4.5k"
]
]

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
}

print("Approximate number of points in cluster: \(cluster.clusterPointCountAbbreviation)")

//#-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() {}
}

0 comments on commit 58b1dc7

Please sign in to comment.