summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wolfe <eric.r.wolfe@gmail.com>2016-12-21 10:22:13 -0800
committerGitHub <noreply@github.com>2016-12-21 10:22:13 -0800
commit9faa4af1c3cf0665ede20de8d98005ef9016b792 (patch)
tree39f2b2ab956798038271bf4a2507c5d6d6d1b9ea
parentb27dabfe472b633922c8beb615a80201ef5b8635 (diff)
downloadqtlocation-mapboxgl-9faa4af1c3cf0665ede20de8d98005ef9016b792.tar.gz
[ios] Add inline examples in documentation (#7337)
-rw-r--r--platform/darwin/src/MGLCircleStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLFillStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLLineStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLRasterSource.h3
-rw-r--r--platform/darwin/src/MGLRasterStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLShapeSource.h3
-rw-r--r--platform/darwin/src/MGLSource.h2
-rw-r--r--platform/darwin/src/MGLStyleLayer.h.ejs2
-rw-r--r--platform/darwin/src/MGLSymbolStyleLayer.h2
-rw-r--r--platform/darwin/src/MGLVectorSource.h2
-rw-r--r--platform/darwin/src/MGLVectorStyleLayer.h2
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj45
-rw-r--r--platform/ios/jazzy.yml2
-rw-r--r--platform/ios/scripts/add-examples-to-docs.js65
-rwxr-xr-xplatform/ios/scripts/document.sh5
-rw-r--r--platform/ios/test/MGLDocumentationExampleTests.swift204
16 files changed, 341 insertions, 4 deletions
diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h
index ddea62e5be..b57e245da2 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.h
+++ b/platform/darwin/src/MGLCircleStyleLayer.h
@@ -59,6 +59,8 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new circle style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGLCircleStyleLayer-->
*/
@interface MGLCircleStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h
index 01f1b17f97..2638e85aa5 100644
--- a/platform/darwin/src/MGLFillStyleLayer.h
+++ b/platform/darwin/src/MGLFillStyleLayer.h
@@ -37,6 +37,8 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new fill style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGLFillStyleLayer-->
*/
@interface MGLFillStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h
index c0f2eb322b..c3371aa2a7 100644
--- a/platform/darwin/src/MGLLineStyleLayer.h
+++ b/platform/darwin/src/MGLLineStyleLayer.h
@@ -87,6 +87,8 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) {
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new line style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGLLineStyleLayer-->
*/
@interface MGLLineStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLRasterSource.h b/platform/darwin/src/MGLRasterSource.h
index 262e8f2ce1..3efd84f383 100644
--- a/platform/darwin/src/MGLRasterSource.h
+++ b/platform/darwin/src/MGLRasterSource.h
@@ -35,6 +35,9 @@ extern const MGLTileSourceOption MGLTileSourceOptionTileSize;
`MGLRasterSource` object that you can use to initialize new style layers. You
can also add and remove sources dynamically using methods such as
`-[MGLStyle addSource:]` and `-[MGLStyle sourceWithIdentifier:]`.
+
+ <!--EXAMPLE: MGLRasterSource-->
+ ```
*/
@interface MGLRasterSource : MGLTileSource
diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h
index 52b2f8aff6..7b53eebf96 100644
--- a/platform/darwin/src/MGLRasterStyleLayer.h
+++ b/platform/darwin/src/MGLRasterStyleLayer.h
@@ -23,6 +23,8 @@ NS_ASSUME_NONNULL_BEGIN
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new raster style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGLRasterStyleLayer-->
*/
@interface MGLRasterStyleLayer : MGLForegroundStyleLayer
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h
index 68cb40a83f..0eb454437b 100644
--- a/platform/darwin/src/MGLShapeSource.h
+++ b/platform/darwin/src/MGLShapeSource.h
@@ -74,6 +74,9 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance;
Any vector style layer initialized with a shape source should have a `nil`
value in its `sourceLayerIdentifier` property.
+
+ <!--EXAMPLE: MGLShapeSource-->
+ ```
*/
@interface MGLShapeSource : MGLSource
diff --git a/platform/darwin/src/MGLSource.h b/platform/darwin/src/MGLSource.h
index 6b381fca19..03bb5fcba2 100644
--- a/platform/darwin/src/MGLSource.h
+++ b/platform/darwin/src/MGLSource.h
@@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
Do not create instances of this class directly, and do not create your own
subclasses of this class. Instead, create instances of `MGLShapeSource` and the
- concrete subclasses of `MGLTileSource`.
+ concrete subclasses of `MGLTileSource`, `MGLVectorSource` and `MGLRasterSource`.
*/
@interface MGLSource : NSObject
diff --git a/platform/darwin/src/MGLStyleLayer.h.ejs b/platform/darwin/src/MGLStyleLayer.h.ejs
index 2754cca1c5..ac95022ea7 100644
--- a/platform/darwin/src/MGLStyleLayer.h.ejs
+++ b/platform/darwin/src/MGLStyleLayer.h.ejs
@@ -67,6 +67,8 @@ typedef NS_ENUM(NSUInteger, MGL<%- camelize(property.name) %>) {
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new <%- type %> style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGL<%- camelize(type) %>StyleLayer-->
*/
<% } -%>
@interface MGL<%- camelize(type) %>StyleLayer : MGL<%-
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index a7b47ad2bb..052d67617a 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -260,6 +260,8 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) {
otherwise, find it using the `MGLStyle.layers` property. You can also create a
new symbol style layer and add it to the style using a method such as
`-[MGLStyle addLayer:]`.
+
+ <!--EXAMPLE: MGLSymbolStyleLayer-->
*/
@interface MGLSymbolStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLVectorSource.h b/platform/darwin/src/MGLVectorSource.h
index f91a0cbb23..ba8f075b5a 100644
--- a/platform/darwin/src/MGLVectorSource.h
+++ b/platform/darwin/src/MGLVectorSource.h
@@ -24,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
(<var>extent</var>&nbsp;×&nbsp;2)&nbsp;−&nbsp;1, inclusive. Any vector style
layer initialized with a vector source must have a non-`nil` value in its
`sourceLayerIdentifier` property.
+
+ <!--EXAMPLE: MGLVectorSource-->
*/
@interface MGLVectorSource : MGLTileSource
diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h
index 1197d76807..ff07a71a76 100644
--- a/platform/darwin/src/MGLVectorStyleLayer.h
+++ b/platform/darwin/src/MGLVectorStyleLayer.h
@@ -128,6 +128,8 @@ NS_ASSUME_NONNULL_BEGIN
style attributes and also `hyphen-minus` and `tag:subtag`. However, you must use
`%K` in the format string to represent these variables:
`@"%K == 'LineString'", @"$type"`.
+
+ <!--EXAMPLE: MGLVectorStyleLayer.predicate-->
*/
@property (nonatomic, nullable) NSPredicate *predicate;
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index c637cca7e8..c9cf5e7b1a 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -164,6 +164,7 @@
40FDA76B1CCAAA6800442548 /* MBXAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 40FDA76A1CCAAA6800442548 /* MBXAnnotationView.m */; };
554180421D2E97DE00012372 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 554180411D2E97DE00012372 /* OpenGLES.framework */; };
55D8C9961D0F18CE00F42F10 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */; };
+ 6407D6701E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */; };
7E016D7E1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */; };
7E016D7F1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */; };
7E016D801D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */; };
@@ -608,6 +609,7 @@
554180411D2E97DE00012372 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
55D8C9941D0F133500F42F10 /* config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = config.xcconfig; path = ../../build/ios/config.xcconfig; sourceTree = "<group>"; };
55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
+ 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MGLDocumentationExampleTests.swift; sourceTree = "<group>"; };
7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolyline+MGLAdditions.h"; sourceTree = "<group>"; };
7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = "<group>"; };
7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = "<group>"; };
@@ -1084,6 +1086,7 @@
DA35A2C31CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m */,
DA35A2C41CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m */,
DA35A2A91CCA058D00E826B2 /* MGLCoordinateFormatterTests.m */,
+ 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */,
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */,
DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */,
DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */,
@@ -1690,6 +1693,7 @@
DA8847CE1CBAF91600AB86E3 /* Frameworks */,
DA8847CF1CBAF91600AB86E3 /* Headers */,
DA8847D01CBAF91600AB86E3 /* Resources */,
+ 64E5BF321E09D729005223F7 /* Add Examples to Documentation */,
);
buildRules = (
);
@@ -1724,6 +1728,7 @@
DAA4E4101CBB71D400178DFB /* Frameworks */,
DAA4E4111CBB71D400178DFB /* CopyFiles */,
DABFB85C1CBE99DE00D62B32 /* Headers */,
+ 6421B07A1E09EA4B00AF169B /* Add Examples to Documentation */,
);
buildRules = (
);
@@ -1767,16 +1772,18 @@
TargetAttributes = {
DA1DC9491CB6C1C2006E619F = {
CreatedOnToolsVersion = 7.3;
+ LastSwiftMigration = 0820;
};
DA25D5B81CCD9EDE00607828 = {
CreatedOnToolsVersion = 7.3;
};
DA2E88501CC036F400F24E7B = {
CreatedOnToolsVersion = 7.3;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0820;
};
DA8847D11CBAF91600AB86E3 = {
CreatedOnToolsVersion = 7.3;
+ LastSwiftMigration = 0820;
};
DA8933D41CCD306400E68420 = {
CreatedOnToolsVersion = 7.3;
@@ -1913,6 +1920,37 @@
};
/* End PBXResourcesBuildPhase section */
+/* Begin PBXShellScriptBuildPhase section */
+ 6421B07A1E09EA4B00AF169B /* Add Examples to Documentation */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Add Examples to Documentation";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "node \"${SRCROOT}/scripts/add-examples-to-docs.js\"";
+ };
+ 64E5BF321E09D729005223F7 /* Add Examples to Documentation */ = {
+ isa = PBXShellScriptBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ inputPaths = (
+ );
+ name = "Add Examples to Documentation";
+ outputPaths = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ shellPath = /bin/sh;
+ shellScript = "node \"${SRCROOT}/scripts/add-examples-to-docs.js\"";
+ };
+/* End PBXShellScriptBuildPhase section */
+
/* Begin PBXSourcesBuildPhase section */
DA1DC9461CB6C1C2006E619F /* Sources */ = {
isa = PBXSourcesBuildPhase;
@@ -1932,6 +1970,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 6407D6701E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift in Sources */,
DA2E88631CC0382C00F24E7B /* MGLOfflineRegionTests.m in Sources */,
3599A3E61DF708BC00E77FB2 /* MGLStyleValueTests.m in Sources */,
DA2E88651CC0382C00F24E7B /* MGLStyleTests.mm in Sources */,
@@ -2314,6 +2353,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
PRODUCT_NAME = "Mapbox GL";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -2326,6 +2366,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL;
PRODUCT_NAME = "Mapbox GL";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -2422,6 +2463,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.sdk.ios;
PRODUCT_NAME = Mapbox;
SKIP_INSTALL = YES;
+ SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@@ -2455,6 +2497,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.sdk.ios;
PRODUCT_NAME = Mapbox;
SKIP_INSTALL = YES;
+ SWIFT_VERSION = 3.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml
index b41a7e118c..a777d8cef9 100644
--- a/platform/ios/jazzy.yml
+++ b/platform/ios/jazzy.yml
@@ -11,8 +11,6 @@ head: |
objc: Yes
skip_undocumented: Yes
hide_documentation_coverage: Yes
-umbrella_header: src/Mapbox.h
-framework_root: ../darwin/src
custom_categories:
- name: Maps
diff --git a/platform/ios/scripts/add-examples-to-docs.js b/platform/ios/scripts/add-examples-to-docs.js
new file mode 100644
index 0000000000..7be755e2c6
--- /dev/null
+++ b/platform/ios/scripts/add-examples-to-docs.js
@@ -0,0 +1,65 @@
+'use strict';
+
+const fs = require('fs');
+
+const examples = fs.readFileSync(`${__dirname}/../test/MGLDocumentationExampleTests.swift`, 'utf8');
+
+// Regex extracts the following block
+// /*---BEGIN EXAMPLE: MGLStyleSource---*/
+// /* Frontmatter to describe the example */
+// let sampleCode: String?
+// /*---END EXAMPLE---*/
+//
+// into the following regex groups:
+// 1 (token): " MGLStyleSource"
+// 2 (frontmatter): "/* Frontmatter to describe the example */"
+// 3 (sample code): "let sampleCode: String?"
+const exampleRegex = /\/\*---BEGIN EXAMPLE:(.*)---\*\/\s*(\/\*+[\s\S]*?\*+\/)?([\s\S]*?)\/\*---END EXAMPLE---\*\//gm;
+
+var path = `${process.env.TARGET_BUILD_DIR}/${process.env.PUBLIC_HEADERS_FOLDER_PATH}`;
+
+console.log("Installing examples...");
+
+var match;
+while ((match = exampleRegex.exec(examples)) !== null) {
+ const token = match[1].trim();
+ const className = token.split('.')[0];
+
+ const frontmatter = (match[2] || '')
+ .replace(/\/\*+/g, '') // Remove block comment /**
+ .replace(/\*+\//g, '') // Remove block comment end */
+ .trim()
+ .replace(/\n {8,9}/g, '\n'); // Remove leading whitespace (8-9 spaces incl block comment)
+
+ const exampleCode = match[3]
+ .trim()
+ .replace(/\n {8}/g, '\n'); // Remove leading whitespace (8 spaces)
+
+ // Generate example text
+ var exampleText = "### Example\n\n";
+ if (frontmatter.length > 0) {
+ exampleText += `${frontmatter}\n\n`;
+ }
+ exampleText += "```swift\n" + exampleCode + "\n```";
+ exampleText = exampleText.replace(/\n/g, '\n ');
+
+ const placeholderRegex = new RegExp(`<!--EXAMPLE: ${token}-->`);
+
+ // check if file exists at path
+ const filename = `${path}/${className}.h`;
+
+ if (fs.existsSync(filename)) {
+ const file = fs.readFileSync(filename, 'utf8');
+ // Check for example placeholder in file & update file if found
+ if (placeholderRegex.test(file)) {
+ console.log("Updating example:", filename);
+ fs.writeFileSync(filename, file.replace(placeholderRegex, exampleText));
+ } else if (file.indexOf(exampleText) === -1) {
+ console.log(`Placeholder "${token}" missing:`, filename);
+ } else {
+ console.log(`Example "${token}" already replaced.`);
+ }
+ } else if (token !== "ExampleToken") {
+ console.log("Error file doesn't exist:", filename);
+ }
+}
diff --git a/platform/ios/scripts/document.sh b/platform/ios/scripts/document.sh
index fddf5abb0f..78eb5121eb 100755
--- a/platform/ios/scripts/document.sh
+++ b/platform/ios/scripts/document.sh
@@ -35,11 +35,16 @@ cp platform/ios/screenshot.png "${OUTPUT}"
DEFAULT_THEME="platform/darwin/docs/theme"
THEME=${JAZZY_THEME:-$DEFAULT_THEME}
+DEFAULT_FRAMEWORK_PATH="build/ios/pkg/dynamic/Mapbox.framework"
+FRAMEWORK_PATH=${FRAMEWORK_PATH:-$DEFAULT_FRAMEWORK_PATH}
+
jazzy \
--config platform/ios/jazzy.yml \
--sdk iphonesimulator \
--github-file-prefix https://github.com/mapbox/mapbox-gl-native/tree/${BRANCH} \
--module-version ${SHORT_VERSION} \
+ --framework-root ${FRAMEWORK_PATH} \
+ --umbrella-header "${FRAMEWORK_PATH}/Headers/Mapbox.h" \
--readme ${README} \
--documentation="platform/ios/docs/Info.plist Keys.md" \
--root-url https://www.mapbox.com/ios-sdk/api/${RELEASE_VERSION}/ \
diff --git a/platform/ios/test/MGLDocumentationExampleTests.swift b/platform/ios/test/MGLDocumentationExampleTests.swift
new file mode 100644
index 0000000000..0d97cfeb35
--- /dev/null
+++ b/platform/ios/test/MGLDocumentationExampleTests.swift
@@ -0,0 +1,204 @@
+import XCTest
+import Mapbox
+import UIKit
+
+/**
+ Test cases that ensure the inline examples in the project documentation
+ compile.
+
+ There is a run script build phase for the dynamic & static iOS targets
+ that invokes `/platform/ios/scrips/add-examples-to-docs.js`. This script
+ will pull example code out of this test file and replace the corresponding
+ placeholder comment in the built header files.
+
+ Adding examples:
+ 1. Add a test case below
+ 2. Wrap the code you'd like to appear in the documentation within the
+ following comment blocks:
+ `/*---BEGIN EXAMPLE: ExampleToken---*/`
+ ...
+ `/*---END EXAMPLE---*/`
+ 3. Insert a comment `<!--EXAMPLE: ExampleToken-->` inside the header file
+ where you'd like the example code to be inserted
+ */
+class MGLDocumentationExampleTests: XCTestCase {
+ var mapView: MGLMapView!
+
+ override func setUp() {
+ super.setUp()
+ self.mapView = MGLMapView(frame: CGRect(x: 0, y: 0, width: 256, height: 256))
+ }
+
+ override func tearDown() {
+ self.mapView = nil
+ super.tearDown()
+ }
+
+ // MGLShapeSource
+ func testMGLShapeSourceExample() {
+ /*---BEGIN EXAMPLE: MGLShapeSource---*/
+ var coordinates: [CLLocationCoordinate2D] = [
+ CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42),
+ CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04),
+ ]
+ let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
+ let shape = MGLShapeCollectionFeature(shapes: [polyline])
+ let source = MGLShapeSource(identifier: "lines", shape: shape, options: nil)
+ mapView.style.addSource(source)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "lines"))
+ }
+
+ // MGLRasterSource
+ func testMGLRasterSourceExample() {
+ /*---BEGIN EXAMPLE: MGLRasterSource---*/
+ let source = MGLRasterSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [
+ .minimumZoomLevel: 9,
+ .maximumZoomLevel: 16,
+ .tileSize: 512,
+ .attributionInfos: [
+ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
+ ]
+ ])
+ mapView.style.addSource(source)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "clouds"))
+ }
+
+ // MGLVectorSource
+ func testMGLVectorSource() {
+ /*---BEGIN EXAMPLE: MGLVectorSource---*/
+ let source = MGLVectorSource(identifier: "pois", tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"], options: [
+ .minimumZoomLevel: 9,
+ .maximumZoomLevel: 16,
+ .attributionInfos: [
+ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
+ ]
+ ])
+ mapView.style.addSource(source)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "pois"))
+ }
+
+ // MGLCircleStyleLayer
+ func testMGLCircleStyleLayerExample() {
+ let population = MGLVectorSource(identifier: "population", configurationURL: URL(string: "https://example.com/style.json")!)
+ mapView.style.addSource(population)
+
+ /*---BEGIN EXAMPLE: MGLCircleStyleLayer---*/
+ let layer = MGLCircleStyleLayer(identifier: "circles", source: population)
+ layer.sourceLayerIdentifier = "population"
+ layer.circleColor = MGLStyleValue(rawValue: UIColor.green)
+ layer.circleRadius = MGLStyleValue(interpolationBase: 1.75, stops: [
+ 12: MGLStyleValue(rawValue: 2),
+ 22: MGLStyleValue(rawValue: 180)
+ ])
+ layer.circleOpacity = MGLStyleValue(rawValue: 0.7)
+ layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married")
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "circles"))
+ }
+
+ // MGLLineStyleLayer
+ func testMGLLineStyleLayerExample() {
+ let trails = MGLVectorSource(identifier: "trails", configurationURL: URL(string: "https://example.com/style.json")!)
+ mapView.style.addSource(trails)
+
+ /*---BEGIN EXAMPLE: MGLLineStyleLayer---*/
+ let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails)
+ layer.sourceLayerIdentifier = "trails"
+ layer.lineWidth = MGLStyleValue(interpolationBase: 1.5, stops: [
+ 14: MGLStyleValue(rawValue: 2),
+ 18: MGLStyleValue(rawValue: 20),
+ ])
+ layer.lineColor = MGLStyleValue(rawValue: UIColor.brown)
+ layer.lineCap = MGLStyleValue(rawValue: NSValue(mglLineCap: .round))
+ layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking")
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "trails-path"))
+ }
+
+ // MGLFillStyleLayer
+ func testMGLFillStyleLayerExample() {
+ let parks = MGLVectorSource(identifier: "parks", configurationURL: URL(string: "https://example.com/style.json")!)
+ mapView.style.addSource(parks)
+
+ /*---BEGIN EXAMPLE: MGLFillStyleLayer---*/
+ let layer = MGLFillStyleLayer(identifier: "parks", source: parks)
+ layer.sourceLayerIdentifier = "parks"
+ layer.fillColor = MGLStyleValue(rawValue: UIColor.green)
+ layer.predicate = NSPredicate(format: "type == %@", "national-park")
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "parks"))
+ }
+
+ // MGLSymbolStyleLayer
+ func testMGLSymbolStyleLayerExample() {
+ let pois = MGLVectorSource(identifier: "pois", configurationURL: URL(string: "https://example.com/style.json")!)
+ mapView.style.addSource(pois)
+
+ /*---BEGIN EXAMPLE: MGLSymbolStyleLayer---*/
+ let layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois)
+ layer.sourceLayerIdentifier = "pois"
+ layer.iconImageName = MGLStyleValue(rawValue: "coffee")
+ layer.iconScale = MGLStyleValue(rawValue: 0.5)
+ layer.textField = MGLStyleValue(rawValue: "{name}")
+ layer.textTranslate = MGLStyleValue(rawValue: NSValue(cgVector: CGVector(dx: 10, dy: 0)))
+ layer.textJustification = MGLStyleValue(rawValue: NSValue(mglTextJustification: .left))
+ layer.textAnchor = MGLStyleValue(rawValue: NSValue(mglTextAnchor: .left))
+ layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee")
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "coffeeshops"))
+ }
+
+ // MGLRasterStyleLayer
+ func testMGLRasterStyleLayer() {
+ let source = MGLRasterSource(identifier: "clouds", tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"], options: [
+ .minimumZoomLevel: 9,
+ .maximumZoomLevel: 16,
+ .tileSize: 512,
+ .attributionInfos: [
+ MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com"))
+ ]
+ ])
+ mapView.style.addSource(source)
+
+ /*---BEGIN EXAMPLE: MGLRasterStyleLayer---*/
+ let layer = MGLRasterStyleLayer(identifier: "clouds", source: source)
+ layer.rasterOpacity = MGLStyleValue(rawValue: 0.5)
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "clouds"))
+ }
+
+ // MGLVectorStyleLayer.predicate
+ func testMGLVectorStyleLayer() {
+ let terrain = MGLVectorSource(identifier: "terrain", configurationURL: URL(string: "https://example.com/style.json")!)
+ mapView.style.addSource(terrain)
+
+ /*---BEGIN EXAMPLE: MGLVectorStyleLayer.predicate---*/
+ /**
+ To create a filter with the logic `(index == 10 || index == 5) && ele >= 200`,
+ you could create a predicate using `NSCompoundPredicate` along these lines:
+ */
+ let layer = MGLLineStyleLayer(identifier: "contour", source: terrain)
+ layer.sourceLayerIdentifier = "contours"
+ layer.predicate = NSPredicate(format: "(index == 10 || index == 5) && ele >= 1500.0")
+ mapView.style.addLayer(layer)
+ /*---END EXAMPLE---*/
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "contour"))
+ }
+}