summaryrefslogtreecommitdiff
path: root/platform/ios
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2017-01-04 12:19:31 -0800
committerGitHub <noreply@github.com>2017-01-04 12:19:31 -0800
commit50ae3eb3c0985567a0f86d08337d7cb8bed79a6c (patch)
tree969dd9b59f7dcbd17fa23e922fcefa5ba5de149c /platform/ios
parent63b1d652f826d786e7502beb0e2abb6d78e508d2 (diff)
downloadqtlocation-mapboxgl-50ae3eb3c0985567a0f86d08337d7cb8bed79a6c.tar.gz
[ios, macos] Insert example code in original headers (#7569)
* [ios, macos] Removed extraneous code fences * [ios] Streamlined example delimiters Use test method names as names of example blocks and test method documentation comments as front matter for examples. Set off example blocks using a syntax similar to playground markup syntax. Avoid hard-coding indentation levels. Trigger Xcode build error when an error occurs in the script. * [ios] Removed platform-specific code from examples * [ios] Fixed logic error The comment said 200 while the code said 1,500. * [ios] Formalize build phase input * [ios] Insert examples into original source documentation Rewrote the example code insertion script to work on the original source files and overwrite any existing code examples on the same symbols. The script uses SourceKitten to find the documentation comment for the symbol named by the test method. Replaced the Run Script build phase that runs the example code insertion script with a make rule that runs the same script. Inlined skeleton examples minus the contents of the code blocks. * [ios] Fixed syntax error * [ios] Ran ios-add-examples-to-docs * [ios] Avoid touching unchanged headers * [ios] Refactored example insertion script * [ios] Point jazzy at original sources * [ios] Invoke SourceKitten only once * [ios] Look for methods as well as properties * [ios] Thoroughly search for code blocks in doc comments Refactored the example code insertion script to index test methods by their names, then recursively search the SourceKitten output for documentation comments that contain Swift code blocks, replacing each code block with the associated test method body. * [ios, macos] Enabled example insertion for macOS The example code insertion script is now platform-agnostic. * [ios, macos] Fixed documentation example tests Set the map view’s style to a minimal local JSON file. Wait for the style to finish loading before running each test. Corrected CGVector type. * [ios, macos] Dry run mode The output of this mode isn’t a good indicator of whether any files would’ve needed to be changed, because the presence of a conditional compilation block in one of the test methods means this script would always change and revert the corresponding comment. * [ios] Fixed test failure The iOS implementation of MGLMapView tries to show the Streets style by default even if no access token has been set. Avoid a race condition and frequent test failure by specifying the minimal style on initialization. * [ios, macos] Ensure SourceKitten is installed before inserting example code * [ios, macos] Tear down map view after each test Keep map views from previous tests from hanging around, potentially obscuring the result of a subsequent test. Set the access token to a bogus token upfront for all style layer tests. Unified MGLStyle usage within MGLStyleTests. * [ios, macos] Reinsert examples after generating runtime styling headers
Diffstat (limited to 'platform/ios')
-rw-r--r--platform/ios/DEVELOPING.md16
-rw-r--r--platform/ios/ios.xcodeproj/project.pbxproj39
-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
6 files changed, 23 insertions, 308 deletions
diff --git a/platform/ios/DEVELOPING.md b/platform/ios/DEVELOPING.md
index 94ff49ee1b..f7bc0cc415 100644
--- a/platform/ios/DEVELOPING.md
+++ b/platform/ios/DEVELOPING.md
@@ -118,6 +118,22 @@ To add a localization to the iOS SDK:
1. In the Project navigator, expand each .strings and .stringsdict file in the project. An additional version for your localization should be listed; translate it. Translate everything on the right side of the equals sign. Leave the left side and any comments unmodified. See Apple’s documentation on the [.strings](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/Strings/Strings.html) and [.stringsdict](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPInternational/StringsdictFileFormat/StringsdictFileFormat.html) formats.
1. You’re already most of the way towards localizing the macOS SDK too – consider [completing that localization](../macos/DEVELOPING.md#adding-a-localization).
+### Adding a code example
+
+To add an example code listing to the documentation for a class or class member:
+
+1. Add a test method named in the form `testMGLClass` or `testMGLClass$method`
+ to [MGLDocumentationExampleTests](test/MGLDocumentationExampleTests.swift).
+ Wrap the code you’d like to appear in the documentation within
+ `//#-example-code` and `//#-end-example-code` comments.
+1. Insert the code listings into the headers:
+
+```bash
+make darwin-update-examples
+```
+
+[SourceKitten](https://github.com/jpsim/SourceKitten/) is required and will be installed automatically using Homebrew.
+
## Testing
`make ios-test` builds and runs unit tests of cross-platform code as well as the SDK.
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index ebcf3a55cb..8d96bcf497 100644
--- a/platform/ios/ios.xcodeproj/project.pbxproj
+++ b/platform/ios/ios.xcodeproj/project.pbxproj
@@ -228,6 +228,7 @@
DA35A2CA1CCAAAD200E826B2 /* NSValue+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = DA35A2C71CCAAAD200E826B2 /* NSValue+MGLAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA35A2CB1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; };
DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; };
+ DA35D0881E1A6309007DED41 /* one-liner.json in Resources */ = {isa = PBXBuildFile; fileRef = DA35D0871E1A6309007DED41 /* one-liner.json */; };
DA6408DB1DA4E7D300908C90 /* MGLVectorStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DA6408D91DA4E7D300908C90 /* MGLVectorStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA6408DC1DA4E7D300908C90 /* MGLVectorStyleLayer.h in Headers */ = {isa = PBXBuildFile; fileRef = DA6408D91DA4E7D300908C90 /* MGLVectorStyleLayer.h */; settings = {ATTRIBUTES = (Public, ); }; };
DA6408DD1DA4E7D300908C90 /* MGLVectorStyleLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = DA6408DA1DA4E7D300908C90 /* MGLVectorStyleLayer.m */; };
@@ -617,7 +618,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>"; };
+ 6407D66F1E0085FD00F6A9C3 /* MGLDocumentationExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MGLDocumentationExampleTests.swift; path = ../../darwin/test/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>"; };
@@ -669,6 +670,7 @@
DA35A2C71CCAAAD200E826B2 /* NSValue+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+MGLAdditions.h"; sourceTree = "<group>"; };
DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSValue+MGLAdditions.m"; sourceTree = "<group>"; };
DA35A2D11CCAB25200E826B2 /* jazzy.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = jazzy.yml; sourceTree = "<group>"; };
+ DA35D0871E1A6309007DED41 /* one-liner.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = "one-liner.json"; path = "../../darwin/test/one-liner.json"; sourceTree = "<group>"; };
DA4A26961CB6E795000B7809 /* Mapbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Mapbox.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DA6408D91DA4E7D300908C90 /* MGLVectorStyleLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLVectorStyleLayer.h; sourceTree = "<group>"; };
DA6408DA1DA4E7D300908C90 /* MGLVectorStyleLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLVectorStyleLayer.m; sourceTree = "<group>"; };
@@ -1110,6 +1112,7 @@
DA2E88601CC0382C00F24E7B /* MGLStyleTests.mm */,
DA2E88551CC036F400F24E7B /* Info.plist */,
DA2784FB1DF02FF4001D5B8D /* Media.xcassets */,
+ DA35D0871E1A6309007DED41 /* one-liner.json */,
);
name = "SDK Tests";
path = test;
@@ -1706,7 +1709,6 @@
DA8847CE1CBAF91600AB86E3 /* Frameworks */,
DA8847CF1CBAF91600AB86E3 /* Headers */,
DA8847D01CBAF91600AB86E3 /* Resources */,
- 64E5BF321E09D729005223F7 /* Add Examples to Documentation */,
);
buildRules = (
);
@@ -1741,7 +1743,6 @@
DAA4E4101CBB71D400178DFB /* Frameworks */,
DAA4E4111CBB71D400178DFB /* CopyFiles */,
DABFB85C1CBE99DE00D62B32 /* Headers */,
- 6421B07A1E09EA4B00AF169B /* Add Examples to Documentation */,
);
buildRules = (
);
@@ -1869,6 +1870,7 @@
files = (
DA2784FC1DF02FF4001D5B8D /* Media.xcassets in Resources */,
353BAEF71D646370009A8DA9 /* amsterdam.geojson in Resources */,
+ DA35D0881E1A6309007DED41 /* one-liner.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1934,37 +1936,6 @@
};
/* 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;
diff --git a/platform/ios/jazzy.yml b/platform/ios/jazzy.yml
index 1f1e48fce5..0a14cc3792 100644
--- a/platform/ios/jazzy.yml
+++ b/platform/ios/jazzy.yml
@@ -11,6 +11,8 @@ head: |
objc: Yes
skip_undocumented: Yes
hide_documentation_coverage: Yes
+umbrella_header: src/Mapbox.h
+framework_root: ../darwin/src
custom_categories:
- name: Guides
diff --git a/platform/ios/scripts/add-examples-to-docs.js b/platform/ios/scripts/add-examples-to-docs.js
deleted file mode 100644
index 7be755e2c6..0000000000
--- a/platform/ios/scripts/add-examples-to-docs.js
+++ /dev/null
@@ -1,65 +0,0 @@
-'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 634f4de5dc..ec349d592d 100755
--- a/platform/ios/scripts/document.sh
+++ b/platform/ios/scripts/document.sh
@@ -35,16 +35,11 @@ cp -r platform/ios/docs/img "${OUTPUT}/img"
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/guides/*.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
deleted file mode 100644
index 0d97cfeb35..0000000000
--- a/platform/ios/test/MGLDocumentationExampleTests.swift
+++ /dev/null
@@ -1,204 +0,0 @@
-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"))
- }
-}