diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-01-11 08:06:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-11 08:06:20 -0800 |
commit | 424c12499cab69b935779d306d7d47d19139116e (patch) | |
tree | 56c27e57288a5df08083ede6b54db7204b46a02c /platform/darwin/test/MGLDocumentationExampleTests.swift | |
parent | 581fb3849da8ce97e557bb3633b886fcc369f6cb (diff) | |
download | qtlocation-mapboxgl-424c12499cab69b935779d306d7d47d19139116e.tar.gz |
[ios, macos] Make MGLMapView.style property nullable (#7664)
* [ios, macos] Made MGLMapView.style property nullable
MGLMapView’s style property is now nullable (optional in Swift). The property is set to nil while the style loads and in the event that the style has failed to load.
* [ios, macos] Switch to delegate method
* [macos] Create MGLMapView programmatically for layer tests
When MGLMapView is created via a nib, -initWithCoder: is called, causing styleURL to be set to nil, in turn causing the default Streets style to be loaded, fooling MGLStyleLayerTests into thinking one-line has been loaded. Instead, create MGLMapView programmatically, passing the intended style URL into the initializer, preventing Streets from being loaded.
Diffstat (limited to 'platform/darwin/test/MGLDocumentationExampleTests.swift')
-rw-r--r-- | platform/darwin/test/MGLDocumentationExampleTests.swift | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift index 65c145456a..5f0e83b2ca 100644 --- a/platform/darwin/test/MGLDocumentationExampleTests.swift +++ b/platform/darwin/test/MGLDocumentationExampleTests.swift @@ -68,10 +68,10 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { 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) + mapView.style?.addSource(source) //#-end-example-code - XCTAssertNotNil(mapView.style.source(withIdentifier: "lines")) + XCTAssertNotNil(mapView.style?.source(withIdentifier: "lines")) } func testMGLRasterSource() { @@ -84,10 +84,10 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] ]) - mapView.style.addSource(source) + mapView.style?.addSource(source) //#-end-example-code - XCTAssertNotNil(mapView.style.source(withIdentifier: "clouds")) + XCTAssertNotNil(mapView.style?.source(withIdentifier: "clouds")) } func testMGLVectorSource() { @@ -99,15 +99,15 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] ]) - mapView.style.addSource(source) + mapView.style?.addSource(source) //#-end-example-code - XCTAssertNotNil(mapView.style.source(withIdentifier: "pois")) + XCTAssertNotNil(mapView.style?.source(withIdentifier: "pois")) } func testMGLCircleStyleLayer() { let population = MGLVectorSource(identifier: "population", configurationURL: URL(string: "https://example.com/style.json")!) - mapView.style.addSource(population) + mapView.style?.addSource(population) //#-example-code let layer = MGLCircleStyleLayer(identifier: "circles", source: population) @@ -119,15 +119,15 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { ]) layer.circleOpacity = MGLStyleValue(rawValue: 0.7) layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married") - mapView.style.addLayer(layer) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "circles")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "circles")) } func testMGLLineStyleLayer() { let trails = MGLVectorSource(identifier: "trails", configurationURL: URL(string: "https://example.com/style.json")!) - mapView.style.addSource(trails) + mapView.style?.addSource(trails) //#-example-code let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails) @@ -139,30 +139,30 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { layer.lineColor = MGLStyleValue(rawValue: .brown) layer.lineCap = MGLStyleValue(rawValue: NSValue(mglLineCap: .round)) layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking") - mapView.style.addLayer(layer) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "trails-path")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "trails-path")) } func testMGLFillStyleLayer() { let parks = MGLVectorSource(identifier: "parks", configurationURL: URL(string: "https://example.com/style.json")!) - mapView.style.addSource(parks) + mapView.style?.addSource(parks) //#-example-code let layer = MGLFillStyleLayer(identifier: "parks", source: parks) layer.sourceLayerIdentifier = "parks" layer.fillColor = MGLStyleValue(rawValue: .green) layer.predicate = NSPredicate(format: "type == %@", "national-park") - mapView.style.addLayer(layer) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "parks")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "parks")) } func testMGLSymbolStyleLayer() { let pois = MGLVectorSource(identifier: "pois", configurationURL: URL(string: "https://example.com/style.json")!) - mapView.style.addSource(pois) + mapView.style?.addSource(pois) //#-example-code let layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois) @@ -179,10 +179,10 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { 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) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "coffeeshops")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "coffeeshops")) } func testMGLRasterStyleLayer() { @@ -194,28 +194,28 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate { MGLAttributionInfo(title: NSAttributedString(string: "© Mapbox"), url: URL(string: "http://mapbox.com")) ] ]) - mapView.style.addSource(source) + mapView.style?.addSource(source) //#-example-code let layer = MGLRasterStyleLayer(identifier: "clouds", source: source) layer.rasterOpacity = MGLStyleValue(rawValue: 0.5) - mapView.style.addLayer(layer) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "clouds")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "clouds")) } func testMGLVectorStyleLayer$predicate() { let terrain = MGLVectorSource(identifier: "terrain", configurationURL: URL(string: "https://example.com/style.json")!) - mapView.style.addSource(terrain) + mapView.style?.addSource(terrain) //#-example-code let layer = MGLLineStyleLayer(identifier: "contour", source: terrain) layer.sourceLayerIdentifier = "contours" layer.predicate = NSPredicate(format: "(index == 5 || index == 10) && ele >= 1500.0") - mapView.style.addLayer(layer) + mapView.style?.addLayer(layer) //#-end-example-code - XCTAssertNotNil(mapView.style.layer(withIdentifier: "contour")) + XCTAssertNotNil(mapView.style?.layer(withIdentifier: "contour")) } } |