diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h
index 42560652efd..657c5d9ad34 100644
--- a/platform/darwin/src/MGLCircleStyleLayer.h
+++ b/platform/darwin/src/MGLCircleStyleLayer.h
@@ -55,8 +55,8 @@ typedef NS_ENUM(NSUInteger, MGLCircleTranslateAnchor) {
22: MGLStyleValue(rawValue: 180)
])
layer.circleOpacity = MGLStyleValue(rawValue: 0.7)
- layer.predicate = NSPredicate(format: "%K == %@", "ethnicity", "ewok")
- mapView.style().add(layer)
+ layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married")
+ mapView.style.addLayer(layer)
```
*/
@interface MGLCircleStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h
index c6f1bd4a4ec..c91a2c6ef12 100644
--- a/platform/darwin/src/MGLFillStyleLayer.h
+++ b/platform/darwin/src/MGLFillStyleLayer.h
@@ -35,7 +35,7 @@ typedef NS_ENUM(NSUInteger, MGLFillTranslateAnchor) {
layer.sourceLayerIdentifier = "parks"
layer.fillColor = MGLStyleValue(rawValue: UIColor.green)
layer.predicate = NSPredicate(format: "type == %@", "national-park")
- mapView.style().add(layer)
+ mapView.style.addLayer(layer)
```
*/
@interface MGLFillStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h
index dc9fdf5c3ef..3af98a3acb6 100644
--- a/platform/darwin/src/MGLLineStyleLayer.h
+++ b/platform/darwin/src/MGLLineStyleLayer.h
@@ -74,13 +74,13 @@ typedef NS_ENUM(NSUInteger, MGLLineTranslateAnchor) {
let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails)
layer.sourceLayerIdentifier = "trails"
layer.lineWidth = MGLStyleValue(base: 1.5, stops: [
- 14: MGLStyleValue(rawValue: 2),
- 18: MGLStyleValue(rawValue: 20),
+ 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().add(layer)
+ layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking")
+ mapView.style.addLayer(layer)
```
*/
@interface MGLLineStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLRasterSource.h b/platform/darwin/src/MGLRasterSource.h
index 75b069aeb3c..469012a5683 100644
--- a/platform/darwin/src/MGLRasterSource.h
+++ b/platform/darwin/src/MGLRasterSource.h
@@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
tileset.attribution = "© Mapbox"
// Add source to map
let source = MGLRasterSource(identifier: "clouds", tileSet: tileset, tileSize: 512)
- mapView.style().add(source)
+ mapView.style.addSource(source)
```
@see The
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h
index a9148a0c123..bdd82d79d8d 100644
--- a/platform/darwin/src/MGLShapeSource.h
+++ b/platform/darwin/src/MGLShapeSource.h
@@ -70,10 +70,14 @@ extern const MGLShapeSourceOption MGLShapeSourceOptionSimplificationTolerance;
### Example ###
```swift
- var coordinates: [CLLocationCoordinate2D] = []
+ 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 source = MGLGeoJSONSource(identifier: "lines", features: [polyline], options: nil)
- self.mapView.style().add(source)
+ let shape = MGLShapeCollectionFeature(shapes: [polyline])
+ let source = MGLShapeSource(identifier: "lines", shape: shape, options: nil)
+ mapView.style.addSource(source)
```
@see The
diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h
index d6d19df8bd8..d9092581d2a 100644
--- a/platform/darwin/src/MGLSymbolStyleLayer.h
+++ b/platform/darwin/src/MGLSymbolStyleLayer.h
@@ -233,14 +233,14 @@ typedef NS_ENUM(NSUInteger, MGLTextTranslateAnchor) {
```swift
let layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois)
layer.sourceLayerIdentifier = "pois"
- layer.iconImage = MGLStyleValue(rawValue: "coffee")
- layer.iconSize = MGLStyleValue(rawValue: 0.5)
+ 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.textJustify = MGLStyleValue(rawValue: NSValue(mglTextJustify: .left))
layer.textAnchor = MGLStyleValue(rawValue: NSValue(mglTextAnchor: .left))
- layer.predicate = NSPredicate(format: "%K == %@", "venue-type" "coffee")
- mapView.style().add(layer)
+ layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee")
+ mapView.style.addLayer(layer)
```
*/
@interface MGLSymbolStyleLayer : MGLVectorStyleLayer
diff --git a/platform/darwin/src/MGLVectorSource.h b/platform/darwin/src/MGLVectorSource.h
index 795d91cd89b..5f38d238e87 100644
--- a/platform/darwin/src/MGLVectorSource.h
+++ b/platform/darwin/src/MGLVectorSource.h
@@ -30,7 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
tileset.attribution = "© Mapbox"
// Add source to map
let source = MGLVectorSource(identifier: "pois", tileSet: tileset)
- mapView.style().add(source)
+ mapView.style.addSource(source)
```
@see The
diff --git a/platform/darwin/src/MGLVectorStyleLayer.h b/platform/darwin/src/MGLVectorStyleLayer.h
index 24add3950e1..a5e3ee2b206 100644
--- a/platform/darwin/src/MGLVectorStyleLayer.h
+++ b/platform/darwin/src/MGLVectorStyleLayer.h
@@ -134,15 +134,10 @@ NS_ASSUME_NONNULL_BEGIN
you could create a predicate using `NSCompoundPredicate` along these lines:
```swift
- let meters = 1500.0
- let layer = MGLLineStyleLayer(identifier: "contour", source: contours)
- layer.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [
- NSCompoundPredicate(orPredicateWithSubpredicates: [
- NSPredicate(format: "%K == 10", "contour-index"),
- NSPredicate(format: "%K == 5", "contour-index"),
- ]),
- NSPredicate(format: "ele >= \(meters)"),
- ])
+ 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)
```
*/
@property (nonatomic, nullable) NSPredicate *predicate;
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj
index 6d778c571aa..4e01182bc2d 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 /* MBLDocumentationExampleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6407D66F1E0085FD00F6A9C3 /* MBLDocumentationExampleTests.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 */; };
@@ -603,6 +604,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 = ""; };
55D8C9951D0F18CE00F42F10 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
+ 6407D66F1E0085FD00F6A9C3 /* MBLDocumentationExampleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MBLDocumentationExampleTests.swift; sourceTree = ""; };
7E016D7C1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolyline+MGLAdditions.h"; sourceTree = ""; };
7E016D7D1D9E86BE00A29A21 /* MGLPolyline+MGLAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "MGLPolyline+MGLAdditions.m"; sourceTree = ""; };
7E016D821D9E890300A29A21 /* MGLPolygon+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MGLPolygon+MGLAdditions.h"; sourceTree = ""; };
@@ -1074,6 +1076,7 @@
DA35A2C31CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m */,
DA35A2C41CCA9F8300E826B2 /* MGLCompassDirectionFormatterTests.m */,
DA35A2A91CCA058D00E826B2 /* MGLCoordinateFormatterTests.m */,
+ 6407D66F1E0085FD00F6A9C3 /* MBLDocumentationExampleTests.swift */,
DA0CD58F1CF56F6A00A5F5A5 /* MGLFeatureTests.mm */,
DA2E885C1CC0382C00F24E7B /* MGLGeometryTests.mm */,
DA2DBBCC1D51E80400D38FF9 /* MGLStyleLayerTests.h */,
@@ -1757,7 +1760,7 @@
};
DA2E88501CC036F400F24E7B = {
CreatedOnToolsVersion = 7.3;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
DA8847D11CBAF91600AB86E3 = {
CreatedOnToolsVersion = 7.3;
@@ -1916,6 +1919,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 6407D6701E0085FD00F6A9C3 /* MBLDocumentationExampleTests.swift in Sources */,
DA2E88631CC0382C00F24E7B /* MGLOfflineRegionTests.m in Sources */,
3599A3E61DF708BC00E77FB2 /* MGLStyleValueTests.m in Sources */,
DA2E88651CC0382C00F24E7B /* MGLStyleTests.mm in Sources */,
@@ -2352,7 +2356,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
- SWIFT_VERSION = 3.0;
+ SWIFT_VERSION = 3.0.1;
};
name = Debug;
};
@@ -2374,7 +2378,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "../darwin/test/test-Bridging-Header.h";
- SWIFT_VERSION = 3.0;
+ SWIFT_VERSION = 3.0.1;
};
name = Release;
};
diff --git a/platform/ios/test/MBLDocumentationExampleTests.swift b/platform/ios/test/MBLDocumentationExampleTests.swift
new file mode 100644
index 00000000000..944a979691d
--- /dev/null
+++ b/platform/ios/test/MBLDocumentationExampleTests.swift
@@ -0,0 +1,147 @@
+import XCTest
+import Mapbox
+
+/**
+ Test cases that ensure the inline examples in the project documentation
+ compile. If any of these need to be changed, update the corresponding header
+ documentation accordingly.
+ */
+class MBLDocumentationExampleTests: 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()
+ }
+
+ // Example code in MGLShapeSource.h
+ func testMGLShapeSourceExample() {
+ 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)
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "lines"))
+ }
+
+ // Example code in MGLRasterSource.h
+ func testMGLRasterSourceExample() {
+ // Define tileset
+ let tileset = MGLTileSet(tileURLTemplates: ["https://example.com/raster-tiles/{z}/{x}/{y}.png"])
+ tileset.minimumZoomLevel = 9
+ tileset.maximumZoomLevel = 16
+ tileset.attribution = "© Mapbox"
+ // Add source to map
+ let source = MGLRasterSource(identifier: "clouds", tileSet: tileset, tileSize: 512)
+ mapView.style.addSource(source)
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "clouds"))
+ }
+
+ // Example code in MGLVectorSource.h
+ func testMGLVectorSource() {
+ // Define tileset
+ let tileset = MGLTileSet(tileURLTemplates: ["https://example.com/vector-tiles/{z}/{x}/{y}.mvt"])
+ tileset.minimumZoomLevel = 9
+ tileset.maximumZoomLevel = 16
+ tileset.attribution = "© Mapbox"
+ // Add source to map
+ let source = MGLVectorSource(identifier: "pois", tileSet: tileset)
+ mapView.style.addSource(source)
+
+ XCTAssertNotNil(mapView.style.source(withIdentifier: "pois"))
+ }
+
+ // Example code in MGLCircleStyleLayer.h
+ func testMGLCircleStyleLayerExample() {
+ let population = MGLVectorSource(identifier: "population", url: URL(string: "https://example.com")!)
+ mapView.style.addSource(population)
+
+ let layer = MGLCircleStyleLayer(identifier: "circles", source: population)
+ layer.sourceLayerIdentifier = "population"
+ layer.circleColor = MGLStyleValue(rawValue: UIColor.green)
+ layer.circleRadius = MGLStyleValue(base: 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)
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "circles"))
+ }
+
+ // Example code in MGLLineStyleLayer.h
+ func testMGLLineStyleLayerExample() {
+ let trails = MGLVectorSource(identifier: "trails", url: URL(string: "https://example.com")!)
+ mapView.style.addSource(trails)
+
+ let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails)
+ layer.sourceLayerIdentifier = "trails"
+ layer.lineWidth = MGLStyleValue(base: 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)
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "trails-path"))
+ }
+
+ // Example code in MGLFillStyleLayer.h
+ func testMGLFillStyleLayerExample() {
+ let parks = MGLVectorSource(identifier: "parks", url: URL(string: "https://example.com")!)
+ mapView.style.addSource(parks)
+
+ 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)
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "parks"))
+ }
+
+ // Example code in MGLSymbolStyleLayer.h
+ func testMGLSymbolStyleLayerExample() {
+ let pois = MGLVectorSource(identifier: "pois", url: URL(string: "https://example.com")!)
+ mapView.style.addSource(pois)
+
+ 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.textJustify = MGLStyleValue(rawValue: NSValue(mglTextJustify: .left))
+ layer.textAnchor = MGLStyleValue(rawValue: NSValue(mglTextAnchor: .left))
+ layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee")
+ mapView.style.addLayer(layer)
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "coffeeshops"))
+ }
+
+ // Example code in MGLVectorStyleLayer.h
+ func testMGLVectorStyleLayer() {
+ let terrain = MGLVectorSource(identifier: "terrain", url: URL(string: "https://example.com")!)
+ mapView.style.addSource(terrain)
+
+ 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)
+
+ XCTAssertNotNil(mapView.style.layer(withIdentifier: "contour"))
+ }
+}