diff options
author | Josh Erb <josh.erb@mapbox.com> | 2018-12-13 16:34:31 -0500 |
---|---|---|
committer | Josh Erb <josherb4@gmail.com> | 2019-01-30 13:18:45 -0500 |
commit | 5d891b4b2a7ce4f71bfb5b31a08aafa64db0a003 (patch) | |
tree | 1e93304dc2f5aa3c53c1ec257aa3ea566e513449 /platform/darwin/test | |
parent | 8faee2554692ae13da5fbb68d3eef2ebb09a0c86 (diff) | |
download | qtlocation-mapboxgl-5d891b4b2a7ce4f71bfb5b31a08aafa64db0a003.tar.gz |
[ios][documenation] add additional code snippets to API docs
Diffstat (limited to 'platform/darwin/test')
-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) |