diff options
Diffstat (limited to 'platform/darwin/test/MGLDocumentationExampleTests.swift')
-rw-r--r-- | platform/darwin/test/MGLDocumentationExampleTests.swift | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift index b59d297f97..9d1d848868 100644 --- a/platform/darwin/test/MGLDocumentationExampleTests.swift +++ b/platform/darwin/test/MGLDocumentationExampleTests.swift @@ -47,6 +47,84 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { styleLoadingExpectation.fulfill() } + func testMGLLight() { + //#-example-code + let light = MGLLight() + let position = MGLSphericalPosition(radial: 5, azimuthal: 180, polar: 80) + light.position = NSExpression(forConstantValue: NSValue(mglSphericalPosition: position)) + light.anchor = NSExpression(forConstantValue: "map") + mapView.style?.light = light + //#-end-example-code + + XCTAssertNotNil(mapView.style?.light) + } + + func testMGLTilePyramidOfflineRegion() { + class MGLStyle { + static var lightStyleURL: URL { + return MGLDocumentationExampleTests.styleURL + } + } + + //#-example-code + let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592) + let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896) + let bbox = MGLCoordinateBounds(sw: southwest, ne: northeast) + + let region = MGLTilePyramidOfflineRegion(styleURL: MGLStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14) + let context = "Tile Pyramid Region".data(using: .utf8) + MGLOfflineStorage.shared.addPack(for: region, withContext: context!) + //#-end-example-code + + XCTAssertNotNil(region) + } + + func testMGLShapeOfflineRegion() { + class MGLStyle { + static var lightStyleURL: URL { + return MGLDocumentationExampleTests.styleURL + } + } + + //#-example-code + var coordinates = [ + CLLocationCoordinate2D(latitude: 45.522585, longitude: -122.685699), + CLLocationCoordinate2D(latitude: 45.534611, longitude: -122.708873), + CLLocationCoordinate2D(latitude: 45.530883, longitude: -122.678833) + ] + + let triangle = MGLPolygon(coordinates: &coordinates, count: UInt(coordinates.count)) + let region = MGLShapeOfflineRegion(styleURL: MGLStyle.lightStyleURL, shape: triangle, fromZoomLevel: 11, toZoomLevel: 14) + let context = "Triangle Region".data(using: .utf8) + MGLOfflineStorage.shared.addPack(for: region, withContext: context!) + //#-end-example-code + + XCTAssertNotNil(region) + } + + func testMGLOfflinePack() { + let northeast = CLLocationCoordinate2D(latitude: 40.989329, longitude: -102.062592) + let southwest = CLLocationCoordinate2D(latitude: 36.986207, longitude: -109.049896) + let bbox = MGLCoordinateBounds(sw: southwest, ne: northeast) + let region = MGLTilePyramidOfflineRegion(styleURL: MGLStyle.lightStyleURL, bounds: bbox, fromZoomLevel: 11, toZoomLevel: 14) + let context = "Tile Pyramid Region".data(using: .utf8) + + //#-example-code + MGLOfflineStorage.shared.addPack(for: region, withContext: context!) { (pack, error) in + guard error == nil else { + // If download fails, log the error to the console + print("Error: \(error?.localizedDescription ?? "unknown error")") + return + } + + // Start an MGLOfflinePack download + pack!.resume() + } + //#-end-example-code + + XCTAssertNotNil(region) + } + func testMGLShape$shapeWithData_encoding_error_() { let mainBundle = Bundle(for: MGLDocumentationExampleTests.self) |