Skip to content

Commit

Permalink
Add StyleManagerProtocol (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Rex committed May 5, 2021
1 parent 2118448 commit c29871e
Show file tree
Hide file tree
Showing 46 changed files with 534 additions and 339 deletions.
10 changes: 9 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,15 @@ jobs:
name: Build metrics tests
command: |
if [ -n "${CIRCLECI_METRICS_TOKEN}" ]; then
curl --fail -X POST --header "Content-Type: application/json" --data "{\"build_parameters\":{\"CIRCLE_JOB\":\"ios-maps-v10-build\",\"SOURCE_HASH\":\"${CIRCLE_SHA1}\",\"SOURCE_NAME\":\"ios-maps-v10\"}}" https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master?circle-token=${CIRCLECI_METRICS_TOKEN}
if [[ $CIRCLE_BRANCH == main ]]; then
curl --fail -X POST --header "Content-Type: application/json" --data "{\"build_parameters\":{\"CIRCLE_JOB\":\"ios-maps-v10-build\",\"SOURCE_HASH\":\"${CIRCLE_SHA1}\",\"SOURCE_NAME\":\"ios-maps-v10\"}}" https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master?circle-token=${CIRCLECI_METRICS_TOKEN}
else
echo "Trying $CIRCLE_BRANCH first:"
if ! curl --fail -X POST --header "Content-Type: application/json" --data "{\"build_parameters\":{\"CIRCLE_JOB\":\"ios-maps-v10-build\",\"SOURCE_HASH\":\"${CIRCLE_SHA1}\",\"SOURCE_NAME\":\"ios-maps-v10\"}}" https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/$CIRCLE_BRANCH?circle-token=${CIRCLECI_METRICS_TOKEN}; then
echo "Falling back to `master` branch:"
curl --fail -X POST --header "Content-Type: application/json" --data "{\"build_parameters\":{\"CIRCLE_JOB\":\"ios-maps-v10-build\",\"SOURCE_HASH\":\"${CIRCLE_SHA1}\",\"SOURCE_NAME\":\"ios-maps-v10\"}}" https://circleci.com/api/v1.1/project/github/mapbox/mobile-metrics/tree/master?circle-token=${CIRCLECI_METRICS_TOKEN}
fi
fi
else
echo "CIRCLECI_METRICS_TOKEN not provided"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public class AnimateGeoJSONLineExample: UIViewController, ExampleProtocol {
// Add the lineLayer to the map.
mapView.style.addSource(source: routeLineSource,
identifier: sourceIdentifier)
mapView.style.addLayer(layer: lineLayer)

try! mapView.style.addLayer(lineLayer)
}

func animatePolyline() {
Expand Down
4 changes: 2 additions & 2 deletions Apps/Examples/Examples/All Examples/AnimateLayerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public class AnimateLayerExample: UIViewController, ExampleProtocol {

// Add the sources and layers to the map style.
_ = mapView.style.addSource(source: airplaneRoute.source, identifier: airplaneRoute.identifier)
_ = mapView.style.addLayer(layer: lineLayer, layerPosition: nil)
try! mapView.style.addLayer(lineLayer, layerPosition: nil)

_ = mapView.style.addSource(source: airplaneSymbol.source, identifier: airplaneSymbol.identifier)
_ = mapView.style.addLayer(layer: airplaneSymbolLayer, layerPosition: nil)
try! mapView.style.addLayer(airplaneSymbolLayer, layerPosition: nil)
}

public func startAnimation(routeLine: LineString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public class BuildingExtrusionsExample: UIViewController, ExampleProtocol {
}
)

mapView.style.addLayer(layer: layer)
try! mapView.style.addLayer(layer)
}
}
4 changes: 2 additions & 2 deletions Apps/Examples/Examples/All Examples/CustomLayerExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class CustomLayerExample: UIViewController, ExampleProtocol {
// Position the custom layer above the water layer and below all other layers.
let layerPosition = LayerPosition(above: "water", below: nil, at: nil)

mapView.mapboxMap.__map.addStyleCustomLayer(
forLayerId: "Custom",
try! mapView.style.addCustomLayer(
withId: "Custom",
layerHost: self,
layerPosition: layerPosition)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class DataDrivenSymbolsExample: UIViewController, ExampleProtocol {

layer.layout?.iconImage = .expression(expression)

_ = mapView.style.addLayer(layer: layer, layerPosition: nil)
try! mapView.style.addLayer(layer, layerPosition: nil)

// The below line is used for internal testing purposes only.
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public class ExternalVectorSourceExample: UIViewController, ExampleProtocol {
// Define the layer's positioning within the layer stack so
// that it doesn't obscure other important labels.
let layerPosition = LayerPosition(above: nil, below: "waterway-label", at: nil)
let addLayerResult = mapView.style.addLayer(layer: lineLayer, layerPosition: layerPosition)

if case .failure(let sourceError) = addSourceResult {
displayAlert(message: sourceError.localizedDescription)
}

if case .failure(let layerError) = addLayerResult {
do {
try mapView.style.addLayer(lineLayer, layerPosition: layerPosition)
} catch let layerError {
displayAlert(message: layerError.localizedDescription)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class FeaturesAtPointExample: UIViewController, ExampleProtocol {

// Add the data source and style layer to the map.
_ = mapView.style.addSource(source: geoJSONSource, identifier: sourceIdentifier)
_ = mapView.style.addLayer(layer: fillLayer, layerPosition: nil)
try! mapView.style.addLayer(fillLayer, layerPosition: nil)

// Set up the tap gesture
addTapGesture(to: mapView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ public class FitCameraToGeometryExample: UIViewController, ExampleProtocol {
polygonLayer.source = sourceIdentifier

let addSourceResult = mapView.style?.addSource(source: source, identifier: sourceIdentifier)
let addLayerResult = mapView.style?.addLayer(layer: polygonLayer, layerPosition: nil)

if case .failure(let sourceError) = addSourceResult {
displayAlert(message: sourceError.localizedDescription)
}

if case .failure(let layerError) = addLayerResult {
do {
try mapView.style?.addLayer(polygonLayer, layerPosition: nil)
} catch let layerError {
displayAlert(message: layerError.localizedDescription)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public class GeoJSONSourceExample: UIViewController, ExampleProtocol {
polygonLayer.paint?.fillOutlineColor = .constant(ColorRepresentable(color: UIColor.purple))
// Add the source and style layers to the map style.
_ = mapView.style.addSource(source: geoJSONSource, identifier: geoJSONDataSourceIdentifier)
_ = mapView.style.addLayer(layer: circleLayer, layerPosition: nil)
_ = mapView.style.addLayer(layer: lineLayer, layerPosition: nil)
_ = mapView.style.addLayer(layer: polygonLayer, layerPosition: nil)
try! mapView.style.addLayer(circleLayer, layerPosition: nil)
try! mapView.style.addLayer(lineLayer, layerPosition: nil)
try! mapView.style.addLayer(polygonLayer, layerPosition: nil)

// The below line is used for internal testing purposes only.
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class LayerBelowExample: UIViewController, ExampleProtocol {
// Add the data source to the map
_ = mapView.style.addSource(source: source, identifier: sourceIdentifier)
// Add the layer to the map below the "settlement-label" layer
_ = mapView.style.addLayer(layer: layer, layerPosition: LayerPosition(below: "settlement-label"))
try! mapView.style.addLayer(layer, layerPosition: LayerPosition(below: "settlement-label"))

// The below line is used for internal testing purposes only.
finish()
Expand Down
26 changes: 13 additions & 13 deletions Apps/Examples/Examples/All Examples/LayerPositionExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@ public class LayerPositionExample: UIViewController, ExampleProtocol {

alert.addAction(UIAlertAction(title: "Above state label", style: .default, handler: { [weak self] _ in
guard let self = self else { return }
_ = self.mapView.style.removeStyleLayer(forLayerId: self.layer.id)
_ = self.mapView.style.addLayer(layer: self.layer,
layerPosition: LayerPosition(above: "state-label"))
try? self.mapView.style.removeLayer(withId: self.layer.id)
try? self.mapView.style.addLayer(self.layer,
layerPosition: LayerPosition(above: "state-label"))
}))

alert.addAction(UIAlertAction(title: "Below state label", style: .default, handler: { [weak self] _ in
guard let self = self else { return }
_ = self.mapView.style.removeStyleLayer(forLayerId: self.layer.id)
_ = self.mapView.style.addLayer(layer: self.layer,
layerPosition: LayerPosition(below: "state-label"))
try? self.mapView.style.removeLayer(withId: self.layer.id)
try? self.mapView.style.addLayer(self.layer,
layerPosition: LayerPosition(below: "state-label"))
}))

alert.addAction(UIAlertAction(title: "Above all", style: .default, handler: { [weak self] _ in
guard let self = self else { return }
_ = self.mapView.style.removeStyleLayer(forLayerId: self.layer.id)
_ = self.mapView.style.addLayer(layer: self.layer,
layerPosition: nil)
try? self.mapView.style.removeLayer(withId: self.layer.id)
try? self.mapView.style.addLayer(self.layer,
layerPosition: nil)
}))

alert.addAction(UIAlertAction(title: "Below all", style: .default, handler: { [weak self] _ in
guard let self = self else { return }
_ = self.mapView.style.removeStyleLayer(forLayerId: self.layer.id)
_ = self.mapView.style.addLayer(layer: self.layer,
layerPosition: LayerPosition(at: 0))
try? self.mapView.style.removeLayer(withId: self.layer.id)
try? self.mapView.style.addLayer(self.layer,
layerPosition: LayerPosition(at: 0))
}))

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
Expand Down Expand Up @@ -110,7 +110,7 @@ public class LayerPositionExample: UIViewController, ExampleProtocol {

_ = mapView.style.addSource(source: source, identifier: sourceIdentifier)
// If a layer position is not supplied, the layer is added above all other layers by default.
_ = mapView.style.addLayer(layer: layer, layerPosition: nil)
try! mapView.style.addLayer(layer, layerPosition: nil)

// The below line is used for internal testing purposes only.
finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ public class LineGradientExample: UIViewController, ExampleProtocol {

// Add the source and style layer to the map style.
mapView.style.addSource(source: geoJSONSource, identifier: geoJSONDataSourceIdentifier)
mapView.style.addLayer(layer: lineLayer, layerPosition: nil)
try! mapView.style.addLayer(lineLayer, layerPosition: nil)
}
}
6 changes: 3 additions & 3 deletions Apps/Examples/Examples/All Examples/SceneKitExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
}

func addModelAndTerrain() {
mapView.mapboxMap.__map.addStyleCustomLayer(
forLayerId: "Custom",
try! mapView.style.addCustomLayer(
withId: "Custom",
layerHost: self,
layerPosition: LayerPosition(above: nil, below: "waterway-label", at: nil))

Expand All @@ -57,7 +57,7 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost
skyLayer.paint?.skyAtmosphereSun = .constant([0, 0])
skyLayer.paint?.skyAtmosphereSunIntensity = .constant(15.0)

_ = self.mapView.style.addLayer(layer: skyLayer)
try! self.mapView.style.addLayer(skyLayer)

// Re-use terrain source for hillshade
let properties = [
Expand Down
2 changes: 1 addition & 1 deletion Apps/Examples/Examples/All Examples/TerrainExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public class TerrainExample: UIViewController, ExampleProtocol {
skyLayer.paint?.skyAtmosphereSun = .constant([0.0, 0.0])
skyLayer.paint?.skyAtmosphereSunIntensity = .constant(15.0)

_ = mapView.style.addLayer(layer: skyLayer)
try! mapView.style.addLayer(skyLayer)
}
}
4 changes: 4 additions & 0 deletions Mapbox/MapboxMaps.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
CA952ECE251C30B80099C080 /* MapboxMaps.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0CD34FCE242AADDB00943687 /* MapboxMaps.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
CA952F4B251C36CE0099C080 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CA952F4A251C36CD0099C080 /* Assets.xcassets */; };
CA99A8702540CD1900D16C78 /* StyleLoadIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA99A86E2540CD1900D16C78 /* StyleLoadIntegrationTests.swift */; };
CA9F8CE32641F95C00A8BCB6 /* StyleManagerProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA9F8CE22641F95C00A8BCB6 /* StyleManagerProtocol.swift */; };
CAA73A9D256F750B00E14EE0 /* FlyToTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAA73A9B256F750B00E14EE0 /* FlyToTests.swift */; };
CABCDF372620E03A00D61635 /* CredentialsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABCDF362620E03A00D61635 /* CredentialsManager.swift */; };
CABCDF422620E09E00D61635 /* MapConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = CABCDF402620E09D00D61635 /* MapConfig.swift */; };
Expand Down Expand Up @@ -735,6 +736,7 @@
CA9481552554AA9E00D93C3C /* TestConveniences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConveniences.swift; sourceTree = "<group>"; };
CA952F4A251C36CD0099C080 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
CA99A86E2540CD1900D16C78 /* StyleLoadIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StyleLoadIntegrationTests.swift; sourceTree = "<group>"; };
CA9F8CE22641F95C00A8BCB6 /* StyleManagerProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleManagerProtocol.swift; sourceTree = "<group>"; };
CAA73A9B256F750B00E14EE0 /* FlyToTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlyToTests.swift; sourceTree = "<group>"; };
CAB11C982555986F00060963 /* HTTPIntegrationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPIntegrationTests.swift; sourceTree = "<group>"; };
CABCDF362620E03A00D61635 /* CredentialsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CredentialsManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1442,6 +1444,7 @@
A4519DCE2432FF03007CF39A /* MapboxMapsStyle */ = {
isa = PBXGroup;
children = (
CA9F8CE22641F95C00A8BCB6 /* StyleManagerProtocol.swift */,
B5DDE95F2613ACB400998840 /* StyleEncodable.swift */,
0CBCF2D7254229630025F7B3 /* STYLE_README.md */,
0C708F3324EB1EFA003CE791 /* Layers.swift */,
Expand Down Expand Up @@ -2076,6 +2079,7 @@
0C088AC526387EA400107B5E /* DateProvider.swift in Sources */,
07BA35CE251578DD003E1B55 /* AnnotationInteractionDelegate.swift in Sources */,
2B8637E62463F36400698135 /* DistanceFormatter.swift in Sources */,
CA9F8CE32641F95C00A8BCB6 /* StyleManagerProtocol.swift in Sources */,
CA0C426926028ED30054D9D0 /* AnnotationOptions.swift in Sources */,
0C708F2F24EB1EE2003CE791 /* RasterLayer.swift in Sources */,
0C088AC026386D2700107B5E /* WeakCameraAnimatorSet.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public protocol AnnotationInteractionDelegate: class {
public protocol AnnotationInteractionDelegate: AnyObject {
func didSelectAnnotation(annotation: Annotation)
func didDeselectAnnotation(annotation: Annotation)
}
16 changes: 3 additions & 13 deletions Sources/MapboxMaps/Annotations/AnnotationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,7 @@ public class AnnotationManager {
"Point"
}

let expectedLayer = styleDelegate.addLayer(layer: symbolLayer, layerPosition: annotationOptions.layerPosition)

if case .failure(let layerError) = expectedLayer {
throw AnnotationError.addAnnotationFailed(layerError)
}
try styleDelegate.addLayer(symbolLayer, layerPosition: annotationOptions.layerPosition)

self.symbolLayer = symbolLayer
}
Expand All @@ -561,10 +557,7 @@ public class AnnotationManager {
"LineString"
}

if case .failure(let layerError) = styleDelegate.addLayer(layer: lineLayer, layerPosition: annotationOptions.layerPosition) {
throw AnnotationError.addAnnotationFailed(layerError)
}

try styleDelegate.addLayer(lineLayer, layerPosition: annotationOptions.layerPosition)
self.lineLayer = lineLayer
}

Expand All @@ -584,10 +577,7 @@ public class AnnotationManager {
"Polygon"
}

if case .failure(let layerError) = styleDelegate.addLayer(layer: fillLayer, layerPosition: annotationOptions.layerPosition) {
throw AnnotationError.addAnnotationFailed(layerError)
}

try styleDelegate.addLayer(fillLayer, layerPosition: annotationOptions.layerPosition)
self.fillLayer = fillLayer
}

Expand Down
3 changes: 1 addition & 2 deletions Sources/MapboxMaps/Annotations/AnnotationStyleDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ public protocol AnnotationStyleDelegate {
property: String,
value: [String: Any]) -> Result<Bool, SourceError>

func addLayer(layer: Layer,
layerPosition: LayerPosition?) -> Result<Bool, LayerError>
func addLayer(_ layer: Layer, layerPosition: LayerPosition?) throws
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import UIKit
public typealias AnimationCompletion = (UIViewAnimatingPosition) -> Void

// MARK: CameraAnimatorDelegate Protocol
internal protocol CameraAnimatorDelegate: class {
internal protocol CameraAnimatorDelegate: AnyObject {

/// The current camera of the map
var camera: CameraState { get }
Expand Down
Loading

0 comments on commit c29871e

Please sign in to comment.