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 | |
parent | 8faee2554692ae13da5fbb68d3eef2ebb09a0c86 (diff) | |
download | qtlocation-mapboxgl-5d891b4b2a7ce4f71bfb5b31a08aafa64db0a003.tar.gz |
[ios][documenation] add additional code snippets to API docs
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/scripts/style-spec-overrides-v8.json | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLLight.h | 9 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflinePack.h | 14 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeOfflineRegion.h | 14 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeSource.h | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLTilePyramidOfflineRegion.h | 11 | ||||
-rw-r--r-- | platform/darwin/test/MGLDocumentationExampleTests.swift | 78 |
7 files changed, 128 insertions, 2 deletions
diff --git a/platform/darwin/scripts/style-spec-overrides-v8.json b/platform/darwin/scripts/style-spec-overrides-v8.json index c98c61f71d..0ba2b77dc5 100644 --- a/platform/darwin/scripts/style-spec-overrides-v8.json +++ b/platform/darwin/scripts/style-spec-overrides-v8.json @@ -1,5 +1,5 @@ { - "light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.\n\n#### Related examples\nSee the <a href=\"https://docs.mapbox.com/ios/maps/examples/light-example/\">Adjust light of 3D buildings</a> to learn how to create and modify the light source for 3D geometries.", + "light-cocoa-doc": "An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`.\n\n### Example\n```swift\n```\n\n#### Related examples\nSee the <a href=\"https://docs.mapbox.com/ios/maps/examples/light-example/\">Adjust light of 3D buildings</a> to learn how to create and modify the light source for 3D geometries.", "light": { "position": { "doc": "Position of the `MGLLight` source relative to lit (extruded) geometries, in a `MGLSphericalPosition` struct [radial coordinate, azimuthal angle, polar angle] where radial indicates the distance from the center of the base of an object to its light, azimuthal indicates the position of the light relative to 0° (0° when `MGLLight.anchor` is set to `MGLLightAnchorViewport` corresponds to the top of the viewport, or 0° when `MGLLight.anchor` is set to `MGLLightAnchorMap` corresponds to due north, and degrees proceed clockwise), and polar indicates the height of the light (from 0°, directly above, to 180°, directly below).", diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index 9694a18d0f..281fcc5c6e 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -60,6 +60,15 @@ NS_INLINE MGLSphericalPosition MGLSphericalPositionMake(CGFloat radial, CLLocati An `MGLLight` object represents the light source for extruded geometries in `MGLStyle`. + ### Example + ```swift + 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 + ``` + #### Related examples See the <a href="https://docs.mapbox.com/ios/maps/examples/light-example/">Adjust light of diff --git a/platform/darwin/src/MGLOfflinePack.h b/platform/darwin/src/MGLOfflinePack.h index 3d22f74e72..7b241e0248 100644 --- a/platform/darwin/src/MGLOfflinePack.h +++ b/platform/darwin/src/MGLOfflinePack.h @@ -103,6 +103,20 @@ typedef struct __attribute__((objc_boxable)) MGLOfflinePackProgress { To create an instance of `MGLOfflinePack`, use the `+[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]` method. A pack created using `-[MGLOfflinePack init]` is immediately invalid. + + ### Example + ```swift + 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() + } + ``` */ MGL_EXPORT @interface MGLOfflinePack : NSObject diff --git a/platform/darwin/src/MGLShapeOfflineRegion.h b/platform/darwin/src/MGLShapeOfflineRegion.h index ac54dc137b..f1def03be8 100644 --- a/platform/darwin/src/MGLShapeOfflineRegion.h +++ b/platform/darwin/src/MGLShapeOfflineRegion.h @@ -10,6 +10,20 @@ NS_ASSUME_NONNULL_BEGIN An offline region defined by a style URL, geographic shape, and range of zoom levels. + ### Example + ```swift + 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!) + ``` + This class requires fewer resources than MGLTilePyramidOfflineRegion for irregularly shaped regions. */ diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index 009e8652c9..a57b963c63 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -25,7 +25,7 @@ typedef NSString *MGLShapeSourceOption NS_STRING_ENUM; This option only affects point features within an `MGLShapeSource` object; it is ignored when creating an `MGLComputedShapeSource` object. - + #### Related examples See the <a href="https://docs.mapbox.com/ios/maps/examples/clustering/">Cluster point data</a> and <a href="https://docs.mapbox.com/ios/maps/examples/clustering-with-images/">Use images to cluster point data</a> examples to learn how to cluster point data with this `MGLShapeSourceOption`. */ diff --git a/platform/darwin/src/MGLTilePyramidOfflineRegion.h b/platform/darwin/src/MGLTilePyramidOfflineRegion.h index 162636eda0..d04e656230 100644 --- a/platform/darwin/src/MGLTilePyramidOfflineRegion.h +++ b/platform/darwin/src/MGLTilePyramidOfflineRegion.h @@ -13,6 +13,17 @@ NS_ASSUME_NONNULL_BEGIN To minimize the resources required by an irregularly shaped offline region, use the MGLShapeOfflineRegion class instead. + ### Example + ```swift + 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!) + ``` + #### Related examples See the <a href="https://docs.mapbox.com/ios/maps/examples/offline-pack/"> Download an offline map</a> example to learn how to define an offline region 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) |