From 524649b6874c2dcc7757d9e74f40595b4d7cd677 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 13:34:56 -0400 Subject: [PATCH 01/19] BaseMapView and MapView public API cleanup --- .../DebugApp/DebugViewController.swift | 2 +- .../AnimateGeoJSONLineExample.swift | 2 +- .../All Examples/AnimateLayerExample.swift | 2 +- .../All Examples/BasicMapExample.swift | 2 +- .../BuildingExtrusionsExample.swift | 2 +- .../All Examples/CameraAnimationExample.swift | 2 +- .../All Examples/CameraAnimatorsExample.swift | 2 +- .../All Examples/ColorExpressionExample.swift | 2 +- .../All Examples/Custom2DPuckExample.swift | 2 +- .../All Examples/Custom3DPuckExample.swift | 2 +- .../All Examples/CustomLayerExample.swift | 2 +- .../CustomPointAnnotationExample.swift | 2 +- .../All Examples/CustomStyleURLExample.swift | 2 +- .../DataDrivenSymbolsExample.swift | 2 +- .../ExternalVectorSourceExample.swift | 2 +- .../All Examples/FeaturesAtPointExample.swift | 2 +- .../FitCameraToGeometryExample.swift | 2 +- .../Examples/All Examples/FlyToExample.swift | 2 +- .../All Examples/GeoJSONSourceExample.swift | 2 +- .../All Examples/LayerBelowExample.swift | 2 +- .../All Examples/LayerPositionExample.swift | 2 +- .../All Examples/LineAnnotationExample.swift | 2 +- .../All Examples/LineGradientExample.swift | 2 +- .../All Examples/MapViewExample.swift | 2 +- .../OfflineRegionManagerExample.swift | 2 +- .../All Examples/PointAnnotationExample.swift | 2 +- .../PolygonAnnotationExample.swift | 2 +- .../RestrictCoordinateBoundsExample.swift | 2 +- .../All Examples/SceneKitExample.swift | 2 +- .../SelectAnnotationExample.swift | 2 +- .../SnapshotterCoreGraphicsExample.swift | 2 +- .../All Examples/SnapshotterExample.swift | 2 +- .../All Examples/SwiftUIExample.swift | 2 +- .../All Examples/TerrainExample.swift | 2 +- .../All Examples/TrackingModeExample.swift | 2 +- ...UpdatePointAnnotationPositionExample.swift | 5 +- .../StressTest/ViewController.swift | 2 +- .../MapboxMaps/Foundation/BaseMapView.swift | 82 +------------------ .../MapboxMaps/Foundation/Events/Event.swift | 6 +- .../MapView/MapView+Supportable.swift | 6 +- Sources/MapboxMaps/MapView/MapView.swift | 8 +- 41 files changed, 51 insertions(+), 128 deletions(-) diff --git a/Apps/DebugApp/DebugApp/DebugViewController.swift b/Apps/DebugApp/DebugApp/DebugViewController.swift index 03375f3ecefa..f307666b17d4 100644 --- a/Apps/DebugApp/DebugApp/DebugViewController.swift +++ b/Apps/DebugApp/DebugApp/DebugViewController.swift @@ -25,7 +25,7 @@ public class DebugViewController: UIViewController { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.update { (mapOptions) in mapOptions.location.puckType = .puck2D() } diff --git a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift index c75a1ac22154..27f4bfa87efc 100644 --- a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift @@ -15,7 +15,7 @@ public class AnimateGeoJSONLineExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift index f865b4e7cd18..e5ff469d06ec 100644 --- a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift @@ -15,7 +15,7 @@ public class AnimateLayerExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/BasicMapExample.swift b/Apps/Examples/Examples/All Examples/BasicMapExample.swift index 9f3d53813b41..6ebf41a97a86 100644 --- a/Apps/Examples/Examples/All Examples/BasicMapExample.swift +++ b/Apps/Examples/Examples/All Examples/BasicMapExample.swift @@ -10,7 +10,7 @@ public class BasicMapExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.update { (mapOptions) in mapOptions.ornaments.showsScale = true diff --git a/Apps/Examples/Examples/All Examples/BuildingExtrusionsExample.swift b/Apps/Examples/Examples/All Examples/BuildingExtrusionsExample.swift index 550e0a09382b..6896b2fc702e 100644 --- a/Apps/Examples/Examples/All Examples/BuildingExtrusionsExample.swift +++ b/Apps/Examples/Examples/All Examples/BuildingExtrusionsExample.swift @@ -9,7 +9,7 @@ public class BuildingExtrusionsExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/CameraAnimationExample.swift b/Apps/Examples/Examples/All Examples/CameraAnimationExample.swift index 765194ea1d7f..13f2340415ce 100644 --- a/Apps/Examples/Examples/All Examples/CameraAnimationExample.swift +++ b/Apps/Examples/Examples/All Examples/CameraAnimationExample.swift @@ -15,7 +15,7 @@ public class CameraAnimationExample: UIViewController, ExampleProtocol { } let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift b/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift index bf5110df1f65..ba1b6844e01e 100644 --- a/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift +++ b/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift @@ -52,7 +52,7 @@ public class CameraAnimatorsExample: UIViewController, ExampleProtocol { } let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift index e3a93e74ae2a..049548b0f011 100644 --- a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift +++ b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift @@ -10,7 +10,7 @@ public class ColorExpressionExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift b/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift index a74a1e353b1b..458ca229843e 100644 --- a/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift +++ b/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift @@ -9,7 +9,7 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift b/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift index 114c21541998..c7b3fdf1d3b6 100644 --- a/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift +++ b/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift @@ -9,7 +9,7 @@ public class Custom3DPuckExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/CustomLayerExample.swift b/Apps/Examples/Examples/All Examples/CustomLayerExample.swift index eb509bfa5ee6..e416a0e90f7d 100644 --- a/Apps/Examples/Examples/All Examples/CustomLayerExample.swift +++ b/Apps/Examples/Examples/All Examples/CustomLayerExample.swift @@ -14,7 +14,7 @@ public class CustomLayerExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift b/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift index 88e83c619aaa..0dff1eb7bdfb 100644 --- a/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift @@ -10,7 +10,7 @@ public class CustomPointAnnotationExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/CustomStyleURLExample.swift b/Apps/Examples/Examples/All Examples/CustomStyleURLExample.swift index 5769cc6c0662..02170693c86d 100644 --- a/Apps/Examples/Examples/All Examples/CustomStyleURLExample.swift +++ b/Apps/Examples/Examples/All Examples/CustomStyleURLExample.swift @@ -14,7 +14,7 @@ internal class CustomStyleURLExample: UIViewController, ExampleProtocol { fatalError("Style URL is invalid") } - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: .custom(url: customStyleURL)) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: .custom(url: customStyleURL)) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift b/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift index 546448cc2a37..059d6948ee58 100644 --- a/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift +++ b/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift @@ -10,7 +10,7 @@ public class DataDrivenSymbolsExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: .outdoors) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: .outdoors) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift index 9cad6202b648..e070a989b600 100644 --- a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift +++ b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift @@ -8,7 +8,7 @@ public class ExternalVectorSourceExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.style.styleURI = .light let centerCoordinate = CLLocationCoordinate2D(latitude: 41.878781, longitude: -87.622088) diff --git a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift index 9f456299214c..1c867f8fe6c4 100644 --- a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift +++ b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift @@ -10,7 +10,7 @@ public class FeaturesAtPointExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/FitCameraToGeometryExample.swift b/Apps/Examples/Examples/All Examples/FitCameraToGeometryExample.swift index adfee214c6ad..b853426bacfc 100644 --- a/Apps/Examples/Examples/All Examples/FitCameraToGeometryExample.swift +++ b/Apps/Examples/Examples/All Examples/FitCameraToGeometryExample.swift @@ -16,7 +16,7 @@ public class FitCameraToGeometryExample: UIViewController, ExampleProtocol { } let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/FlyToExample.swift b/Apps/Examples/Examples/All Examples/FlyToExample.swift index 06628c944fcf..a6117f1ae223 100644 --- a/Apps/Examples/Examples/All Examples/FlyToExample.swift +++ b/Apps/Examples/Examples/All Examples/FlyToExample.swift @@ -11,7 +11,7 @@ public class FlyToExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/GeoJSONSourceExample.swift b/Apps/Examples/Examples/All Examples/GeoJSONSourceExample.swift index 650804d65df0..7d7256c5a90e 100644 --- a/Apps/Examples/Examples/All Examples/GeoJSONSourceExample.swift +++ b/Apps/Examples/Examples/All Examples/GeoJSONSourceExample.swift @@ -10,7 +10,7 @@ public class GeoJSONSourceExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/LayerBelowExample.swift b/Apps/Examples/Examples/All Examples/LayerBelowExample.swift index ec67a3411342..faea2207f5ca 100644 --- a/Apps/Examples/Examples/All Examples/LayerBelowExample.swift +++ b/Apps/Examples/Examples/All Examples/LayerBelowExample.swift @@ -10,7 +10,7 @@ public class LayerBelowExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) view.addSubview(mapView) // Center the map over downtown Atlanta diff --git a/Apps/Examples/Examples/All Examples/LayerPositionExample.swift b/Apps/Examples/Examples/All Examples/LayerPositionExample.swift index d851e5697236..3260bec8fdb2 100644 --- a/Apps/Examples/Examples/All Examples/LayerPositionExample.swift +++ b/Apps/Examples/Examples/All Examples/LayerPositionExample.swift @@ -13,7 +13,7 @@ public class LayerPositionExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift b/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift index b576e7424577..42486c052b89 100644 --- a/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift @@ -10,7 +10,7 @@ public class LineAnnotationExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/LineGradientExample.swift b/Apps/Examples/Examples/All Examples/LineGradientExample.swift index 9d12dbdf93a8..988d5bf6bfab 100644 --- a/Apps/Examples/Examples/All Examples/LineGradientExample.swift +++ b/Apps/Examples/Examples/All Examples/LineGradientExample.swift @@ -10,7 +10,7 @@ public class LineGradientExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/MapViewExample.swift b/Apps/Examples/Examples/All Examples/MapViewExample.swift index 893a6f43a363..7cd8566a4c80 100644 --- a/Apps/Examples/Examples/All Examples/MapViewExample.swift +++ b/Apps/Examples/Examples/All Examples/MapViewExample.swift @@ -7,7 +7,7 @@ public class MapViewExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - let mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + let mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) NSLayoutConstraint.activate([ diff --git a/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift b/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift index 3b2b43a22ffe..f4c704735104 100644 --- a/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift +++ b/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift @@ -18,7 +18,7 @@ public class OfflineRegionManagerExample: UIViewController, ExampleProtocol { super.viewDidLoad() print("This example uses a deprecated API, and will be removed in a future release.") - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: .light) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift b/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift index db49b7803c95..219d107eb049 100644 --- a/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift @@ -10,7 +10,7 @@ public class PointAnnotationExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift b/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift index a116c66e09de..1cee44066978 100644 --- a/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift @@ -9,7 +9,7 @@ public class PolygonAnnotationExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/RestrictCoordinateBoundsExample.swift b/Apps/Examples/Examples/All Examples/RestrictCoordinateBoundsExample.swift index 6dace26621b3..c5756dd0742f 100644 --- a/Apps/Examples/Examples/All Examples/RestrictCoordinateBoundsExample.swift +++ b/Apps/Examples/Examples/All Examples/RestrictCoordinateBoundsExample.swift @@ -9,7 +9,7 @@ public class RestrictCoordinateBoundsExample: UIViewController, ExampleProtocol override public func viewDidLoad() { super.viewDidLoad() - let mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + let mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/SceneKitExample.swift b/Apps/Examples/Examples/All Examples/SceneKitExample.swift index d4ceeba22a80..43cde79fbc8a 100644 --- a/Apps/Examples/Examples/All Examples/SceneKitExample.swift +++ b/Apps/Examples/Examples/All Examples/SceneKitExample.swift @@ -20,7 +20,7 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost override public func viewDidLoad() { super.viewDidLoad() - self.mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + self.mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(mapView) mapView.cameraManager.setCamera( diff --git a/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift b/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift index d274e538e812..a356c016f2be 100644 --- a/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift @@ -22,7 +22,7 @@ public class SelectAnnotationExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions()) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift b/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift index 82b958f58b3d..798214cb2102 100644 --- a/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift +++ b/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift @@ -15,7 +15,7 @@ public class SnapshotterCoreGraphicsExample: UIViewController, ExampleProtocol { // TODO: Fix crash that occurs when omitting MapViewController. let testRect = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height) - mapView = MapView(with: testRect, resourceOptions: resourceOptions()) + mapView = MapView(frame: testRect, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] // Add the `UIImageView` that will eventually render the snapshot. diff --git a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift index f0c3c07a6e50..12c9eb2d9f45 100644 --- a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift +++ b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift @@ -19,7 +19,7 @@ public class SnapshotterExample: UIViewController, ExampleProtocol { stackView.spacing = 12.0 let testRect = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height / 2) - mapView = MapView(with: testRect, resourceOptions: resourceOptions()) + mapView = MapView(frame: testRect, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.style.styleURI = .dark mapView.cameraManager.setCamera(centerCoordinate: CLLocationCoordinate2D(latitude: 37.858, longitude: 138.472), diff --git a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift index 97e08ad042fe..a21cd69f8e53 100644 --- a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift +++ b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift @@ -75,7 +75,7 @@ internal struct SwiftUIMapView: UIViewRepresentable { /// This method should create the `MapView`, and make sure that it is configured to be in sync /// with the current settings of `SwiftUIMapView` (in this example, just the `camera` and `styleURI`). func makeUIView(context: UIViewRepresentableContext) -> MapView { - let mapView = MapView(with: .zero, resourceOptions: resourceOptions) + let mapView = MapView(frame: .zero, resourceOptions: resourceOptions) updateUIView(mapView, context: context) /// Additionally, this is your opportunity to connect the coordinator to the map view. In this example diff --git a/Apps/Examples/Examples/All Examples/TerrainExample.swift b/Apps/Examples/Examples/All Examples/TerrainExample.swift index 99223a2146d5..1edb81b673e4 100644 --- a/Apps/Examples/Examples/All Examples/TerrainExample.swift +++ b/Apps/Examples/Examples/All Examples/TerrainExample.swift @@ -15,7 +15,7 @@ public class TerrainExample: UIViewController, ExampleProtocol { let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: view.bounds, + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions, styleURI: .custom(url: URL(string: "mapbox://styles/mapbox-map-design/ckhqrf2tz0dt119ny6azh975y")!)) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] diff --git a/Apps/Examples/Examples/All Examples/TrackingModeExample.swift b/Apps/Examples/Examples/All Examples/TrackingModeExample.swift index 8aa4be88b82e..52701c02aa90 100644 --- a/Apps/Examples/Examples/All Examples/TrackingModeExample.swift +++ b/Apps/Examples/Examples/All Examples/TrackingModeExample.swift @@ -13,7 +13,7 @@ public class TrackingModeExample: UIViewController, ExampleProtocol { override public func viewDidLoad() { super.viewDidLoad() - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions(), styleURI: StyleURI.streets) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions(), styleURI: StyleURI.streets) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift index 5e532afe4e00..3aaaf219084f 100644 --- a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift +++ b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift @@ -17,7 +17,7 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt } let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.cameraManager.setCamera(centerCoordinate: CLLocationCoordinate2D(latitude: 59.3, longitude: 8.06), zoom: 12) @@ -40,7 +40,8 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt } @objc public func updatePosition(_ sender: UITapGestureRecognizer) { - let newCoordinate = mapView.coordinate(for: sender.location(in: mapView)) + let screenCoordinate = mapView.convert(sender.location(in: mapView), to: mapView).screenCoordinate + let newCoordinate = try! mapView.__map.coordinateForPixel(forPixel: screenCoordinate) pointAnnotation.coordinate = newCoordinate do { diff --git a/Apps/StressTest/StressTest/ViewController.swift b/Apps/StressTest/StressTest/ViewController.swift index 405737fa2118..3c46025c3714 100644 --- a/Apps/StressTest/StressTest/ViewController.swift +++ b/Apps/StressTest/StressTest/ViewController.swift @@ -80,7 +80,7 @@ class ViewController: UIViewController { // Do any additional setup after loading the view. resourceOptions = ResourceOptions(accessToken: AccountManager.shared.accessToken!) - mapView = MapView(with: view.bounds, resourceOptions: resourceOptions, styleURI: .streets) + mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions, styleURI: .streets) view.addSubview(mapView) NSLayoutConstraint.activate([ mapView.leftAnchor.constraint(equalTo: view.leftAnchor), diff --git a/Sources/MapboxMaps/Foundation/BaseMapView.swift b/Sources/MapboxMaps/Foundation/BaseMapView.swift index 6bb57573698a..ee1521bae517 100644 --- a/Sources/MapboxMaps/Foundation/BaseMapView.swift +++ b/Sources/MapboxMaps/Foundation/BaseMapView.swift @@ -88,9 +88,9 @@ open class BaseMapView: UIView, MapClient, MBMMetalViewProvider, CameraViewDeleg /// List of completion blocks that need to be completed by the displayLink internal var pendingAnimatorCompletionBlocks: [PendingAnimationCompletion] = [] - public var needsDisplayRefresh: Bool = false - public var dormant: Bool = false - public var displayCallback: (() -> Void)? + internal var needsDisplayRefresh: Bool = false + internal var dormant: Bool = false + internal var displayCallback: (() -> Void)? private var observerConcrete: ObserverConcrete! @objc dynamic internal var displayLink: CADisplayLink? @@ -197,7 +197,7 @@ open class BaseMapView: UIView, MapClient, MBMMetalViewProvider, CameraViewDeleg } // MARK: Init - public init(with frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions, styleURI: URL?) { + public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions, styleURI: URL?) { super.init(frame: frame) self.commonInit(resourceOptions: resourceOptions, glyphsRasterizationOptions: glyphsRasterizationOptions, @@ -440,80 +440,6 @@ open class BaseMapView: UIView, MapClient, MBMMetalViewProvider, CameraViewDeleg return metalView } - - // MARK: Conversion utilities - /** - Converts a point in a given view’s coordinate system to a geographic coordinate. - - - Parameter point: The point to convert. - - Parameter view: An optional view the `point` is relative to. - Omitting this value assumes the point is relative to the `MapView`. - - Returns: A CLLocationCoordinate that represents the geographic location of the point. - */ - public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D { - let view = view ?? self - let screenCoordinate = convert(point, from: view).screenCoordinate // Transform to view's coordinate space - return try! __map.coordinateForPixel(forPixel: screenCoordinate) - } - - /** - Converts a map coordinate to a `CGPoint`, relative to the map view. - - - Parameter coordinate: The coordinate to convert. - - Parameter view: An optional view the resulting point will be relative to. - Omitting this value assumes resulting `CGPoint` will be expressed - relative to the `MapView`. - - Returns: A `CGPoint` relative to the `UIView`. - */ - public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint { - let view = view ?? self - let point = try! __map.pixelForCoordinate(for: coordinate).point - let transformedPoint = convert(point, to: view) - return transformedPoint - } - - /** - Transforms a view's frame into a set of coordinate bounds. - - - Parameter view: The `UIView` whose bounds will be transformed into a set of map coordinate bounds. - - Returns: A `CoordinateBounds` object that represents the southwest and northeast corners of the view's bounds. - */ - public func coordinateBounds(for view: UIView) -> CoordinateBounds { - let rect = view.bounds - - let topRight = coordinate(for: CGPoint(x: rect.maxX, y: rect.minY), in: view).wrap() - let bottomLeft = coordinate(for: CGPoint(x: rect.minX, y: rect.maxY), in: view).wrap() - - let southwest = CLLocationCoordinate2D(latitude: bottomLeft.latitude, longitude: bottomLeft.longitude) - let northeast = CLLocationCoordinate2D(latitude: topRight.latitude, longitude: topRight.longitude) - - return CoordinateBounds(southwest: southwest, northeast: northeast) - } - - /** - Transforms a set of map coordinate bounds to a `CGRect`. - - - Parameter view: An optional `UIView` whose coordinate space the resulting `CGRect` will be relative to. - Omitting this value assumes the resulting `CGRect` will be expressed - relative to the `MapView`. - - Returns: A `CGRect` whose corners represent the vertices of a set of `CoordinateBounds`. - */ - public func rect(for coordinateBounds: CoordinateBounds, in view: UIView? = nil) -> CGRect { - let view = view ?? self - let southwest = coordinateBounds.southwest.wrap() - let northeast = coordinateBounds.northeast.wrap() - - var rect = CGRect.zero - - let swPoint = point(for: southwest, in: view) - let nePoint = point(for: northeast, in: view) - - rect = CGRect(origin: swPoint, size: CGSize.zero) - - rect = rect.extend(from: nePoint) - - return rect - } } private class BaseMapViewProxy: NSObject { diff --git a/Sources/MapboxMaps/Foundation/Events/Event.swift b/Sources/MapboxMaps/Foundation/Events/Event.swift index befe34e3eb90..a4ebe0e6714c 100644 --- a/Sources/MapboxMaps/Foundation/Events/Event.swift +++ b/Sources/MapboxMaps/Foundation/Events/Event.swift @@ -27,10 +27,6 @@ public enum EventType { } } -public protocol EventsEmitter { - var eventsListener: EventsListener! { get set } -} - -public protocol EventsListener: AnyObject { +internal protocol EventsListener: AnyObject { func push(event: EventType) } diff --git a/Sources/MapboxMaps/MapView/MapView+Supportable.swift b/Sources/MapboxMaps/MapView/MapView+Supportable.swift index 0f7d8feda3c6..2bbb31eed35e 100644 --- a/Sources/MapboxMaps/MapView/MapView+Supportable.swift +++ b/Sources/MapboxMaps/MapView/MapView+Supportable.swift @@ -3,11 +3,11 @@ import CoreLocation extension MapView: OrnamentSupportableView { // User has tapped on an ornament - public func tapped() { + internal func tapped() { } - public func compassTapped() { + internal func compassTapped() { // Don't have access to CameraManager, so calling UIView.animate directly. UIView.animate(withDuration: 0.3, delay: 0.0, @@ -17,7 +17,7 @@ extension MapView: OrnamentSupportableView { }, completion: nil) } - public func subscribeCameraChangeHandler(_ handler: @escaping (CameraOptions) -> Void) { + internal func subscribeCameraChangeHandler(_ handler: @escaping (CameraOptions) -> Void) { on(.cameraChanged) { [weak self] _ in guard let validSelf = self else { return } handler(try! validSelf.__map.getCameraOptions(forPadding: nil)) diff --git a/Sources/MapboxMaps/MapView/MapView.swift b/Sources/MapboxMaps/MapView/MapView.swift index 2c2f5e15e7ab..adea86455ea5 100644 --- a/Sources/MapboxMaps/MapView/MapView.swift +++ b/Sources/MapboxMaps/MapView/MapView.swift @@ -1,7 +1,7 @@ import Foundation import Turf -open class MapView: BaseMapView, EventsEmitter { +open class MapView: BaseMapView { /// The `mapOptions` structure is the interface for consumers to configure the map. /// It's initialized on the creation of the `MapView` with a set of sane, default values. @@ -27,10 +27,10 @@ open class MapView: BaseMapView, EventsEmitter { public internal(set) var annotationManager: AnnotationManager! /// A reference to the `EventsManager` used for dispatching telemetry. - public var eventsListener: EventsListener! + internal var eventsListener: EventsListener! - public init(with frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets) { - super.init(with: frame, resourceOptions: resourceOptions, glyphsRasterizationOptions: glyphsRasterizationOptions, styleURI: styleURI?.url) + public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets) { + super.init(frame: frame, resourceOptions: resourceOptions, glyphsRasterizationOptions: glyphsRasterizationOptions, styleURI: styleURI?.url) initialize() } From 7909c42602c9917aca22c3cc1808ed2b81886d20 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 13:49:55 -0400 Subject: [PATCH 02/19] Ornaments api cleanup, removing unneeded tests, and fixing downstream effects in tests from function rename --- .../Configuration/LayoutPosition.swift | 36 ---- .../Configuration/LayoutVisibility.swift | 26 --- .../Configuration/OrnamentOptions.swift | 20 +-- .../Compass/CompassDirectionFormatter.swift | 6 +- .../Compass/MapboxCompassOrnamentView.swift | 6 +- .../MapboxMaps/Ornaments/OrnamentConfig.swift | 20 +-- .../ScaleBar/MapboxScaleBarLabel.swift | 4 +- .../ScaleBar/MapboxScaleBarOrnamentView.swift | 14 +- .../ScaleBar/MapbxoScaleBarConstants.swift | 20 +-- .../MapSnapshotOptions.swift | 0 .../Camera/MapboxMapsCameraTests.swift | 2 +- .../MapboxMapsFoundationTests.swift | 159 +----------------- .../Gestures/GestureManagerTests.swift | 2 +- .../Pucks/Puck3DIntegrationTests.swift | 2 +- .../Map/DidIdleFailureIntegrationTest.swift | 2 +- .../Map/MapViewIntegrationTests.swift | 4 +- .../MapViewIntegrationTestCase.swift | 2 +- .../MapView/Unit Tests/MapViewTests.swift | 4 +- 18 files changed, 55 insertions(+), 274 deletions(-) delete mode 100644 Sources/MapboxMaps/MapView/Configuration/LayoutPosition.swift delete mode 100644 Sources/MapboxMaps/MapView/Configuration/LayoutVisibility.swift rename Sources/MapboxMaps/{MapView/Configuration => Snapshot}/MapSnapshotOptions.swift (100%) diff --git a/Sources/MapboxMaps/MapView/Configuration/LayoutPosition.swift b/Sources/MapboxMaps/MapView/Configuration/LayoutPosition.swift deleted file mode 100644 index af1bf81245fb..000000000000 --- a/Sources/MapboxMaps/MapView/Configuration/LayoutPosition.swift +++ /dev/null @@ -1,36 +0,0 @@ -import Foundation - -/// Enum that provides options for positioning an ornament -public enum LayoutPosition: String, Equatable { - case topLeft - case topCenter - case topRight - case centerRight - case bottomRight - case bottomCenter - case bottomLeft - case centerLeft -} - -extension LayoutPosition { - internal var ornamentPosition: OrnamentPosition { - switch self { - case .topLeft: - return .topLeft - case .topCenter: - return .topCenter - case .topRight: - return .topRight - case .centerRight: - return .centerRight - case .bottomRight: - return .bottomRight - case .bottomCenter: - return .bottomCenter - case .bottomLeft: - return .bottomLeft - case .centerLeft: - return .centerLeft - } - } -} diff --git a/Sources/MapboxMaps/MapView/Configuration/LayoutVisibility.swift b/Sources/MapboxMaps/MapView/Configuration/LayoutVisibility.swift deleted file mode 100644 index d8cadd2c2d6f..000000000000 --- a/Sources/MapboxMaps/MapView/Configuration/LayoutVisibility.swift +++ /dev/null @@ -1,26 +0,0 @@ -import Foundation - -/// Constants indicating the visibility of different map ornaments. -public enum LayoutVisibility: String, Equatable { - /// A constant indicating that the ornament adapts to the current map state. - case adaptive - - /// A constant indicating that the ornament is always hidden. - case hidden - - /// A constant indicating that the ornament is always visible. - case visible -} - -extension LayoutVisibility { - internal var ornamentVisibility: OrnamentVisibility { - switch self { - case .adaptive: - return .adaptive - case .hidden: - return .hidden - case .visible: - return .visible - } - } -} diff --git a/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift b/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift index 5fcad794d31e..d1e788210349 100644 --- a/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift +++ b/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift @@ -7,23 +7,23 @@ public struct OrnamentOptions: Equatable { /// Scale Bar options public var showsScale: Bool = true - public var scaleBarPosition: LayoutPosition = .topLeft + public var scaleBarPosition: OrnamentPosition = .topLeft public var scaleBarMargins: CGPoint = defaultOrnamentsMargin /// Compass options public var showsCompass: Bool = true - public var compassViewPosition: LayoutPosition = .topRight + public var compassViewPosition: OrnamentPosition = .topRight public var compassViewMargins: CGPoint = defaultOrnamentsMargin - public var compassVisiblity: LayoutVisibility = .adaptive + public var compassVisiblity: OrnamentVisibility = .adaptive /// Logo view options public private(set) var showsLogoView: Bool = true - public var logoViewPosition: LayoutPosition = .bottomLeft + public var logoViewPosition: OrnamentPosition = .bottomLeft public var logoViewMargins: CGPoint = defaultOrnamentsMargin /// Attribution options public private(set) var showsAttributionButton: Bool = true - public var attributionButtonPosition: LayoutPosition = .bottomRight + public var attributionButtonPosition: OrnamentPosition = .bottomRight public var attributionButtonMargins: CGPoint = defaultOrnamentsMargin /// Used to generate the internal `OrnamentConfig` used by the `OrnamentsManager` to configure the map. @@ -34,23 +34,23 @@ public struct OrnamentOptions: Equatable { var ornamentVisibility: [OrnamentType: OrnamentVisibility] = [:] if showsScale { - supportedOrnaments[.mapboxScaleBar] = scaleBarPosition.ornamentPosition + supportedOrnaments[.mapboxScaleBar] = scaleBarPosition supportedOrnamentMargins[.mapboxScaleBar] = scaleBarMargins } if showsCompass { - supportedOrnaments[.compass] = compassViewPosition.ornamentPosition + supportedOrnaments[.compass] = compassViewPosition supportedOrnamentMargins[.compass] = compassViewMargins - ornamentVisibility[.compass] = compassVisiblity.ornamentVisibility + ornamentVisibility[.compass] = compassVisiblity } if showsLogoView { - supportedOrnaments[.mapboxLogoView] = logoViewPosition.ornamentPosition + supportedOrnaments[.mapboxLogoView] = logoViewPosition supportedOrnamentMargins[.mapboxLogoView] = logoViewMargins } if showsAttributionButton { - supportedOrnaments[.infoButton] = attributionButtonPosition.ornamentPosition + supportedOrnaments[.infoButton] = attributionButtonPosition supportedOrnamentMargins[.infoButton] = attributionButtonMargins } diff --git a/Sources/MapboxMaps/Ornaments/Compass/CompassDirectionFormatter.swift b/Sources/MapboxMaps/Ornaments/Compass/CompassDirectionFormatter.swift index 9f9606e52f21..8a480e49cf07 100644 --- a/Sources/MapboxMaps/Ornaments/Compass/CompassDirectionFormatter.swift +++ b/Sources/MapboxMaps/Ornaments/Compass/CompassDirectionFormatter.swift @@ -336,11 +336,11 @@ private enum Constants { }() } -public class CompassDirectionFormatter { +internal class CompassDirectionFormatter { private static let longStrings: [String] = [] - public var unitStyle: Formatter.UnitStyle = .medium + internal var unitStyle: Formatter.UnitStyle = .medium - public func string(from direction: CLLocationDirection) -> String { + internal func string(from direction: CLLocationDirection) -> String { assert(Constants.shortStrings.count == Constants.longStrings.count, "The numbers of short and long strings should be the same") let stringsCount = Constants.shortStrings.count diff --git a/Sources/MapboxMaps/Ornaments/Compass/MapboxCompassOrnamentView.swift b/Sources/MapboxMaps/Ornaments/Compass/MapboxCompassOrnamentView.swift index 57011a6df9db..2a22ba96a5b3 100644 --- a/Sources/MapboxMaps/Ornaments/Compass/MapboxCompassOrnamentView.swift +++ b/Sources/MapboxMaps/Ornaments/Compass/MapboxCompassOrnamentView.swift @@ -5,7 +5,7 @@ import UIKit import MapboxMapsFoundation #endif -public class MapboxCompassOrnamentView: UIButton { +internal class MapboxCompassOrnamentView: UIButton { private enum Constants { static let localizableTableName = "OrnamentsLocalizable" static let compassSize = CGSize(width: 40, height: 40) @@ -25,7 +25,7 @@ public class MapboxCompassOrnamentView: UIButton { private var lineColor: UIColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1) private let directionFormatter = CompassDirectionFormatter() /// Should be in range [-pi; pi] - public var currentBearing: CLLocationDirection = 0 { + internal var currentBearing: CLLocationDirection = 0 { didSet { let adjustedBearing = currentBearing.truncatingRemainder(dividingBy: 360) updateVisibility() @@ -33,7 +33,7 @@ public class MapboxCompassOrnamentView: UIButton { } } - required public init(visibility: OrnamentVisibility) { + required internal init(visibility: OrnamentVisibility) { super.init(frame: .zero) translatesAutoresizingMaskIntoConstraints = false self.visibility = visibility diff --git a/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift b/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift index 127dc73ecd37..0c606a0d57fc 100644 --- a/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift +++ b/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift @@ -1,13 +1,13 @@ import UIKit -public typealias OrnamentMargins = CGPoint +internal typealias OrnamentMargins = CGPoint -public class Ornament: Equatable { - public var view: UIView? - public let type: OrnamentType - public let position: OrnamentPosition - public let margins: OrnamentMargins - public let visibility: OrnamentVisibility +internal class Ornament: Equatable { + internal var view: UIView? + internal let type: OrnamentType + internal let position: OrnamentPosition + internal let margins: OrnamentMargins + internal let visibility: OrnamentVisibility convenience internal init(view: UIView?, type: OrnamentType, @@ -16,7 +16,7 @@ public class Ornament: Equatable { self.init(view: view, type: type, position: position, margins: .defaultMargins, visibility: visibility) } - public init(view: UIView?, + internal init(view: UIView?, type: OrnamentType, position: OrnamentPosition, margins: OrnamentMargins, @@ -28,12 +28,12 @@ public class Ornament: Equatable { self.visibility = visibility } - public static func == (lhs: Ornament, rhs: Ornament) -> Bool { + internal static func == (lhs: Ornament, rhs: Ornament) -> Bool { return lhs.type == rhs.type && lhs.position == rhs.position && lhs.margins == rhs.margins } } -public struct OrnamentConfig: Equatable { +internal struct OrnamentConfig: Equatable { internal let ornaments: [Ornament] /** diff --git a/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarLabel.swift b/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarLabel.swift index bc512f6c68f1..7d789b4a86b7 100644 --- a/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarLabel.swift +++ b/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarLabel.swift @@ -1,8 +1,8 @@ import UIKit -public class MapboxScaleBarLabel: UILabel { +internal class MapboxScaleBarLabel: UILabel { - override public func drawText(in rect: CGRect) { + override internal func drawText(in rect: CGRect) { let originalShadowOffset = shadowOffset let context = UIGraphicsGetCurrentContext() diff --git a/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarOrnamentView.swift b/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarOrnamentView.swift index 9e31e89bf030..70d9aa9e1d2a 100644 --- a/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarOrnamentView.swift +++ b/Sources/MapboxMaps/Ornaments/ScaleBar/MapboxScaleBarOrnamentView.swift @@ -5,13 +5,13 @@ import CoreLocation import MapboxMapsFoundation #endif -public class MapboxScaleBarOrnamentView: UIView { +internal class MapboxScaleBarOrnamentView: UIView { - public typealias Row = (distance: CLLocationDistance, numberOfBars: UInt) + internal typealias Row = (distance: CLLocationDistance, numberOfBars: UInt) // MARK: - Properties - public var metersPerPoint: CLLocationDistance = 1 { + internal var metersPerPoint: CLLocationDistance = 1 { didSet { guard metersPerPoint != oldValue else { return @@ -105,7 +105,7 @@ public class MapboxScaleBarOrnamentView: UIView { return Locale(identifier: Bundle.main.preferredLocalizations.first!).usesMetricSystem } - public override var intrinsicContentSize: CGSize { + internal override var intrinsicContentSize: CGSize { // Size is calculated elsewhere - since 'intrinsicContentSize' is part of the // constraint system, this should be done in 'updateConstraints' guard size.width >= 0 else { @@ -116,7 +116,7 @@ public class MapboxScaleBarOrnamentView: UIView { // MARK: - Initialization - override public init(frame: CGRect) { + override internal init(frame: CGRect) { super.init(frame: frame) commonInit() } @@ -149,7 +149,7 @@ public class MapboxScaleBarOrnamentView: UIView { // current 'row', which in turn determines the "actualWidth". To obtain the full // width of the scale bar, we also need to include some space for the "last" // label - public override func updateConstraints() { + internal override func updateConstraints() { guard !isHidden && needsRecalculateSize else { super.updateConstraints() return @@ -185,7 +185,7 @@ public class MapboxScaleBarOrnamentView: UIView { super.updateConstraints() // This calls intrinsicContentSize } - public override func layoutSubviews() { + internal override func layoutSubviews() { super.layoutSubviews() guard needsRecalculateSize else { diff --git a/Sources/MapboxMaps/Ornaments/ScaleBar/MapbxoScaleBarConstants.swift b/Sources/MapboxMaps/Ornaments/ScaleBar/MapbxoScaleBarConstants.swift index 90b845cd8e1e..4ded484c0580 100644 --- a/Sources/MapboxMaps/Ornaments/ScaleBar/MapbxoScaleBarConstants.swift +++ b/Sources/MapboxMaps/Ornaments/ScaleBar/MapbxoScaleBarConstants.swift @@ -3,18 +3,18 @@ import UIKit extension MapboxScaleBarOrnamentView { struct Constants { - public static let primaryColor: UIColor = #colorLiteral(red: 0.07058823529, green: 0.1764705882, blue: 0.06666666667, alpha: 1) - public static let secondaryColor: UIColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1) - public static let borderWidth: CGFloat = 1 + internal static let primaryColor: UIColor = #colorLiteral(red: 0.07058823529, green: 0.1764705882, blue: 0.06666666667, alpha: 1) + internal static let secondaryColor: UIColor = #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1) + internal static let borderWidth: CGFloat = 1 - public static let feetPerMile: Double = 5280 - public static let feetPerMeter: Double = 3.28084 + internal static let feetPerMile: Double = 5280 + internal static let feetPerMeter: Double = 3.28084 - public static let barHeight: CGFloat = 4 - public static let scaleBarLabelWidthHint: CGFloat = 30.0 - public static let scaleBarMinimumBarWidth: CGFloat = 30.0 // Arbitrary + internal static let barHeight: CGFloat = 4 + internal static let scaleBarLabelWidthHint: CGFloat = 30.0 + internal static let scaleBarMinimumBarWidth: CGFloat = 30.0 // Arbitrary - public static let metricTable: [Row] = [ + internal static let metricTable: [Row] = [ (distance: 1, numberOfBars: 2), (distance: 2, numberOfBars: 2), (distance: 4, numberOfBars: 2), @@ -44,7 +44,7 @@ extension MapboxScaleBarOrnamentView { (distance: 800000, numberOfBars: 2) ] - public static let imperialTable: [Row] = [ + internal static let imperialTable: [Row] = [ (distance: 4, numberOfBars: 2), (distance: 6, numberOfBars: 2), (distance: 10, numberOfBars: 2), diff --git a/Sources/MapboxMaps/MapView/Configuration/MapSnapshotOptions.swift b/Sources/MapboxMaps/Snapshot/MapSnapshotOptions.swift similarity index 100% rename from Sources/MapboxMaps/MapView/Configuration/MapSnapshotOptions.swift rename to Sources/MapboxMaps/Snapshot/MapSnapshotOptions.swift diff --git a/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift b/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift index 6476def837f3..6e3eb036c6bb 100644 --- a/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift @@ -15,7 +15,7 @@ class CameraManagerTests: XCTestCase { override func setUp() { resourceOptions = ResourceOptions(accessToken: "pk.feedcafedeadbeefbadebede") - mapView = BaseMapView(with: CGRect(x: 0, y: 0, width: 100, height: 100), + mapView = BaseMapView(frame: CGRect(x: 0, y: 0, width: 100, height: 100), resourceOptions: resourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions.default, styleURI: nil) diff --git a/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift b/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift index f2596a313a58..6c389a86a8d1 100644 --- a/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift +++ b/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift @@ -25,7 +25,7 @@ class MapboxMapsFoundationTests: XCTestCase { Test with offset bounds */ let resourceOptions = ResourceOptions(accessToken: "a1b2c3") - mapView = BaseMapView(with: CGRect(x: 10, y: 10, width: 100, height: 100), + mapView = BaseMapView(frame: CGRect(x: 10, y: 10, width: 100, height: 100), resourceOptions: resourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions.default, styleURI: nil) @@ -56,125 +56,6 @@ class MapboxMapsFoundationTests: XCTestCase { XCTAssertEqual(coordinate.longitude, coordinate.wrap().longitude) } - // MARK: Converting between points and coordinates - - func testCoordinateToPoint() { - let centerCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) - let convertedPoint = mapView.point(for: centerCoordinate, in: mapView) - - XCTAssertEqual(convertedPoint.x, mapView.bounds.midX, accuracy: 0.01) - XCTAssertEqual(convertedPoint.y, mapView.bounds.midY, accuracy: 0.01) - } - - func testPointToCoordinateInSubviewWithEqualCenter() { - let subView = UIView(frame: mapView.bounds) - mapView.addSubview(subView) - - // Convert the subview's center to a coordinate. - // The subview's center is expected to be at the center coordinate of the map. - let center = CGPoint(x: subView.bounds.midX, y: subView.bounds.midY) - let coordinate = mapView.coordinate(for: center, in: subView) - - XCTAssertEqual(coordinate.latitude, CLLocationDegrees(0), accuracy: accuracy) - XCTAssertEqual(coordinate.longitude, CLLocationDegrees(0), accuracy: accuracy) - } - - func testPointToCoordinateInSubViewEqualOrigins() { - let subViewRect = CGRect(x: 0, - y: 0, - width: mapView.bounds.size.width / 2, - height: mapView.bounds.size.height / 2) - let subview = UIView(frame: subViewRect) - - mapView.addSubview(subview) - - /** - We shouldn't expect the centers to be the same, since now that the - mapView is offset. The "center" is in the space of the parent view. - */ - subview.center = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) - XCTAssertNotEqual(subview.center, mapView.center, "Center of both views are not equal") - XCTAssertEqual(subview.frame.origin.x, 25.0) - XCTAssertEqual(subview.frame.origin.y, 25.0) - - let updatedSubViewOrigin = subview.frame.origin - let originCoordinateA = mapView.coordinate(for: updatedSubViewOrigin, in: mapView) - let originCoordinateB = mapView.coordinate(for: CGPoint.zero, in: subview) - - XCTAssertEqual(originCoordinateA.latitude, originCoordinateB.latitude, accuracy: accuracy) - XCTAssertEqual(originCoordinateA.longitude, originCoordinateB.longitude, accuracy: accuracy) - - // The subview's origin is expected to be 1/4 of the map view's height and width -// let expectedSubViewOrigin = CGPoint(x: mapView.bounds.width * 0.25, y: mapView.bounds.height * 0.25) -// let convertedSubViewOrigin = mapView.convert(expectedSubViewOrigin, to: subview) -// // So this should be zero -// XCTAssertEqual(convertedSubViewOrigin, .zero) -// -// let originCoordinateC = mapView.convert(convertedSubViewOrigin, toCoordinateFrom: subview) -// -// XCTAssertEqual(originCoordinateB.latitude, originCoordinateC.latitude, accuracy: accuracy) -// XCTAssertEqual(originCoordinateB.longitude, originCoordinateC.longitude, accuracy: accuracy) -// -// XCTAssertEqual(originCoordinateA.latitude, originCoordinateC.latitude, accuracy: accuracy) -// XCTAssertEqual(originCoordinateA.longitude, originCoordinateC.longitude, accuracy: accuracy) - } - - func testPointToCoordinateWithBoundsShifted() { - // Shift bounds down and right 1/2 of the map's size - mapView.bounds = CGRect(x: mapView.frame.midX, - y: mapView.frame.midY, - width: mapView.frame.width, - height: mapView.frame.height) - - let mapViewFrameCenterPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) - let mapViewFrameCenterCoordinate = mapView.coordinate(for: mapViewFrameCenterPoint, in: mapView) - let mapViewBoundsOriginCoordinate = mapView.coordinate(for: mapView.bounds.origin, in: mapView) - - XCTAssertEqual(mapViewFrameCenterCoordinate.latitude, - mapViewBoundsOriginCoordinate.latitude, - accuracy: accuracy) - XCTAssertEqual(mapViewFrameCenterCoordinate.longitude, - mapViewBoundsOriginCoordinate.longitude, - accuracy: accuracy) - } - - func testPointToCoordinateWithBoundsShifted2() { - let originalCenter = mapView.center - let originalMapViewBoundsCenterPoint = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) - let originalMapViewBoundsCenterCoordinate = mapView.coordinate(for: originalMapViewBoundsCenterPoint, - in: mapView) - - // Shift bounds by some arbitrary offset - mapView.bounds = CGRect(x: 30, - y: -30, - width: mapView.frame.width, - height: mapView.frame.height) - - let mapViewFrameCenterPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) - let mapViewBoundsCenterPoint = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) - - // Frame should not have changed, since we're only changing the bounds - XCTAssertEqual(originalCenter, mapView.center) - XCTAssertEqual(originalCenter, mapViewFrameCenterPoint) - - let mapViewBoundsCenterCoordinate = mapView.coordinate(for: mapViewBoundsCenterPoint, in: mapView) - - // Adjusting the bounds should affect the coordinate conversion - XCTAssertNotEqual(originalMapViewBoundsCenterCoordinate.latitude, mapViewBoundsCenterCoordinate.latitude) - XCTAssertNotEqual(originalMapViewBoundsCenterCoordinate.longitude, mapViewBoundsCenterCoordinate.longitude) - } - - func testConvertCoordinateRoundTrip() { - // Convert a point to a coordinate and back to a point - let originalPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) - - let coordinate = mapView.coordinate(for: originalPoint, in: mapView) - let point = mapView.point(for: coordinate, in: mapView) - - XCTAssertEqual(originalPoint.x, point.x, accuracy: CGFloat(accuracy)) - XCTAssertEqual(originalPoint.y, point.y, accuracy: CGFloat(accuracy)) - } - // MARK: Converting between CGRect and coordinate bounds func testRectExtend() { @@ -189,44 +70,6 @@ class MapboxMapsFoundationTests: XCTestCase { XCTAssertEqual(expectedRect, actualRect) } - func testCoordinateBoundsToRect() { - let southwest = CLLocationCoordinate2D(latitude: -20, longitude: -20) - let northeast = CLLocationCoordinate2D(latitude: 20, longitude: 20) - - let bounds = CoordinateBounds(southwest: southwest, northeast: northeast) - - let southeast = bounds.southeast - let northwest = bounds.northwest - - let rect = mapView.rect(for: bounds, in: mapView) - - // Test southwest points - let swPoint = mapView.point(for: southwest, in: mapView) - let swRect = CGPoint(x: rect.minX, y: rect.maxY) - - XCTAssertEqual(swPoint.x, swRect.x, accuracy: 0.1) - XCTAssertEqual(swPoint.y, swRect.y, accuracy: 0.1) - - // Test southeast points - let sePoint = mapView.point(for: southeast, in: mapView) - let seRect = CGPoint(x: rect.maxX, y: rect.maxY) - - XCTAssertEqual(sePoint.x, seRect.x, accuracy: 0.1) - XCTAssertEqual(sePoint.y, seRect.y, accuracy: 0.1) - - // Test northwest points - let nwPoint = mapView.point(for: northwest, in: mapView) - let nwRect = CGPoint(x: rect.minX, y: rect.minY) - XCTAssertEqual(nwPoint.x, nwRect.x, accuracy: 0.1) - XCTAssertEqual(nwPoint.y, nwRect.y, accuracy: 0.1) - - // Test northeast points - let nePoint = mapView.point(for: northeast, in: mapView) - let neRect = CGPoint(x: rect.maxX, y: rect.minY) - XCTAssertEqual(nePoint.x, neRect.x, accuracy: 0.1) - XCTAssertEqual(nePoint.y, neRect.y, accuracy: 0.1) - } - func testImageConversion() { guard let original = UIImage(named: "green-star", in: .mapboxMapsTests, compatibleWith: nil) else { XCTFail("Could not load test image from bundle") diff --git a/Tests/MapboxMapsTests/Gestures/GestureManagerTests.swift b/Tests/MapboxMapsTests/Gestures/GestureManagerTests.swift index 3b625d179a86..055dabc7f022 100644 --- a/Tests/MapboxMapsTests/Gestures/GestureManagerTests.swift +++ b/Tests/MapboxMapsTests/Gestures/GestureManagerTests.swift @@ -20,7 +20,7 @@ final class GestureManagerTests: XCTestCase { override func setUp() { let resourceOptions = ResourceOptions(accessToken: "") - mapView = BaseMapView(with: CGRect(x: 0, y: 0, width: 100, height: 100), + mapView = BaseMapView(frame: CGRect(x: 0, y: 0, width: 100, height: 100), resourceOptions: resourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions.default, styleURI: nil) diff --git a/Tests/MapboxMapsTests/Location/Pucks/Puck3DIntegrationTests.swift b/Tests/MapboxMapsTests/Location/Pucks/Puck3DIntegrationTests.swift index ded20e75c2b5..975979bf512f 100644 --- a/Tests/MapboxMapsTests/Location/Pucks/Puck3DIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Location/Pucks/Puck3DIntegrationTests.swift @@ -12,7 +12,7 @@ final class Puck3DIntegrationTests: XCTestCase { func testPuck3DDeinitializationDoesNotCrash() { autoreleasepool { - let mapView = MapView(with: .zero, resourceOptions: resourceOptions) + let mapView = MapView(frame: .zero, resourceOptions: resourceOptions) mapView.update { (options) in options.location.puckType = .puck3D( Puck3DConfiguration( diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift index de1387a47f19..c8cbe930a8a2 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift @@ -103,7 +103,7 @@ internal class DidIdleFailureIntegrationTest: IntegrationTestCase { } let resourceOptions = ResourceOptions(accessToken: accessToken) - let view = MapView(with: window.bounds, resourceOptions: resourceOptions) + let view = MapView(frame: window.bounds, resourceOptions: resourceOptions) let observer = ObservableIntegrationTestsObserver(with: { [weak self] (resourceEvent) in guard let self = self else { diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/MapViewIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/MapViewIntegrationTests.swift index 59062b60b225..6948bd47097b 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/MapViewIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/MapViewIntegrationTests.swift @@ -15,7 +15,7 @@ class MapViewIntegrationTests: IntegrationTestCase { rootView = root let resourceOptions = ResourceOptions(accessToken: accessToken) - mapView = MapView(with: rootView.bounds, resourceOptions: resourceOptions, styleURI: .streets) + mapView = MapView(frame: rootView.bounds, resourceOptions: resourceOptions, styleURI: .streets) rootView.addSubview(mapView) } @@ -30,7 +30,7 @@ class MapViewIntegrationTests: IntegrationTestCase { let expectation = self.expectation(description: "wait for map") let resourceOptions = ResourceOptions(accessToken: accessToken) - let mapView = MapView(with: rootView.bounds, resourceOptions: resourceOptions, styleURI: .streets) + let mapView = MapView(frame: rootView.bounds, resourceOptions: resourceOptions, styleURI: .streets) weakMapView = mapView rootView.addSubview(mapView) diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/MapViewIntegrationTestCase.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/MapViewIntegrationTestCase.swift index 0b625bb7cfd5..e9c499cfc916 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/MapViewIntegrationTestCase.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/MapViewIntegrationTestCase.swift @@ -24,7 +24,7 @@ internal class MapViewIntegrationTestCase: IntegrationTestCase { } let resourceOptions = ResourceOptions(accessToken: accessToken) - let view = MapView(with: window.bounds, resourceOptions: resourceOptions) + let view = MapView(frame: window.bounds, resourceOptions: resourceOptions) view.on(.styleLoaded) { [weak self] _ in guard let self = self else { return } diff --git a/Tests/MapboxMapsTests/MapView/Unit Tests/MapViewTests.swift b/Tests/MapboxMapsTests/MapView/Unit Tests/MapViewTests.swift index 72b2b2904ab1..b16f9a68ce9b 100644 --- a/Tests/MapboxMapsTests/MapView/Unit Tests/MapViewTests.swift +++ b/Tests/MapboxMapsTests/MapView/Unit Tests/MapViewTests.swift @@ -7,7 +7,7 @@ class MapViewTests: XCTestCase { func testMapViewIsReleased() throws { weak var weakMapView: MapView? autoreleasepool { - let mapView = MapView(with: CGRect(origin: .zero, size: CGSize(width: 100, height: 100)), resourceOptions: ResourceOptions()) + let mapView = MapView(frame: CGRect(origin: .zero, size: CGSize(width: 100, height: 100)), resourceOptions: ResourceOptions()) weakMapView = mapView } XCTAssertNil(weakMapView) @@ -16,7 +16,7 @@ class MapViewTests: XCTestCase { func testDisplayLink() throws { weak var weakMapView: MapView? autoreleasepool { - let mapView = MapView(with: CGRect(origin: .zero, size: CGSize(width: 100, height: 100)), resourceOptions: ResourceOptions()) + let mapView = MapView(frame: CGRect(origin: .zero, size: CGSize(width: 100, height: 100)), resourceOptions: ResourceOptions()) weakMapView = mapView do { From 45ee965ada93aeb4907e2dc6412561d21030bcd3 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 15:36:00 -0400 Subject: [PATCH 03/19] Camera public API cleanup --- .../Foundation/Camera/CameraAnimator.swift | 14 +- .../Foundation/Camera/CameraManager.swift | 170 ++---------------- .../Foundation/Camera/CameraOptions.swift | 19 +- ...estureManager+GestureHandlerDelegate.swift | 4 +- .../MapboxMaps/Gestures/GestureManager.swift | 2 +- .../Camera/MapboxMapsCameraTests.swift | 77 +------- .../Gestures/MockCameraManager.swift | 2 +- .../FeatureQueryingTest.swift | 8 +- 8 files changed, 41 insertions(+), 255 deletions(-) diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraAnimator.swift b/Sources/MapboxMaps/Foundation/Camera/CameraAnimator.swift index f7f00452cdb0..1de6d45d5c65 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraAnimator.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraAnimator.swift @@ -32,9 +32,9 @@ public class CameraAnimator: NSObject { } /// Value that represents what percentage of the animation has been completed. - public var fractionComplete: CGFloat { - get { return propertyAnimator.fractionComplete } - set { propertyAnimator.fractionComplete = newValue } + public var fractionComplete: Double { + get { return Double(propertyAnimator.fractionComplete) } + set { propertyAnimator.fractionComplete = CGFloat(newValue) } } // MARK: Initializer @@ -75,9 +75,9 @@ public class CameraAnimator: NSObject { } /// Add animations block to the animator with a `delayFactor`. - public func addAnimations(_ animations: @escaping () -> Void, delayFactor: CGFloat) { + public func addAnimations(_ animations: @escaping () -> Void, delayFactor: Double) { // if this cameraAnimator is not in the list of CameraAnimators held by the `CameraManager` then add it to that list - propertyAnimator.addAnimations(animations, delayFactor: delayFactor) + propertyAnimator.addAnimations(animations, delayFactor: CGFloat(delayFactor)) } /// Add animations block to the animator. @@ -94,7 +94,7 @@ public class CameraAnimator: NSObject { } /// Continue the animation with a timing parameter (`UITimingCurveProvider`) and duration factor (`CGFloat`). - public func continueAnimation(withTimingParameters parameters: UITimingCurveProvider?, durationFactor: CGFloat) { - propertyAnimator.continueAnimation(withTimingParameters: parameters, durationFactor: durationFactor) + public func continueAnimation(withTimingParameters parameters: UITimingCurveProvider?, durationFactor: Double) { + propertyAnimator.continueAnimation(withTimingParameters: parameters, durationFactor: CGFloat(durationFactor)) } } diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift index 9df0526f0853..d461bf506e7d 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift @@ -20,7 +20,12 @@ public class CameraManager { } /// Pointer HashTable for holding camera animators - public internal(set) var cameraAnimators = NSHashTable.weakObjects() + internal var cameraAnimators = NSHashTable.weakObjects() + + /// List of animators currently alive + public var cameraAnimatorsList: [CameraAnimator] { + return cameraAnimators.allObjects + } /// Internal camera animator used for animated transition internal var internalCameraAnimator: CameraAnimator? @@ -28,7 +33,7 @@ public class CameraManager { /// May want to convert to an enum. fileprivate let northBearing: CGFloat = 0 - public weak var mapView: BaseMapView? + internal weak var mapView: BaseMapView? public init(for mapView: BaseMapView, with mapCameraOptions: MapCameraOptions) { self.mapView = mapView @@ -133,7 +138,10 @@ public class CameraManager { /// - animated: Set to `true` if transition should be animated. `false` by default. /// - duration: Controls the duration of the animation transition. Must be greater than zero if `animated` is true. /// - completion: The completion block to be called after an animated transition. Only called if `animated` is true. - public func setCamera(to targetCamera: CameraOptions, animated: Bool = false, duration: TimeInterval = 0, completion: ((UIViewAnimatingPosition) -> Void)? = nil) { + public func setCamera(to targetCamera: CameraOptions, + animated: Bool = false, + duration: TimeInterval = 0, + completion: ((UIViewAnimatingPosition) -> Void)? = nil) { guard let mapView = mapView else { assertionFailure("MapView is nil.") return @@ -162,39 +170,7 @@ public class CameraManager { } } - /// Transition the camera view to a new map camera based on individual camera properties, - /// optionally animating the change and executing a completion block after the transition occurs. - /// - Parameters: - /// - centerCoordinate: The new center coordinate the viewport will transition to. - /// - padding: The new edge insets the viewport will use to to apply padding. - /// - anchor: The new anchor point the viewport will use. - /// - zoom: The new zoom level the viewport will transition to. - /// - bearing: The bearing the viewport will rotate to. - /// - pitch: The new pitch the viewport will transition to. - /// - animated: A boolean indicating if the change should be animated. By default, this value is `false` - /// - duration: The `TimeInterval` for the animation to be completed - /// - completion: The completion block to execute after the transition has occurred. - public func setCamera(centerCoordinate: CLLocationCoordinate2D? = nil, - padding: UIEdgeInsets? = nil, - anchor: CGPoint? = nil, - zoom: CGFloat? = nil, - bearing: CLLocationDirection? = nil, - pitch: CGFloat? = nil, - animated: Bool = false, - duration: TimeInterval = 0, - completion: ((UIViewAnimatingPosition) -> Void)? = nil) { - let newCamera = CameraOptions(center: centerCoordinate, - padding: padding, - anchor: anchor, - zoom: zoom, - bearing: bearing, - pitch: pitch) - - setCamera(to: newCamera, animated: animated, duration: duration, completion: completion) - } - // swiftlint:enable function_parameter_count - - public func cancelTransitions() { + public func cancelAnimations() { for animator in cameraAnimators.allObjects where animator.state == .active { animator.stopAnimation() } @@ -226,128 +202,6 @@ public class CameraManager { internalCameraAnimator?.startAnimation() } - /// Reset the map's camera to the default style camera. - public func resetPosition() { - guard let mapView = mapView else { - assertionFailure("MapView is nil.") - return - } - - let defaultOptions = try! mapView.__map.getStyleDefaultCamera() - setCamera(to: defaultOptions, completion: nil) - } - - /// Resets the map rotation to a north bearing of `0` degrees. - /// - Parameter animated: A boolean indicating if the change should be animated. By default, this value is `false`. - public func resetNorth(_ animated: Bool = false) { - setCamera(bearing: CLLocationDirection(northBearing), - animated: animated) - } - - // MARK: Fitting the camera specified regions - - /// Transitions the viewport to fit a given set of new coordinate bounds, - /// optionally animating the change. - /// - /// This method also accounts for any `UIEdgeInsets` that may have been set - /// through the the `CameraView`'s `padding` property. - /// - Parameters: - /// - newCoordinateBounds: The coordinate bounds that will be displayed within the viewport. - /// - animated: A boolean indicating if the change should be animated. Defaults to `false`. - public func transitionCoordinateBounds(newCoordinateBounds: CoordinateBounds, - animated: Bool = false) { - transitionCoordinateBounds(to: newCoordinateBounds, - edgePadding: UIEdgeInsets.zero, - animated: animated, - completion: nil) - } - - /// Transitions the viewport to fit a given set of new coordinate bounds, - /// specifying a custom edge padding, an optional animation change, and an optional - /// completion block to execute after the transition occurs. - /// - /// - Parameters: - /// - newCoordinateBounds: The new coordinate bounds that will be displayed within the viewport. - /// - edgePadding: The padding the viewport will adjust itself by after transitioning to the new viewport. - /// - animated: A boolean indicating if the change should be animated. Defaults to `false`. - /// - completion: An optional function to execute after the transition has occurred. - public func transitionCoordinateBounds(to newCoordinateBounds: CoordinateBounds, - edgePadding: UIEdgeInsets, - animated: Bool = false, - completion: ((UIViewAnimatingPosition) -> Void)? = nil) { - let southeast = CLLocationCoordinate2D(latitude: newCoordinateBounds.northeast.latitude, - longitude: newCoordinateBounds.southwest.longitude) - let southwest = newCoordinateBounds.southwest - let northwest = CLLocationCoordinate2D(latitude: newCoordinateBounds.southwest.latitude, - longitude: newCoordinateBounds.northeast.longitude) - let northeast = newCoordinateBounds.northeast - - transitionVisibleCoordinates(to: [southeast, southwest, northwest, northeast], - edgePadding: edgePadding, - bearing: 0, - duration: 0, - animated: animated, - completion: completion) - } - - /// Transitions the viewport to fit a given array of new coordinates, specifying - /// a custom edge padding an optional animation change. - /// - /// - Parameters: - /// - newCoordinates: The coordinate bounds that will be displayed within the viewport. - /// - edgePadding: The padding the viewport will adjust itself by after transitioning to the new viewport. - /// - animated: A boolean indicating if the change should be animated. Defaults to `false`. - - public func transitionVisibleCoordinates(newCoordinates: [CLLocationCoordinate2D], - edgePadding: UIEdgeInsets, - animated: Bool = false) { - transitionVisibleCoordinates(to: newCoordinates, - edgePadding: edgePadding, - bearing: 0, - duration: 0, - animated: animated, - completion: nil) - } - - /// Transitions the viewport to fit a given array of new coordinates, specifying - /// a custom edge padding, an optional animation change, and an optional - /// completion block to execute after the transition occurs. - /// - /// - Parameters: - /// - newCoordinates: The array of coordinates that will be displayed within the viewport. - /// - edgePadding: The padding the viewport will adjust itself by after transitioning to the new viewport. - /// - bearing: The bearing the viewport will adjust itself after transitioning to the new viewport - /// - animated: A boolean indicating if the change should be animated. Defaults to `false`. - /// - completion: An optional closure to execute after the transition has occurred. - - public func transitionVisibleCoordinates(to newCoordinates: [CLLocationCoordinate2D], - edgePadding: UIEdgeInsets, - bearing: CLLocationDirection, - duration: TimeInterval, - animated: Bool = false, - completion: ((UIViewAnimatingPosition) -> Void)? = nil) { - guard let mapView = mapView else { - assertionFailure("MapView is nil.") - return - } - - // Don't set visible coordinate bounds if the coordinates are - // outside of the range of bounds specified in the MapCameraOptions. - if mapCameraOptions.restrictedCoordinateBounds?.contains(newCoordinates) == false { return } - - let padding = edgePadding.toMBXEdgeInsetsValue() - let bearing = bearing >= 0 ? CLLocationDirection(CGFloat(bearing)) : mapView.bearing - let coordinates = newCoordinates.map { CLLocation(latitude: $0.latitude, longitude: $0.longitude)} - let pitch = mapView.pitch - - let cameraOptions = try! mapView.__map.cameraForCoordinates(forCoordinates: coordinates, - padding: padding, - bearing: NSNumber(value: Float(bearing)), - pitch: NSNumber(value: Float(pitch))) - - setCamera(to: cameraOptions, animated: animated, duration: duration, completion: completion) - } - /// Moves the viewpoint to a different location using a transition animation that /// evokes powered flight and an optional transition duration and timing function /// It seamlessly incorporates zooming and panning to help diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift b/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift index 55b57bddf73e..8019a18078a2 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift @@ -2,7 +2,7 @@ import Foundation import CoreLocation import UIKit -public extension CameraOptions { +extension CameraOptions { /** The `CameraOptions` object contains information about the current state of the camera. @@ -17,7 +17,7 @@ public extension CameraOptions { - Returns: A `CameraOptions` object that contains all configuration information the `CameraView` will use to render the map's viewport. */ - convenience init(center: CLLocationCoordinate2D? = nil, + public convenience init(center: CLLocationCoordinate2D? = nil, padding: UIEdgeInsets? = nil, anchor: CGPoint? = nil, zoom: CGFloat? = nil, @@ -31,7 +31,7 @@ public extension CameraOptions { pitch: pitch?.NSNumber) } - var center: CLLocationCoordinate2D? { + public var center: CLLocationCoordinate2D? { get { return __center?.coordinate } @@ -40,7 +40,7 @@ public extension CameraOptions { } } - var padding: UIEdgeInsets? { + public var padding: UIEdgeInsets? { get { return __padding?.toUIEdgeInsetsValue() } @@ -49,7 +49,7 @@ public extension CameraOptions { } } - var anchor: CGPoint? { + public var anchor: CGPoint? { get { return __anchor?.point } @@ -58,7 +58,7 @@ public extension CameraOptions { } } - var zoom: CGFloat? { + public var zoom: CGFloat? { get { return __zoom?.CGFloat } @@ -67,7 +67,7 @@ public extension CameraOptions { } } - var bearing: CLLocationDirection? { + public var bearing: CLLocationDirection? { get { return __bearing?.CLLocationDirection } @@ -76,7 +76,7 @@ public extension CameraOptions { } } - var pitch: CGFloat? { + public var pitch: CGFloat? { get { return __pitch?.CGFloat } @@ -84,9 +84,8 @@ public extension CameraOptions { __pitch = newValue?.NSNumber } } -} -extension CameraOptions { + // MARK: Equals function public static func == (lhs: CameraOptions, rhs: CameraOptions) -> Bool { return lhs.center == rhs.center && lhs.padding == rhs.padding && diff --git a/Sources/MapboxMaps/Gestures/GestureManager+GestureHandlerDelegate.swift b/Sources/MapboxMaps/Gestures/GestureManager+GestureHandlerDelegate.swift index c662736cf896..41ed4cca8055 100644 --- a/Sources/MapboxMaps/Gestures/GestureManager+GestureHandlerDelegate.swift +++ b/Sources/MapboxMaps/Gestures/GestureManager+GestureHandlerDelegate.swift @@ -59,11 +59,11 @@ extension GestureManager: GestureHandlerDelegate { } internal func cancelGestureTransitions() { - cameraManager.cancelTransitions() + cameraManager.cancelAnimations() } internal func gestureBegan(for gestureType: GestureType) { - cameraManager.cancelTransitions() + cameraManager.cancelAnimations() delegate?.gestureBegan(for: gestureType) } diff --git a/Sources/MapboxMaps/Gestures/GestureManager.swift b/Sources/MapboxMaps/Gestures/GestureManager.swift index 87e04e2059b2..a2b228910b6b 100644 --- a/Sources/MapboxMaps/Gestures/GestureManager.swift +++ b/Sources/MapboxMaps/Gestures/GestureManager.swift @@ -117,7 +117,7 @@ internal protocol CameraManagerProtocol: AnyObject { duration: TimeInterval, completion: ((UIViewAnimatingPosition) -> Void)?) - func cancelTransitions() + func cancelAnimations() } extension CameraManager: CameraManagerProtocol { } diff --git a/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift b/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift index 6e3eb036c6bb..03edf5b020f7 100644 --- a/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift +++ b/Tests/MapboxMapsTests/Foundation/Camera/MapboxMapsCameraTests.swift @@ -28,7 +28,7 @@ class CameraManagerTests: XCTestCase { mapView.zoom = 5.0 XCTAssertEqual(mapView.cameraView.localZoom, 5.0, "Camera's zoom value is not initialized.") - cameraManager.setCamera(zoom: 10.0) + cameraManager.setCamera(to: CameraOptions(zoom: 10.0)) XCTAssertEqual(mapView.cameraView.localZoom, 10.0, "Camera manager did not set camera view zoom value.") } @@ -60,73 +60,6 @@ class CameraManagerTests: XCTestCase { XCTAssertEqual(camera.pitch, 0) } - // The default bounds returned by getBounds() matches the coordinate bounds for one world. Disabling -// func testDefaultCameraBoundsRestrictionIsNil() { -// let cameraManager = CameraManager(for: mapView, with: MapCameraOptions()) -// -// let restrictedBounds = cameraManager.mapCameraOptions.restrictedCoordinateBounds -// XCTAssertNil(restrictedBounds, "Default camera options don't have set bounds restriction.") -// } - - func testCameraOptionRestrictedBoundsRejectsBounds() { - let restrictedBounds = CoordinateBounds(southwest: CLLocationCoordinate2D(latitude: 0, longitude: 0), - northeast: CLLocationCoordinate2D(latitude: 10, longitude: 10)) - - let outOfBounds = CoordinateBounds(southwest: CLLocationCoordinate2D(latitude: -10, longitude: -10), - northeast: CLLocationCoordinate2D(latitude: -5, longitude: -5)) - - var cameraOptions = MapCameraOptions() - cameraOptions.restrictedCoordinateBounds = restrictedBounds - let cameraManager = CameraManager(for: mapView, with: cameraOptions) - let previousCenter = mapView.centerCoordinate - cameraManager.transitionCoordinateBounds(newCoordinateBounds: outOfBounds) - let currentCenter = mapView.centerCoordinate - - // The bounds to set the camera view to falls outside the restricted bounds, - // so the center won't change since the call to `transitionVisibleCoordinateBounds(to:)` won't complete. - XCTAssertEqual(previousCenter.latitude, currentCenter.latitude, "Camera view center latitude did not change.") - XCTAssertEqual(previousCenter.longitude, - currentCenter.longitude, - "Camera view center longitude did not change.") - } - - func testCameraForCoordinateBounds() { - let cameraManager = CameraManager(for: mapView, with: MapCameraOptions()) - let southwest = CLLocationCoordinate2D(latitude: -10, longitude: -10) - let northeast = CLLocationCoordinate2D(latitude: 0, longitude: 0) - let coordinateBounds = CoordinateBounds(southwest: southwest, northeast: northeast) - - let camera = cameraManager.camera(for: coordinateBounds) - _ = cameraManager.fly(to: camera, completion: nil) - - XCTAssertNotNil(mapView.cameraView.camera) - - // Failing. See https://github.com/mapbox/mapbox-maps-internal/issues/396 -// XCTAssertEqual(mapView.cameraView.centerCoordinate.latitude, camera.centerCoordinate.latitude) -// XCTAssertEqual(mapView.cameraView.centerCoordinate.longitude, camera.centerCoordinate.longitude) - } - - func testCameraOptionRestrictedBoundsAcceptsBounds() { - let restrictedBounds = CoordinateBounds(southwest: CLLocationCoordinate2D(latitude: 0, longitude: 0), - northeast: CLLocationCoordinate2D(latitude: 10, longitude: 10)) - - let allowedBounds = CoordinateBounds(southwest: CLLocationCoordinate2D(latitude: 2, longitude: 2), - northeast: CLLocationCoordinate2D(latitude: 4, longitude: 4)) - - var cameraOptions = MapCameraOptions() - cameraOptions.restrictedCoordinateBounds = restrictedBounds - let cameraManager = CameraManager(for: mapView, with: cameraOptions) - let previousCenter = mapView.centerCoordinate - cameraManager.transitionCoordinateBounds(newCoordinateBounds: allowedBounds) - let currentCenter = mapView.cameraView.localCenterCoordinate - - // The bounds to set the camera view to falls within the restricted bounds, - // so the center will change. - XCTAssertNotEqual(previousCenter.latitude, currentCenter.latitude, "Camera view center latitude was changed.") - XCTAssertNotEqual(previousCenter.longitude, currentCenter.longitude, - "Camera view center longitude was changed.") - } - func testSetCamera() { let expectedCamera = CameraOptions(center: CLLocationCoordinate2D(latitude: 50, longitude: 50), padding: UIEdgeInsets(top: 1, left: 2, bottom: 3, right: 4), @@ -194,7 +127,7 @@ class CameraManagerTests: XCTestCase { func testSetCameraByComponentEnforcesMinZoom() { cameraManager.mapCameraOptions.minimumZoomLevel = CGFloat.random(in: 0.. Date: Tue, 6 Apr 2021 15:37:18 -0400 Subject: [PATCH 04/19] Make `EventType` internal --- Sources/MapboxMaps/Foundation/Events/Event.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/MapboxMaps/Foundation/Events/Event.swift b/Sources/MapboxMaps/Foundation/Events/Event.swift index a4ebe0e6714c..5959fcb39041 100644 --- a/Sources/MapboxMaps/Foundation/Events/Event.swift +++ b/Sources/MapboxMaps/Foundation/Events/Event.swift @@ -2,7 +2,7 @@ import Foundation internal typealias EventAttributes = [String: Any] -public enum EventType { +internal enum EventType { case custom(name: String) case map(event: Maps) case metrics(event: Metrics) @@ -10,19 +10,19 @@ public enum EventType { case offlineStorage(event: OfflineStorage) case memoryWarning - public enum Maps { + internal enum Maps { case loaded } - public enum Metrics { + internal enum Metrics { case performance(metrics: [String: Any]) } - public enum Snapshot { + internal enum Snapshot { case initialized } - public enum OfflineStorage { + internal enum OfflineStorage { case downloadStarted(attributes: [String: Any]) } } From 2dbe3742e3b1d0943bbfd6f22cbc3b90d4790616 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 16:05:47 -0400 Subject: [PATCH 05/19] extensions public api clean up --- .../AnimateGeoJSONLineExample.swift | 4 +- .../All Examples/AnimateLayerExample.swift | 4 +- .../All Examples/CameraAnimatorsExample.swift | 2 +- .../All Examples/ColorExpressionExample.swift | 3 +- .../All Examples/Custom2DPuckExample.swift | 6 +- .../All Examples/Custom3DPuckExample.swift | 6 +- .../CustomPointAnnotationExample.swift | 4 +- .../DataDrivenSymbolsExample.swift | 4 +- .../ExternalVectorSourceExample.swift | 4 +- .../All Examples/FeaturesAtPointExample.swift | 4 +- .../Examples/All Examples/FlyToExample.swift | 4 +- .../All Examples/LayerBelowExample.swift | 4 +- .../All Examples/LayerPositionExample.swift | 4 +- .../All Examples/LineAnnotationExample.swift | 4 +- .../All Examples/PointAnnotationExample.swift | 4 +- .../PolygonAnnotationExample.swift | 4 +- .../All Examples/SceneKitExample.swift | 12 +-- .../SelectAnnotationExample.swift | 4 +- .../All Examples/SnapshotterExample.swift | 4 +- .../All Examples/SwiftUIExample.swift | 3 +- .../All Examples/TerrainExample.swift | 8 +- .../All Examples/TrackingModeExample.swift | 6 +- ...UpdatePointAnnotationPositionExample.swift | 7 +- .../Core/GlyphsRasterizationOptions.swift | 8 +- .../Extensions/Core/LayerPosition.swift | 6 +- .../Extensions/Core/MBXEdgeInsets.swift | 4 +- .../Extensions/Core/ResourceOptions.swift | 90 ++++++++++--------- .../Extensions/Core/ScreenCoordinate.swift | 6 +- .../Foundation/Extensions/CoreGraphics.swift | 12 +-- .../Foundation/Extensions/CoreLocation.swift | 12 +-- .../Foundation/Extensions/Int.swift | 4 +- .../Foundation/Extensions/UIImage.swift | 4 +- .../{MapboxLogoView.swift => LogoView.swift} | 8 +- .../Ornaments/OrnamentsManager.swift | 4 +- Sources/MapboxMaps/Snapshot/Snapshotter.swift | 4 +- 35 files changed, 138 insertions(+), 133 deletions(-) rename Sources/MapboxMaps/Foundation/{MapboxLogoView.swift => LogoView.swift} (99%) diff --git a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift index 27f4bfa87efc..f950c305fe8b 100644 --- a/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateGeoJSONLineExample.swift @@ -21,8 +21,8 @@ public class AnimateGeoJSONLineExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 45.5076, longitude: -122.6736) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 11.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 11.0)) // Wait for the map to load its style before adding data. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift index e5ff469d06ec..671208fa2e90 100644 --- a/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift +++ b/Apps/Examples/Examples/All Examples/AnimateLayerExample.swift @@ -23,8 +23,8 @@ public class AnimateLayerExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 37.8, longitude: -96) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 2) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 2)) // Allows the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift b/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift index ba1b6844e01e..e109dc23e436 100644 --- a/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift +++ b/Apps/Examples/Examples/All Examples/CameraAnimatorsExample.swift @@ -58,7 +58,7 @@ public class CameraAnimatorsExample: UIViewController, ExampleProtocol { // Center the map over New York City. let newYork = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) - mapView.cameraManager.setCamera(centerCoordinate: newYork) + mapView.cameraManager.setCamera(to: CameraOptions(center: newYork)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift index 049548b0f011..36cf47c1a5d0 100644 --- a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift +++ b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift @@ -18,8 +18,7 @@ public class ColorExpressionExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 40.58058466412761, longitude: -97.734375) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 3) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, zoom: 3)) // Allows the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift b/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift index 458ca229843e..ec25f514e05d 100644 --- a/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift +++ b/Apps/Examples/Examples/All Examples/Custom2DPuckExample.swift @@ -34,8 +34,8 @@ public class Custom2DPuckExample: UIViewController, ExampleProtocol { } let coordinate = CLLocationCoordinate2D(latitude: 39.085006, longitude: -77.150925) - mapView.cameraManager.setCamera(centerCoordinate: coordinate, - zoom: 14, - pitch: 0) + mapView.cameraManager.setCamera(to: CameraOptions(center: coordinate, + zoom: 14, + pitch: 0)) } } diff --git a/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift b/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift index c7b3fdf1d3b6..b77cfa04ff69 100644 --- a/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift +++ b/Apps/Examples/Examples/All Examples/Custom3DPuckExample.swift @@ -72,8 +72,8 @@ public class Custom3DPuckExample: UIViewController, ExampleProtocol { } let coordinate = CLLocationCoordinate2D(latitude: 39.085006, longitude: -77.150925) - mapView.cameraManager.setCamera(centerCoordinate: coordinate, - zoom: 14, - pitch: 80) + mapView.cameraManager.setCamera(to: CameraOptions(center: coordinate, + zoom: 14, + pitch: 80)) } } diff --git a/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift b/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift index 0dff1eb7bdfb..e5e9aba981d2 100644 --- a/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/CustomPointAnnotationExample.swift @@ -17,8 +17,8 @@ public class CustomPointAnnotationExample: UIViewController, ExampleProtocol { // Center the map camera over New York City let centerCoordinate = CLLocationCoordinate2D(latitude: 40.7128, longitude: -74.0060) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 9.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 9.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift b/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift index 059d6948ee58..978c1437d273 100644 --- a/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift +++ b/Apps/Examples/Examples/All Examples/DataDrivenSymbolsExample.swift @@ -17,8 +17,8 @@ public class DataDrivenSymbolsExample: UIViewController, ExampleProtocol { // Set center location let centerCoordinate = CLLocationCoordinate2D(latitude: 37.761, longitude: -119.624) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 10.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 10.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift index e070a989b600..87fd5a22e88b 100644 --- a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift +++ b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift @@ -12,8 +12,8 @@ public class ExternalVectorSourceExample: UIViewController, ExampleProtocol { mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.style.styleURI = .light let centerCoordinate = CLLocationCoordinate2D(latitude: 41.878781, longitude: -87.622088) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 12) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 12)) view.addSubview(mapView) // Allow the view controller to receive information about map events. diff --git a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift index 1c867f8fe6c4..164011e6e30e 100644 --- a/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift +++ b/Apps/Examples/Examples/All Examples/FeaturesAtPointExample.swift @@ -18,8 +18,8 @@ public class FeaturesAtPointExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 39.368279, longitude: -97.646484) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 2.4) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 2.4)) // Allows the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/FlyToExample.swift b/Apps/Examples/Examples/All Examples/FlyToExample.swift index a6117f1ae223..221cb006fa96 100644 --- a/Apps/Examples/Examples/All Examples/FlyToExample.swift +++ b/Apps/Examples/Examples/All Examples/FlyToExample.swift @@ -16,8 +16,8 @@ public class FlyToExample: UIViewController, ExampleProtocol { view.addSubview(mapView) // Center the map over San Francisco. - mapView.cameraManager.setCamera(centerCoordinate: .sanfrancisco, - zoom: 15) + mapView.cameraManager.setCamera(to: CameraOptions(center: .sanfrancisco, + zoom: 15)) // Allows the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/LayerBelowExample.swift b/Apps/Examples/Examples/All Examples/LayerBelowExample.swift index faea2207f5ca..ab28f575d26d 100644 --- a/Apps/Examples/Examples/All Examples/LayerBelowExample.swift +++ b/Apps/Examples/Examples/All Examples/LayerBelowExample.swift @@ -18,8 +18,8 @@ public class LayerBelowExample: UIViewController, ExampleProtocol { longitude: -88.137343) // Zoom to cover the whole Atlanta urban area - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 4) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 4)) // Allows the view controller to receive information about map events mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/LayerPositionExample.swift b/Apps/Examples/Examples/All Examples/LayerPositionExample.swift index 3260bec8fdb2..916cd3a14868 100644 --- a/Apps/Examples/Examples/All Examples/LayerPositionExample.swift +++ b/Apps/Examples/Examples/All Examples/LayerPositionExample.swift @@ -21,8 +21,8 @@ public class LayerPositionExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 40.58058466412761, longitude: -97.734375) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 3) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 3)) // Allows the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift b/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift index 42486c052b89..396388dbd842 100644 --- a/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/LineAnnotationExample.swift @@ -16,8 +16,8 @@ public class LineAnnotationExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 39.7128, longitude: -75.0060) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 5.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 5.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift b/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift index 219d107eb049..b5d47fcc387f 100644 --- a/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/PointAnnotationExample.swift @@ -17,8 +17,8 @@ public class PointAnnotationExample: UIViewController, ExampleProtocol { // Center the map camera over Copenhagen. let centerCoordinate = CLLocationCoordinate2D(latitude: 55.665957, longitude: 12.550343) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 8.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 8.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift b/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift index 1cee44066978..3de995f7df2a 100644 --- a/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/PolygonAnnotationExample.swift @@ -15,8 +15,8 @@ public class PolygonAnnotationExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 25.04579, longitude: -88.90136) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 5.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 5.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/SceneKitExample.swift b/Apps/Examples/Examples/All Examples/SceneKitExample.swift index 43cde79fbc8a..18d8b8e19c69 100644 --- a/Apps/Examples/Examples/All Examples/SceneKitExample.swift +++ b/Apps/Examples/Examples/All Examples/SceneKitExample.swift @@ -23,12 +23,12 @@ public class SceneKitExample: UIViewController, ExampleProtocol, CustomLayerHost self.mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.view.addSubview(mapView) - mapView.cameraManager.setCamera( - centerCoordinate: self.modelOrigin, - zoom: 18, - bearing: 180, - pitch: 60 - ) + + let camera = CameraOptions(center: self.modelOrigin, + zoom: 18, + bearing: 180, + pitch: 60) + mapView.cameraManager.setCamera(to: camera) self.mapView.on(.styleLoaded) { [weak self] _ in self?.addModelAndTerrain() diff --git a/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift b/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift index a356c016f2be..943aa029e820 100644 --- a/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift +++ b/Apps/Examples/Examples/All Examples/SelectAnnotationExample.swift @@ -30,8 +30,8 @@ public class SelectAnnotationExample: UIViewController, ExampleProtocol { let centerCoordinate = CLLocationCoordinate2D(latitude: 63.982738, longitude: -16.741790) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 12.0) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 12.0)) // Allow the view controller to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift index 12c9eb2d9f45..62f3e65f4656 100644 --- a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift +++ b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift @@ -22,8 +22,8 @@ public class SnapshotterExample: UIViewController, ExampleProtocol { mapView = MapView(frame: testRect, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.style.styleURI = .dark - mapView.cameraManager.setCamera(centerCoordinate: CLLocationCoordinate2D(latitude: 37.858, longitude: 138.472), - zoom: 3.5) + mapView.cameraManager.setCamera(to: CameraOptions(center: CLLocationCoordinate2D(latitude: 37.858, longitude: 138.472), + zoom: 3.5)) // Add the `MapViewController`'s view to the stack view as a // child view controller. diff --git a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift index a21cd69f8e53..7ba779d9eda2 100644 --- a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift +++ b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift @@ -89,8 +89,7 @@ internal struct SwiftUIMapView: UIViewRepresentable { /// If your `SwiftUIMapView` is reconfigured externally, SwiftUI will invoke `updateUIView(_:context:)` /// to give you an opportunity to re-sync the state of the underlying map view. func updateUIView(_ mapView: MapView, context: Context) { - mapView.cameraManager.setCamera(centerCoordinate: camera.center, - zoom: camera.zoom, + mapView.cameraManager.setCamera(to: CameraOptions(center: camera.center, zoom: camera.zoom), animated: false) /// Since changing the style causes annotations to be removed from the map /// we only call the setter if the value has changed. diff --git a/Apps/Examples/Examples/All Examples/TerrainExample.swift b/Apps/Examples/Examples/All Examples/TerrainExample.swift index 1edb81b673e4..f40addbf2f6b 100644 --- a/Apps/Examples/Examples/All Examples/TerrainExample.swift +++ b/Apps/Examples/Examples/All Examples/TerrainExample.swift @@ -23,10 +23,10 @@ public class TerrainExample: UIViewController, ExampleProtocol { view.addSubview(mapView) let centerCoordinate = CLLocationCoordinate2D(latitude: 32.6141, longitude: -114.34411) - mapView.cameraManager.setCamera(centerCoordinate: centerCoordinate, - zoom: 13.1, - bearing: 80, - pitch: 85) + mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, + zoom: 13.1, + bearing: 80, + pitch: 85)) mapView.on(.styleLoaded) { [weak self] _ in self?.addTerrain() diff --git a/Apps/Examples/Examples/All Examples/TrackingModeExample.swift b/Apps/Examples/Examples/All Examples/TrackingModeExample.swift index 52701c02aa90..05d9921e3845 100644 --- a/Apps/Examples/Examples/All Examples/TrackingModeExample.swift +++ b/Apps/Examples/Examples/All Examples/TrackingModeExample.swift @@ -25,7 +25,7 @@ public class TrackingModeExample: UIViewController, ExampleProtocol { } // Set initial camera settings - mapView.cameraManager.setCamera(zoom: 15.0) + mapView.cameraManager.setCamera(to: CameraOptions(zoom: 15.0)) // Allows the delegate to receive information about map events. mapView.on(.mapLoaded) { [weak self] _ in @@ -49,6 +49,8 @@ public class CameraLocationConsumer: LocationConsumer { } public func locationUpdate(newLocation: Location) { - mapView?.cameraManager.setCamera(centerCoordinate: newLocation.coordinate, zoom: 15, animated: true, duration: 1.3) + mapView?.cameraManager.setCamera(to: CameraOptions(center: newLocation.coordinate, zoom: 15), + animated: true, + duration: 1.3) } } diff --git a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift index 3aaaf219084f..691b7009a040 100644 --- a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift +++ b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift @@ -19,8 +19,8 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt let resourceOptions = ResourceOptions(accessToken: accessToken) mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - mapView.cameraManager.setCamera(centerCoordinate: CLLocationCoordinate2D(latitude: 59.3, longitude: 8.06), - zoom: 12) + mapView.cameraManager.setCamera(to: CameraOptions(center: CLLocationCoordinate2D(latitude: 59.3, longitude: 8.06), + zoom: 12)) view.addSubview(mapView) // Allows the view controller to receive information about map events. @@ -40,7 +40,8 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt } @objc public func updatePosition(_ sender: UITapGestureRecognizer) { - let screenCoordinate = mapView.convert(sender.location(in: mapView), to: mapView).screenCoordinate + let point = mapView.convert(sender.location(in: mapView), to: mapView) + let screenCoordinate = ScreenCoordinate(x: Double(point.x), y: Double(point.y)) let newCoordinate = try! mapView.__map.coordinateForPixel(forPixel: screenCoordinate) pointAnnotation.coordinate = newCoordinate diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift index e953a55a6423..4adf38701e3a 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift @@ -1,17 +1,17 @@ import Foundation import MapboxCoreMaps -public extension GlyphsRasterizationOptions { +extension GlyphsRasterizationOptions { /// Default fallback font - static var fallbackFontFamilyName: String = { + internal static var fallbackFontFamilyName: String = { UIFont.systemFont(ofSize: 0, weight: .regular).familyName }() /// Default GlyphsRasterizationOptions. RasterizationMode defaults to /// `.ideographsRasterizedLocally` i.e. ideographic symbols are rasterized locally (not loaded /// from the server) using an appropriate system font. - static var `default`: GlyphsRasterizationOptions = { + public static var `default`: GlyphsRasterizationOptions = { GlyphsRasterizationOptions(rasterizationMode: .ideographsRasterizedLocally) }() @@ -20,7 +20,7 @@ public extension GlyphsRasterizationOptions { /// - rasterizationMode: Rasterization mode /// - fontFamilies: Array of fonts, used for glyph rendering. Defaults to an appropriate /// system font - convenience init(rasterizationMode: GlyphsRasterizationMode, + public convenience init(rasterizationMode: GlyphsRasterizationMode, fontFamilies: [String] = []) { let fontFamilies = fontFamilies.isEmpty ? Self.fallbackFontFamilyName : fontFamilies.joined(separator: "\n") self.init(rasterizationMode: rasterizationMode, fontFamily: fontFamilies) diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift index ed9cc6748b9c..b50ec2fee60c 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift @@ -1,12 +1,12 @@ import MapboxCoreMaps -public extension LayerPosition { +extension LayerPosition { /// Layer should be positioned at a specified index in the layers stack - var at: UInt32? { + public var at: UInt32? { return __at?.uint32Value } - override func isEqual(_ object: Any?) -> Bool { + public override func isEqual(_ object: Any?) -> Bool { guard let object = object as? LayerPosition else { return false } diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/MBXEdgeInsets.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/MBXEdgeInsets.swift index e8d678c9a025..b0208864f6dc 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/MBXEdgeInsets.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/MBXEdgeInsets.swift @@ -1,6 +1,6 @@ import Foundation -public extension EdgeInsets { +internal extension EdgeInsets { func toUIEdgeInsetsValue() -> UIEdgeInsets { return UIEdgeInsets(top: CGFloat(self.top), left: CGFloat(self.left), @@ -9,7 +9,7 @@ public extension EdgeInsets { } } -public extension UIEdgeInsets { +internal extension UIEdgeInsets { func toMBXEdgeInsetsValue() -> EdgeInsets { return EdgeInsets(top: Double(self.top), left: Double(self.left), diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift index 96731c15a8d6..b054cbbb7420 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift @@ -2,16 +2,25 @@ import Foundation // MARK: - ResourceOptions -public extension ResourceOptions { - convenience init(accessToken: String, - baseUrl: String? = nil, - cachePath: String? = nil, - assetPath: String? = nil, - tileStorePath: String? = nil, - loadTilePacksFromNetwork: NSNumber? = nil, - cacheSize: UInt64 = (1024*1024*10)) { - - let cacheURL = ResourceOptions.cacheURLIncludingSubdirectory(useSubdirectory: true) +extension ResourceOptions { + /// Intializer for `ResourceOptions` + /// - Parameters: + /// - accessToken: Your mapbox access API token. + /// - baseUrl: The base URL. + /// - cachePath: The path to the cache. + /// - assetPath: The path to the assets. + /// - tileStorePath: The path to the tile store. + /// - loadTilePacksFromNetwork: Detemines if tiles pack should or should not be avoided from the network. + /// - cacheSize: The size of the cahce. + public convenience init(accessToken: String, + baseUrl: String? = nil, + cachePath: String? = nil, + assetPath: String? = nil, + tileStorePath: String? = nil, + loadTilePacksFromNetwork: NSNumber? = nil, + cacheSize: UInt64 = (1024*1024*10)) { + + let cacheURL = ResourceOptions.cacheURLIncludingSubdirectory() let resolvedCachePath = cachePath == nil ? cacheURL?.path : cachePath self.init(__accessToken: accessToken, baseURL: baseUrl, @@ -22,42 +31,37 @@ public extension ResourceOptions { cacheSize: NSNumber(value: cacheSize)) } - var cacheSize: UInt64? { + public var cacheSize: UInt64? { __cacheSize?.uint64Value } - static func cacheURLIncludingSubdirectory(useSubdirectory: Bool) -> URL? { - guard let bundleIdentifier = Bundle.main.bundleIdentifier else { return nil } - - var cacheDirectoryURL: URL - do { - cacheDirectoryURL = try FileManager.default.url(for: .applicationSupportDirectory, - in: .userDomainMask, - appropriateFor: nil, - create: true) - } catch { - return nil - } - - cacheDirectoryURL = cacheDirectoryURL.appendingPathComponent(bundleIdentifier) - - if useSubdirectory { - cacheDirectoryURL.appendPathComponent(".mapbox") - } - - do { - try FileManager.default.createDirectory(at: cacheDirectoryURL, - withIntermediateDirectories: true, - attributes: nil) - } catch { - return nil - } - - if useSubdirectory { - cacheDirectoryURL.setTemporaryResourceValue(true, forKey: .isExcludedFromBackupKey) - } - - return cacheDirectoryURL.appendingPathComponent("cache.db") + private static func cacheURLIncludingSubdirectory() -> URL? { + guard let bundleIdentifier = Bundle.main.bundleIdentifier else { return nil } + + var cacheDirectoryURL: URL + do { + cacheDirectoryURL = try FileManager.default.url(for: .applicationSupportDirectory, + in: .userDomainMask, + appropriateFor: nil, + create: true) + } catch { + return nil + } + + cacheDirectoryURL = cacheDirectoryURL.appendingPathComponent(bundleIdentifier) + cacheDirectoryURL.appendPathComponent(".mapbox") + + + do { + try FileManager.default.createDirectory(at: cacheDirectoryURL, + withIntermediateDirectories: true, + attributes: nil) + } catch { + return nil } + cacheDirectoryURL.setTemporaryResourceValue(true, forKey: .isExcludedFromBackupKey) + + return cacheDirectoryURL.appendingPathComponent("cache.db") + } } diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/ScreenCoordinate.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/ScreenCoordinate.swift index d6293a3868c4..af65d40a3334 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/ScreenCoordinate.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/ScreenCoordinate.swift @@ -5,20 +5,20 @@ import MapboxCoreMaps // MARK: - ScreenCoordinate -public extension ScreenCoordinate { +extension ScreenCoordinate { // swiftlint:disable identifier_name /// Initializes an internal `ScreenCoordinate` type from two `CGFloat` values. /// - Parameters: /// - x: The horizontal point along the screen's coordinate system. /// - y: The vertical point along the screen's coordinate system. - convenience init(x: CGFloat, y: CGFloat) { + internal convenience init(x: CGFloat, y: CGFloat) { self.init(x: Double(x), y: Double(y)) } // swiftlint:enable identifier_name /// Returns a `CGPoint` representation of an internal `ScreenCoordinate` value. - var point: CGPoint { + internal var point: CGPoint { CGPoint(x: x, y: y) } } diff --git a/Sources/MapboxMaps/Foundation/Extensions/CoreGraphics.swift b/Sources/MapboxMaps/Foundation/Extensions/CoreGraphics.swift index 5d067d79222f..0ba9d7b36691 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/CoreGraphics.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/CoreGraphics.swift @@ -4,10 +4,10 @@ import CoreGraphics import MapboxCoreMaps // MARK: - CGPoint -public extension CGPoint { +extension CGPoint { /// Converts a `CGPoint` to an internal `ScreenCoordinate` type. - var screenCoordinate: ScreenCoordinate { + internal var screenCoordinate: ScreenCoordinate { ScreenCoordinate(x: Double(x), y: Double(y)) } @@ -20,17 +20,17 @@ public extension CGPoint { /// represents the end position. /// - Returns: A `CGPoint` that represents the fractional point along the path /// between the source and destination points. - static func interpolate(origin: CGPoint, destination: CGPoint, fraction: CGFloat) -> CGPoint { + internal static func interpolate(origin: CGPoint, destination: CGPoint, fraction: CGFloat) -> CGPoint { return CGPoint(x: origin.x + fraction * (destination.x - origin.x), y: origin.y + fraction * (destination.y - origin.y)) } } // MARK: - CGFloat -public extension CGFloat { +extension CGFloat { /// Converts a `CGFloat` to a `NSValue` which wraps a `Double`. - var NSNumber: NSNumber { + internal var NSNumber: NSNumber { Foundation.NSNumber(value: Double(self)) } } @@ -41,7 +41,7 @@ extension CGRect { /// Returns a new `CGRect` whose origin is a given `CGPoint` value. /// - Parameter originPoint: The `CGPoint` which acts as the origin of the new `CGRect`. /// - Note: This method is the equivalent of `MGLExtendRect` in pre-v10.0.0 versions of the SDK. - func extend(from originPoint: CGPoint) -> CGRect { + internal func extend(from originPoint: CGPoint) -> CGRect { var rect = self diff --git a/Sources/MapboxMaps/Foundation/Extensions/CoreLocation.swift b/Sources/MapboxMaps/Foundation/Extensions/CoreLocation.swift index 3cd5d25ad693..836aa9f970e7 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/CoreLocation.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/CoreLocation.swift @@ -4,15 +4,15 @@ import CoreGraphics import MapboxCoreMaps // MARK: - CLLocationCoordinate2D -public extension CLLocationCoordinate2D { +extension CLLocationCoordinate2D { /// Converts a `CLLocationCoordinate` to a `CLLocation`. - var location: CLLocation { + internal var location: CLLocation { CLLocation(latitude: latitude, longitude: longitude) } /// Returns a new `CLLocationCoordinate` value with a new longitude constrained to [-180, +180] degrees. - func wrap() -> CLLocationCoordinate2D { + internal func wrap() -> CLLocationCoordinate2D { /** mbgl::geo.hpp equivalent: @@ -30,7 +30,7 @@ public extension CLLocationCoordinate2D { /// the distance from start to end longitudes is between a half and full /// world, ensuring that the shortest path is taken. /// - Parameter end: The coordinate to possibly wrap, if needed. - func unwrapForShortestPath(_ end: CLLocationCoordinate2D) -> CLLocationCoordinate2D { + internal func unwrapForShortestPath(_ end: CLLocationCoordinate2D) -> CLLocationCoordinate2D { let delta = fabs(end.longitude - longitude) if delta <= 180.0 || delta >= 360 { @@ -62,10 +62,10 @@ public extension CLLocationCoordinate2D { } // MARK: - CLLocationDirection -public extension CLLocationDirection { +extension CLLocationDirection { /// Converts a `CLLocationDirection` to an `NSNumber` containing a `Double`. - var NSNumber: NSNumber { + internal var NSNumber: NSNumber { Foundation.NSNumber(value: Double(self)) } } diff --git a/Sources/MapboxMaps/Foundation/Extensions/Int.swift b/Sources/MapboxMaps/Foundation/Extensions/Int.swift index 658d43d1fff4..43a66dc58a7a 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Int.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Int.swift @@ -1,10 +1,10 @@ import Foundation // MARK: - Int -public extension Int { +extension Int { /// Wraps an `Int` within a `NSNumber` value. - var NSNumber: NSNumber { + internal var NSNumber: NSNumber { Foundation.NSNumber(value: Int(self)) } } diff --git a/Sources/MapboxMaps/Foundation/Extensions/UIImage.swift b/Sources/MapboxMaps/Foundation/Extensions/UIImage.swift index 5073d77468c0..5f53de75e397 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/UIImage.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/UIImage.swift @@ -2,13 +2,13 @@ import UIKit // MARK: - UIImage -public extension UIImage { +extension UIImage { /// Initialize a `UIImage` with an internal `Image` type, using a givens scale. /// - Parameters: /// - mbxImage: The internal `Image` type to use for the `UIImage`. /// - scale: The scale of the new `UIImage`. - convenience init?(mbxImage: Image, scale: CGFloat = UIScreen.main.scale) { + internal convenience init?(mbxImage: Image, scale: CGFloat = UIScreen.main.scale) { let cgImage = mbxImage.cgImage().takeUnretainedValue() let size = CGSize(width: CGFloat(CGFloat(mbxImage.width) / scale), diff --git a/Sources/MapboxMaps/Foundation/MapboxLogoView.swift b/Sources/MapboxMaps/Foundation/LogoView.swift similarity index 99% rename from Sources/MapboxMaps/Foundation/MapboxLogoView.swift rename to Sources/MapboxMaps/Foundation/LogoView.swift index 53815d1a1bfc..da2711df3201 100644 --- a/Sources/MapboxMaps/Foundation/MapboxLogoView.swift +++ b/Sources/MapboxMaps/Foundation/LogoView.swift @@ -1,9 +1,9 @@ import UIKit // swiftlint:disable function_body_length file_length type_body_length -public class MapboxLogoView: UIView { +public class LogoView: UIView { - public enum MapboxLogoSize: RawRepresentable { + public enum LogoSize: RawRepresentable { case regular case compact @@ -27,9 +27,9 @@ public class MapboxLogoView: UIView { } } - internal var logoSize: MapboxLogoSize + internal var logoSize: LogoSize - public init(logoSize: MapboxLogoSize) { + public init(logoSize: LogoSize) { let frame = CGRect(origin: .zero, size: logoSize.rawValue) self.logoSize = logoSize super.init(frame: frame) diff --git a/Sources/MapboxMaps/Ornaments/OrnamentsManager.swift b/Sources/MapboxMaps/Ornaments/OrnamentsManager.swift index 6885da1331ba..13bd7f9113f9 100644 --- a/Sources/MapboxMaps/Ornaments/OrnamentsManager.swift +++ b/Sources/MapboxMaps/Ornaments/OrnamentsManager.swift @@ -50,7 +50,7 @@ public enum OrnamentType: Hashable { internal func makeOrnament(for view: OrnamentSupportableView, visibility: OrnamentVisibility = .visible) -> UIView { switch self { case .mapboxLogoView: - return MapboxLogoView(logoSize: .regular) + return LogoView(logoSize: .regular) case .mapboxScaleBar: let scalebarView = MapboxScaleBarOrnamentView() @@ -246,7 +246,7 @@ internal class OrnamentsManager: NSObject { also make the watermark seem disproportionally large on an iPad. Consider using size classes to figure out height/width instead. */ - if ornamentView is MapboxLogoView { + if ornamentView is LogoView { constraints.append(contentsOf: [ ornamentView.widthAnchor.constraint(equalTo: universalLayoutGuide.widthAnchor, multiplier: 0.25), ornamentView.heightAnchor.constraint(equalTo: ornamentView.widthAnchor, multiplier: 0.25) diff --git a/Sources/MapboxMaps/Snapshot/Snapshotter.swift b/Sources/MapboxMaps/Snapshot/Snapshotter.swift index 586f9d6e93fe..605136e85a5f 100644 --- a/Sources/MapboxMaps/Snapshot/Snapshotter.swift +++ b/Sources/MapboxMaps/Snapshot/Snapshotter.swift @@ -151,7 +151,7 @@ public class Snapshotter: Observer { // Composite the logo on the snapshot, // only after everything else has been drawn. - let logoView = MapboxLogoView(logoSize: .regular) + let logoView = LogoView(logoSize: .regular) let logoPadding = CGFloat(10.0) let logoOrigin = CGPoint(x: logoPadding, y: uiImage.size.height - logoView.frame.size.height - logoPadding) @@ -189,7 +189,7 @@ public class Snapshotter: Observer { internal func compositeLogo(for snapshotImage: UIImage) -> UIImage { let rect = CGRect(origin: .zero, size: snapshotImage.size) - let logoView = MapboxLogoView(logoSize: .regular) + let logoView = LogoView(logoSize: .regular) let renderer = UIGraphicsImageRenderer(size: snapshotImage.size) From 0ae98efcc9eac7a1575072bce7226bd2ba6184ec Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 16:08:37 -0400 Subject: [PATCH 06/19] Gestures & Snapshotter public API cleanup --- Sources/MapboxMaps/Gestures/GestureManager.swift | 6 +++--- Sources/MapboxMaps/Snapshot/Snapshotter.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/MapboxMaps/Gestures/GestureManager.swift b/Sources/MapboxMaps/Gestures/GestureManager.swift index a2b228910b6b..71359e73c798 100644 --- a/Sources/MapboxMaps/Gestures/GestureManager.swift +++ b/Sources/MapboxMaps/Gestures/GestureManager.swift @@ -5,7 +5,7 @@ import CoreLocation import MapboxMapsFoundation #endif -public enum GestureType: Hashable { +internal enum GestureType: Hashable { /// The pan gesture type case pan @@ -100,7 +100,7 @@ internal class GestureHandler { } } -public protocol GestureManagerDelegate: AnyObject { +internal protocol GestureManagerDelegate: AnyObject { /// Informs the delegate that a gesture haas begun. Could be used to cancel camera tracking. func gestureBegan(for gestureType: GestureType) @@ -136,7 +136,7 @@ public final class GestureManager: NSObject { /// The camera manager that responds to gestures. internal let cameraManager: CameraManagerProtocol - public weak var delegate: GestureManagerDelegate? + internal weak var delegate: GestureManagerDelegate? internal init(for view: UIView, options: GestureOptions, cameraManager: CameraManagerProtocol) { self.cameraManager = cameraManager diff --git a/Sources/MapboxMaps/Snapshot/Snapshotter.swift b/Sources/MapboxMaps/Snapshot/Snapshotter.swift index 605136e85a5f..4b4b5a1077fc 100644 --- a/Sources/MapboxMaps/Snapshot/Snapshotter.swift +++ b/Sources/MapboxMaps/Snapshot/Snapshotter.swift @@ -30,7 +30,7 @@ public class Snapshotter: Observer { } /// A `style` object that can be manipulated to set different styles for a snapshot - public private(set) var style: Style + public let style: Style /// Initialize a `Snapshotter` instance /// - Parameters: From 51e510dc3561a81d5bd898aa52d43157c29d5e99 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Tue, 6 Apr 2021 16:16:34 -0400 Subject: [PATCH 07/19] swift lint errors --- .../MapboxMaps/Foundation/Camera/CameraManager.swift | 1 - .../MapboxMaps/Foundation/Camera/CameraOptions.swift | 10 +++++----- .../Extensions/Core/GlyphsRasterizationOptions.swift | 2 +- .../Foundation/Extensions/Core/ResourceOptions.swift | 1 - Sources/MapboxMaps/Ornaments/OrnamentConfig.swift | 8 ++++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift index d461bf506e7d..731c23f37cb5 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift @@ -1,4 +1,3 @@ -// swiftlint:disable file_length type_body_length import UIKit import Turf diff --git a/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift b/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift index 8019a18078a2..a179299660b2 100644 --- a/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift +++ b/Sources/MapboxMaps/Foundation/Camera/CameraOptions.swift @@ -18,11 +18,11 @@ extension CameraOptions { will use to render the map's viewport. */ public convenience init(center: CLLocationCoordinate2D? = nil, - padding: UIEdgeInsets? = nil, - anchor: CGPoint? = nil, - zoom: CGFloat? = nil, - bearing: CLLocationDirection? = nil, - pitch: CGFloat? = nil) { + padding: UIEdgeInsets? = nil, + anchor: CGPoint? = nil, + zoom: CGFloat? = nil, + bearing: CLLocationDirection? = nil, + pitch: CGFloat? = nil) { self.init(__center: center?.location, padding: padding?.toMBXEdgeInsetsValue(), anchor: anchor?.screenCoordinate, diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift index 4adf38701e3a..f13300ff6fa2 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/GlyphsRasterizationOptions.swift @@ -21,7 +21,7 @@ extension GlyphsRasterizationOptions { /// - fontFamilies: Array of fonts, used for glyph rendering. Defaults to an appropriate /// system font public convenience init(rasterizationMode: GlyphsRasterizationMode, - fontFamilies: [String] = []) { + fontFamilies: [String] = []) { let fontFamilies = fontFamilies.isEmpty ? Self.fallbackFontFamilyName : fontFamilies.joined(separator: "\n") self.init(rasterizationMode: rasterizationMode, fontFamily: fontFamilies) } diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift index b054cbbb7420..9b823097eff5 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift @@ -51,7 +51,6 @@ extension ResourceOptions { cacheDirectoryURL = cacheDirectoryURL.appendingPathComponent(bundleIdentifier) cacheDirectoryURL.appendPathComponent(".mapbox") - do { try FileManager.default.createDirectory(at: cacheDirectoryURL, withIntermediateDirectories: true, diff --git a/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift b/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift index 0c606a0d57fc..3dd429d2b2a8 100644 --- a/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift +++ b/Sources/MapboxMaps/Ornaments/OrnamentConfig.swift @@ -17,10 +17,10 @@ internal class Ornament: Equatable { } internal init(view: UIView?, - type: OrnamentType, - position: OrnamentPosition, - margins: OrnamentMargins, - visibility: OrnamentVisibility) { + type: OrnamentType, + position: OrnamentPosition, + margins: OrnamentMargins, + visibility: OrnamentVisibility) { self.view = view self.type = type self.position = position From 3cd60c9fe9c007f7678ea6a282726f0f95b88427 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Wed, 7 Apr 2021 00:05:28 -0400 Subject: [PATCH 08/19] Remove show properties in `OrnamentConfig` --- .../MapView/Configuration/OrnamentOptions.swift | 15 +++++++-------- .../MapView/OptionsIntegrationTests.swift | 4 +--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift b/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift index d1e788210349..661c910eff8d 100644 --- a/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift +++ b/Sources/MapboxMaps/MapView/Configuration/OrnamentOptions.swift @@ -6,23 +6,22 @@ private let defaultOrnamentsMargin = CGPoint(x: 8.0, y: 8.0) public struct OrnamentOptions: Equatable { /// Scale Bar options - public var showsScale: Bool = true public var scaleBarPosition: OrnamentPosition = .topLeft public var scaleBarMargins: CGPoint = defaultOrnamentsMargin + public var scaleBarVisibility: OrnamentVisibility = .adaptive /// Compass options - public var showsCompass: Bool = true public var compassViewPosition: OrnamentPosition = .topRight public var compassViewMargins: CGPoint = defaultOrnamentsMargin public var compassVisiblity: OrnamentVisibility = .adaptive /// Logo view options - public private(set) var showsLogoView: Bool = true + public var _showsLogoView: Bool = true public var logoViewPosition: OrnamentPosition = .bottomLeft public var logoViewMargins: CGPoint = defaultOrnamentsMargin /// Attribution options - public private(set) var showsAttributionButton: Bool = true + public var _showsAttributionButton: Bool = true public var attributionButtonPosition: OrnamentPosition = .bottomRight public var attributionButtonMargins: CGPoint = defaultOrnamentsMargin @@ -33,23 +32,23 @@ public struct OrnamentOptions: Equatable { var supportedOrnamentMargins: [OrnamentType: OrnamentMargins] = [:] var ornamentVisibility: [OrnamentType: OrnamentVisibility] = [:] - if showsScale { + if scaleBarVisibility != .hidden { supportedOrnaments[.mapboxScaleBar] = scaleBarPosition supportedOrnamentMargins[.mapboxScaleBar] = scaleBarMargins } - if showsCompass { + if compassVisiblity != .hidden { supportedOrnaments[.compass] = compassViewPosition supportedOrnamentMargins[.compass] = compassViewMargins ornamentVisibility[.compass] = compassVisiblity } - if showsLogoView { + if _showsLogoView { supportedOrnaments[.mapboxLogoView] = logoViewPosition supportedOrnamentMargins[.mapboxLogoView] = logoViewMargins } - if showsAttributionButton { + if _showsAttributionButton { supportedOrnaments[.infoButton] = attributionButtonPosition supportedOrnamentMargins[.infoButton] = attributionButtonMargins } diff --git a/Tests/MapboxMapsTests/MapView/OptionsIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/OptionsIntegrationTests.swift index 69cfc4480411..e38ae2e5dd58 100644 --- a/Tests/MapboxMapsTests/MapView/OptionsIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/OptionsIntegrationTests.swift @@ -15,8 +15,6 @@ internal class OptionsIntegrationTest: MapViewIntegrationTestCase { newOptions.location.activityType = .automotiveNavigation newOptions.camera.animationDuration = 0.1 newOptions.gestures.scrollEnabled = false - newOptions.ornaments.showsScale = false - newOptions.ornaments.showsCompass = false mapView.update { (options) in options = newOptions @@ -25,7 +23,7 @@ internal class OptionsIntegrationTest: MapViewIntegrationTestCase { XCTAssertEqual(mapView.gestureManager.gestureOptions, newOptions.gestures) XCTAssertEqual(mapView.cameraManager.mapCameraOptions, newOptions.camera) XCTAssertEqual(mapView.locationManager.locationOptions, newOptions.location) - XCTAssertFalse( + XCTAssertTrue( mapView.ornamentsManager.ornamentConfig.ornaments.contains { $0.type == .compass || $0.type == .mapboxScaleBar } From 220a075936e6c4c8a1203fae0ad5172d2b96e38e Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Wed, 7 Apr 2021 11:34:53 -0400 Subject: [PATCH 09/19] Expression public API cleanup --- Sources/MapboxMaps/Style/Types/Color.swift | 2 +- .../MapboxMaps/Style/Types/Expression.swift | 19 +++--------- .../Style/Types/ExpressionBuilder.swift | 30 +++++++++---------- 3 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Sources/MapboxMaps/Style/Types/Color.swift b/Sources/MapboxMaps/Style/Types/Color.swift index 0f3b9737fc1b..2bee7f11fb5d 100644 --- a/Sources/MapboxMaps/Style/Types/Color.swift +++ b/Sources/MapboxMaps/Style/Types/Color.swift @@ -75,7 +75,7 @@ public struct ColorRepresentable: Codable, Equatable { } } -extension UIColor: ValidExpressionArgument { +extension UIColor: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { var red: CGFloat = 0.0 diff --git a/Sources/MapboxMaps/Style/Types/Expression.swift b/Sources/MapboxMaps/Style/Types/Expression.swift index 6df917d2a10e..dfdc5b725457 100644 --- a/Sources/MapboxMaps/Style/Types/Expression.swift +++ b/Sources/MapboxMaps/Style/Types/Expression.swift @@ -5,7 +5,7 @@ public typealias Exp = Expression public struct Expression: Codable, CustomStringConvertible, Equatable { /// The individual elements of the expression in an array - public var elements: [Element] + internal var elements: [Element] // swiftlint:disable identifier_name public init(_ op: Expression.Operator, @@ -20,17 +20,6 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { self.init(with: elements) } - /// Attempts to create an Expression from a jsonObject. - public init?(from jsonObject: Any) { - do { - let data = try JSONSerialization.data(withJSONObject: jsonObject, options: []) - let exp = try JSONDecoder().decode(Expression.self, from: data) - self = exp - } catch { - return nil - } - } - /// Returns a jsonObject representation of this expression if serialization is successful, throws otherwise public func jsonObject() throws -> Any { let data = try JSONEncoder().encode(self) @@ -148,7 +137,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { return "\(exp)" case .option(let option): return "\(option)" - case .array(let array): + case .numberArray(let array): return "\(array)" } } @@ -167,7 +156,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { return true case (.expression(let lhsExpression), .expression(let rhsExpression)): return lhsExpression == rhsExpression - case (.array(let lhsArray), .array(let rhsArray)): + case (.numberArray(let lhsArray), .numberArray(let rhsArray)): return lhsArray == rhsArray default: return false @@ -215,7 +204,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { self = .null } else { let context = DecodingError.Context(codingPath: decoder.codingPath, - debugDescription: "Failed to decode ExpressionArgument") + debugDescription: "Failed to decode ExpressionArgument") throw DecodingError.dataCorrupted(context) } } diff --git a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift index 1fd17b919360..16aba2a3c231 100644 --- a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift +++ b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift @@ -4,7 +4,7 @@ import UIKit @_functionBuilder public struct ExpressionBuilder { - public static func buildBlock(_ arguments: ValidExpressionArgument...) -> Expression { + public static func buildBlock(_ arguments: ExpressionArgumentConvertible...) -> Expression { var expressionElements = [Expression.Element]() @@ -16,72 +16,72 @@ public struct ExpressionBuilder { } } -public protocol ValidExpressionArgument { +public protocol ExpressionArgumentConvertible { var expressionElements: [Expression.Element] { get } } -extension Int: ValidExpressionArgument { +extension Int: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.number(Double(self)))] } } -extension UInt: ValidExpressionArgument { +extension UInt: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.number(Double(self)))] } } -extension Double: ValidExpressionArgument { +extension Double: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.number(Double(self)))] } } -extension String: ValidExpressionArgument { +extension String: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.string(self))] } } -extension Bool: ValidExpressionArgument { +extension Bool: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.boolean(self))] } } -extension Array: ValidExpressionArgument where Element == Double { +extension Array: ExpressionArgumentConvertible where Element == Double { public var expressionElements: [Expression.Element] { - return [.argument(.array(self))] + return [.argument(.numberArray(self))] } } -extension Expression.Element: ValidExpressionArgument { +extension Expression.Element: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [self] } } -extension Expression: ValidExpressionArgument { +extension Expression: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(.expression(self))] } } -extension Expression.Argument: ValidExpressionArgument { +extension Expression.Argument: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.argument(self)] } } -extension Expression.Operator: ValidExpressionArgument { +extension Expression.Operator: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { return [.op(self)] } } -extension Dictionary: ValidExpressionArgument where Key == Double, - Value: ValidExpressionArgument { +extension Dictionary: ExpressionArgumentConvertible where Key == Double, + Value: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { var elements = [Expression.Element]() for key in Array(keys).sorted(by: <) { From 1b2fe8d55eeb95eafdcdfc0570ba0a8e2d44dcf1 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Wed, 7 Apr 2021 11:46:15 -0400 Subject: [PATCH 10/19] Removing unneeded Expressions Tests due to code removal --- .../ExpressionTests/ExpressionTests.swift | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift index 058c6661e9b8..730784a70b9d 100644 --- a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift +++ b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift @@ -7,26 +7,6 @@ import XCTest internal class ExpressionTests: XCTestCase { - internal func testRoundtripExpressionConversion() throws { - let expression = Exp(.interpolate) { - Exp(.linear) - Exp(.zoom) - 0 - UIColor.red - 14 - UIColor.blue - } - - do { - let expressionAsJSON = try expression.jsonObject() - let expressionAgain = Expression(from: expressionAsJSON) - XCTAssert(expressionAgain != nil) - XCTAssert(expression == expressionAgain!) - } catch { - XCTFail("Failed to convert expression to JSON and back") - } - } - internal func testExpressionValidity() { let sumExp = Exp(.sum) { 10 From 0af2946c3e0094334c4f4263e8e6a2d1b18db049 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Wed, 7 Apr 2021 16:25:06 -0400 Subject: [PATCH 11/19] Style public API cleanup --- .../All Examples/BasicMapExample.swift | 2 +- .../ExternalVectorSourceExample.swift | 2 +- .../All Examples/MapViewExample.swift | 2 +- .../OfflineRegionManagerExample.swift | 2 +- .../SnapshotterCoreGraphicsExample.swift | 2 +- .../All Examples/SnapshotterExample.swift | 4 ++-- .../All Examples/SwiftUIExample.swift | 4 ++-- .../StressTest/ViewController.swift | 6 ++--- .../Extensions/Core/LayerPosition.swift | 10 ++++++++ Sources/MapboxMaps/MapView/MapView.swift | 2 +- .../Style/Generated/Layers/FillLayer.swift | 2 +- Sources/MapboxMaps/Style/Layers.swift | 24 +++++++------------ Sources/MapboxMaps/Style/Style.swift | 6 ++--- Sources/MapboxMaps/Style/StyleURI.swift | 5 ---- Sources/MapboxMaps/Style/Types/Color.swift | 6 ++--- .../MapboxMaps/Style/Types/Expression.swift | 12 +++++----- .../Style/Types/ExpressionBuilder.swift | 2 +- .../AnnotationManagerIntegrationTests.swift | 6 ++--- .../ExampleIntegrationTest.swift | 2 +- .../FeatureQueryingTest.swift | 4 ++-- .../HTTP/HTTPIntegrationTests.swift | 4 ++-- .../LocationManagerIntegrationTests.swift | 2 +- .../Map/DidIdleFailureIntegrationTest.swift | 2 +- .../Map/ObservableIntegrationTests.swift | 2 +- .../Style/StyleLoadIntegrationTests.swift | 2 +- .../ExpressionTests/ExpressionTests.swift | 6 ++--- .../BackgroundLayerIntegrationTests.swift | 2 +- .../Layers/CircleLayerIntegrationTests.swift | 2 +- .../FillExtrusionLayerIntegrationTests.swift | 2 +- .../Layers/FillLayerIntegrationTests.swift | 2 +- .../Layers/HeatmapLayerIntegrationTests.swift | 2 +- .../HillshadeLayerIntegrationTests.swift | 2 +- .../Layers/LineLayerIntegrationTests.swift | 2 +- ...cationIndicatorLayerIntegrationTests.swift | 2 +- .../Layers/ModelLayerIntegrationTests.swift | 2 +- .../Layers/RasterLayerIntegrationTests.swift | 2 +- .../Layers/SkyLayerIntegrationTests.swift | 2 +- .../Layers/SymbolLayerIntegrationTests.swift | 2 +- .../GeoJsonSourceIntegrationTests.swift | 2 +- .../Sources/ImageSourceIntegrationTests.swift | 2 +- .../RasterDemSourceIntegrationTests.swift | 2 +- .../RasterSourceIntegrationTests.swift | 2 +- .../VectorSourceIntegrationTests.swift | 2 +- .../Style/StyleIntegrationTests.swift | 4 ++-- .../MapboxMapsTests/Style/StyleURITests.swift | 2 +- 45 files changed, 81 insertions(+), 82 deletions(-) diff --git a/Apps/Examples/Examples/All Examples/BasicMapExample.swift b/Apps/Examples/Examples/All Examples/BasicMapExample.swift index 6ebf41a97a86..b3296f1cb239 100644 --- a/Apps/Examples/Examples/All Examples/BasicMapExample.swift +++ b/Apps/Examples/Examples/All Examples/BasicMapExample.swift @@ -13,7 +13,7 @@ public class BasicMapExample: UIViewController, ExampleProtocol { mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] mapView.update { (mapOptions) in - mapOptions.ornaments.showsScale = true + mapOptions.ornaments.scaleBarVisibility = .visible } view.addSubview(mapView) diff --git a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift index 87fd5a22e88b..1fa8409edb19 100644 --- a/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift +++ b/Apps/Examples/Examples/All Examples/ExternalVectorSourceExample.swift @@ -10,7 +10,7 @@ public class ExternalVectorSourceExample: UIViewController, ExampleProtocol { mapView = MapView(frame: view.bounds, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - mapView.style.styleURI = .light + mapView.style.uri = .light let centerCoordinate = CLLocationCoordinate2D(latitude: 41.878781, longitude: -87.622088) mapView.cameraManager.setCamera(to: CameraOptions(center: centerCoordinate, zoom: 12)) diff --git a/Apps/Examples/Examples/All Examples/MapViewExample.swift b/Apps/Examples/Examples/All Examples/MapViewExample.swift index 7cd8566a4c80..5826c3a0f376 100644 --- a/Apps/Examples/Examples/All Examples/MapViewExample.swift +++ b/Apps/Examples/Examples/All Examples/MapViewExample.swift @@ -17,7 +17,7 @@ public class MapViewExample: UIViewController, ExampleProtocol { mapView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) - mapView.style.styleURI = StyleURI.custom(url: URL(string: "mapbox://styles/examples/cke97f49z5rlg19l310b7uu7j")!) + mapView.style.uri = StyleURI.custom(url: URL(string: "mapbox://styles/examples/cke97f49z5rlg19l310b7uu7j")!) mapView.on(.styleLoaded) { [weak self] _ in // The below line is used for internal testing purposes only. diff --git a/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift b/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift index f4c704735104..59a94c816932 100644 --- a/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift +++ b/Apps/Examples/Examples/All Examples/OfflineRegionManagerExample.swift @@ -42,7 +42,7 @@ public class OfflineRegionManagerExample: UIViewController, ExampleProtocol { } internal func setupExample() { - let offlineRegionDef = OfflineRegionGeometryDefinition(styleURL: mapView.style.styleURI.url.absoluteString, + let offlineRegionDef = OfflineRegionGeometryDefinition(styleURL: mapView.style.uri.rawValue.absoluteURL.absoluteString, geometry: MBXGeometry(coordinate: coord), minZoom: zoom - 2, maxZoom: zoom + 2, diff --git a/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift b/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift index 798214cb2102..4aab3e7e39aa 100644 --- a/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift +++ b/Apps/Examples/Examples/All Examples/SnapshotterCoreGraphicsExample.swift @@ -34,7 +34,7 @@ public class SnapshotterCoreGraphicsExample: UIViewController, ExampleProtocol { height: view.bounds.height), resourceOptions: resourceOptions) snapshotter = Snapshotter(options: options) - snapshotter.style.styleURI = .dark + snapshotter.style.uri = .dark snapshotter.on(.styleLoaded) { [weak self] _ in self?.startSnapshot() diff --git a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift index 62f3e65f4656..b584524b010a 100644 --- a/Apps/Examples/Examples/All Examples/SnapshotterExample.swift +++ b/Apps/Examples/Examples/All Examples/SnapshotterExample.swift @@ -21,7 +21,7 @@ public class SnapshotterExample: UIViewController, ExampleProtocol { let testRect = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height / 2) mapView = MapView(frame: testRect, resourceOptions: resourceOptions()) mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - mapView.style.styleURI = .dark + mapView.style.uri = .dark mapView.cameraManager.setCamera(to: CameraOptions(center: CLLocationCoordinate2D(latitude: 37.858, longitude: 138.472), zoom: 3.5)) @@ -42,7 +42,7 @@ public class SnapshotterExample: UIViewController, ExampleProtocol { height: view.bounds.height / 2), resourceOptions: resourceOptions()) snapshotter = Snapshotter(options: options) - snapshotter.style.styleURI = .light + snapshotter.style.uri = .light snapshotter.camera = mapView.camera snapshotter.on(.styleLoaded) { [weak self] _ in diff --git a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift index 7ba779d9eda2..088ce5dbffb2 100644 --- a/Apps/Examples/Examples/All Examples/SwiftUIExample.swift +++ b/Apps/Examples/Examples/All Examples/SwiftUIExample.swift @@ -93,8 +93,8 @@ internal struct SwiftUIMapView: UIViewRepresentable { animated: false) /// Since changing the style causes annotations to be removed from the map /// we only call the setter if the value has changed. - if mapView.style.styleURI != styleURI { - mapView.style.styleURI = styleURI + if mapView.style.uri != styleURI { + mapView.style.uri = styleURI } /// The coordinator needs to manager annotations because diff --git a/Apps/StressTest/StressTest/ViewController.swift b/Apps/StressTest/StressTest/ViewController.swift index 3c46025c3714..b5206cc5f581 100644 --- a/Apps/StressTest/StressTest/ViewController.swift +++ b/Apps/StressTest/StressTest/ViewController.swift @@ -101,7 +101,7 @@ class ViewController: UIViewController { self.flyToNextCoordinate() } - mapView.style.styleURI = styles[styleStep].0 + mapView.style.uri = styles[styleStep].0 } func flyToNextCoordinate() { @@ -119,7 +119,7 @@ class ViewController: UIViewController { removeAnnotations() // Change the style - mapView.style.styleURI = styles[styleStep].0 + mapView.style.uri = styles[styleStep].0 print("Changing style to \(styles[styleStep].0)") return @@ -288,7 +288,7 @@ class ViewController: UIViewController { print("Creating snapshotter") let snapshotter = Snapshotter(options: options) - snapshotter.style.styleURI = .light + snapshotter.style.uri = .light snapshotter.camera = mapView.camera snapshotter.on(.styleLoaded) { [weak self] _ in diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift index b50ec2fee60c..103bcb8ac4e3 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/LayerPosition.swift @@ -1,6 +1,16 @@ import MapboxCoreMaps extension LayerPosition { + + /// Convenience initializer for LayerPosition + /// - Parameters: + /// - above: Layer should be positioned above specified layer id + /// - below: Layer should be positioned below specified layer id + /// - at: Layer should be positioned at specified index in a layers stack + public convenience init(above: String? = nil, below: String? = nil, at: Int? = nil) { + self.init(__above: above, below: below, at: at?.NSNumber) + } + /// Layer should be positioned at a specified index in the layers stack public var at: UInt32? { return __at?.uint32Value diff --git a/Sources/MapboxMaps/MapView/MapView.swift b/Sources/MapboxMaps/MapView/MapView.swift index adea86455ea5..f220c939ce85 100644 --- a/Sources/MapboxMaps/MapView/MapView.swift +++ b/Sources/MapboxMaps/MapView/MapView.swift @@ -30,7 +30,7 @@ open class MapView: BaseMapView { internal var eventsListener: EventsListener! public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets) { - super.init(frame: frame, resourceOptions: resourceOptions, glyphsRasterizationOptions: glyphsRasterizationOptions, styleURI: styleURI?.url) + super.init(frame: frame, resourceOptions: resourceOptions, glyphsRasterizationOptions: glyphsRasterizationOptions, styleURI: styleURI?.rawValue) initialize() } diff --git a/Sources/MapboxMaps/Style/Generated/Layers/FillLayer.swift b/Sources/MapboxMaps/Style/Generated/Layers/FillLayer.swift index 581b3243f829..ca0a74bbd153 100644 --- a/Sources/MapboxMaps/Style/Generated/Layers/FillLayer.swift +++ b/Sources/MapboxMaps/Style/Generated/Layers/FillLayer.swift @@ -124,4 +124,4 @@ public struct FillLayer: Layer { } } -// End of generated file. \ No newline at end of file +// End of generated file. diff --git a/Sources/MapboxMaps/Style/Layers.swift b/Sources/MapboxMaps/Style/Layers.swift index 85436e48791f..f735813b8541 100644 --- a/Sources/MapboxMaps/Style/Layers.swift +++ b/Sources/MapboxMaps/Style/Layers.swift @@ -4,38 +4,38 @@ import MapboxCoreMaps /// Layer rendering types public enum LayerType: String, Codable { /// A filled polygon with an optional stroked border. - case fill = "fill" + case fill /// A stroked line. - case line = "line" + case line /// An icon or a text label. - case symbol = "symbol" + case symbol /// A filled circle. - case circle = "circle" + case circle /// A heatmap. - case heatmap = "heatmap" + case heatmap /// An extruded (3D) polygon. case fillExtrusion = "fill-extrusion" /// Raster map textures such as satellite imagery. - case raster = "raster" + case raster /// Client-side hillshading visualization based on DEM data. /// Currently, the implementation only supports Mapbox Terrain RGB and Mapzen Terrarium tiles. - case hillshade = "hillshade" + case hillshade /// The background color or pattern of the map. - case background = "background" + case background /// Layer representing the location indicator case locationIndicator = "location-indicator" /// Layer representing the sky - case sky = "sky" + case sky /// Layer used for a 3D model case model = "model" @@ -106,9 +106,3 @@ public extension Layer { self = try JSONDecoder().decode(Self.self, from: layerData) } } - -public extension LayerPosition { - convenience init(above: String? = nil, below: String? = nil, at: Int? = nil) { - self.init(__above: above, below: below, at: at?.NSNumber) - } -} diff --git a/Sources/MapboxMaps/Style/Style.swift b/Sources/MapboxMaps/Style/Style.swift index 9f2cf4521e6b..ba6d2ce043a1 100644 --- a/Sources/MapboxMaps/Style/Style.swift +++ b/Sources/MapboxMaps/Style/Style.swift @@ -7,7 +7,7 @@ import MapboxMapsFoundation public class Style { public private(set) weak var styleManager: StyleManager! - public init(with styleManager: StyleManager) { + internal init(with styleManager: StyleManager) { self.styleManager = styleManager } @@ -23,9 +23,9 @@ public class Style { receiver will use the default style and this property will automatically be set to that style’s URL. */ - public var styleURI: StyleURI = .streets { + public var uri: StyleURI = .streets { didSet { - let uriString = styleURI.url.absoluteString + let uriString = uri.rawValue.absoluteString try! styleManager.setStyleURIForUri(uriString) } } diff --git a/Sources/MapboxMaps/Style/StyleURI.swift b/Sources/MapboxMaps/Style/StyleURI.swift index 9e2bcdc6f799..ea586fcfc8c3 100644 --- a/Sources/MapboxMaps/Style/StyleURI.swift +++ b/Sources/MapboxMaps/Style/StyleURI.swift @@ -29,11 +29,6 @@ public enum StyleURI: Hashable, RawRepresentable { /// resource path. case custom(url: URL) - /// Underlying URL for the StyleURI - public var url: URL { - return rawValue - } - /// :nodoc: /// `RawRepresentable` conformance public var rawValue: URL { diff --git a/Sources/MapboxMaps/Style/Types/Color.swift b/Sources/MapboxMaps/Style/Types/Color.swift index 2bee7f11fb5d..c27802995c21 100644 --- a/Sources/MapboxMaps/Style/Types/Color.swift +++ b/Sources/MapboxMaps/Style/Types/Color.swift @@ -4,12 +4,12 @@ import UIKit public struct ColorRepresentable: Codable, Equatable { /// Expression representation of a `UIColor` used by the renderer - public let colorRepresentation: Expression? + internal let colorRepresentation: Expression? /// `UIColor` instance represented by this `ColorRepresentable` - public var uiColor: UIColor? { + internal var uiColor: UIColor? { - if case let .op(rgbaOp) = colorRepresentation?.elements[0], + if case let .operator(rgbaOp) = colorRepresentation?.elements[0], rgbaOp == .rgba, // operator must be `rgba` case let .argument(.number(red)) = colorRepresentation?.elements[1], // red case let .argument(.number(green)) = colorRepresentation?.elements[2], // green diff --git a/Sources/MapboxMaps/Style/Types/Expression.swift b/Sources/MapboxMaps/Style/Types/Expression.swift index dfdc5b725457..d27eb4d8465a 100644 --- a/Sources/MapboxMaps/Style/Types/Expression.swift +++ b/Sources/MapboxMaps/Style/Types/Expression.swift @@ -16,7 +16,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { elements = [] } - elements.insert(.op(op), at: 0) + elements.insert(.operator(op), at: 0) self.init(with: elements) } @@ -58,12 +58,12 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { */ public indirect enum Element: Codable, CustomStringConvertible, Equatable { - case op(Operator) + case `operator`(Operator) case argument(Argument) public var description: String { switch self { - case .op(let op): + case .operator(let op): return op.rawValue case .argument(let arg): return "\(arg)" @@ -72,7 +72,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { public static func == (lhs: Expression.Element, rhs: Expression.Element) -> Bool { switch (lhs, rhs) { - case (.op(let lhsOp), .op(let rhsOp)): + case (.operator(let lhsOp), .operator(let rhsOp)): return lhsOp.rawValue == rhsOp.rawValue case (.argument(let lhsArg), .argument(let rhsArg)): return lhsArg == rhsArg @@ -85,7 +85,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { var container = encoder.singleValueContainer() switch self { - case .op(let op): + case .operator(let op): try container.encode(op) case .argument(let argument): try container.encode(argument) @@ -96,7 +96,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { let container = try decoder.singleValueContainer() if let validOp = try? container.decode(Operator.self) { - self = .op(validOp) + self = .operator(validOp) return } diff --git a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift index 16aba2a3c231..5e786aa598ce 100644 --- a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift +++ b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift @@ -76,7 +76,7 @@ extension Expression.Argument: ExpressionArgumentConvertible { extension Expression.Operator: ExpressionArgumentConvertible { public var expressionElements: [Expression.Element] { - return [.op(self)] + return [.operator(self)] } } diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/AnnotationManagerIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/AnnotationManagerIntegrationTests.swift index ef0c8bdec7f1..f3a1ae18e307 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/AnnotationManagerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/AnnotationManagerIntegrationTests.swift @@ -12,7 +12,7 @@ internal class AnnotationManagerIntegrationTestCase: MapViewIntegrationTestCase to ensure the correct layers exist. */ internal func testAddAnnotation() { - style?.styleURI = .streets + style?.uri = .streets let styleLoadedExpectation = XCTestExpectation(description: "Wait for map to load style") let sourceAddedExpectation = XCTestExpectation(description: "Annotation source layer added") @@ -55,7 +55,7 @@ internal class AnnotationManagerIntegrationTestCase: MapViewIntegrationTestCase } internal func testAddAnnotationAtSpecificLayerPosition() { - style?.styleURI = .streets + style?.uri = .streets let styleLoadedExpectation = XCTestExpectation(description: "Wait for map to load style") @@ -94,7 +94,7 @@ internal class AnnotationManagerIntegrationTestCase: MapViewIntegrationTestCase that information at another instance. */ internal func testAddUserInfoToAnnotation() { - style?.styleURI = .streets + style?.uri = .streets let styleLoadedExpectation = XCTestExpectation(description: "Wait for map to load style") let sourceAddedExpectation = XCTestExpectation(description: "Annotation source layer added") diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/ExampleIntegrationTest.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/ExampleIntegrationTest.swift index 987ccf22d5a4..718c5717051b 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/ExampleIntegrationTest.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/ExampleIntegrationTest.swift @@ -19,7 +19,7 @@ internal class ExampleIntegrationTest: MapViewIntegrationTestCase { let expectation = XCTestExpectation(description: "Wait for map to idle") expectation.expectedFulfillmentCount = 2 - style.styleURI = .streets + style.uri = .streets mapView.centerCoordinate = CLLocationCoordinate2D(latitude: 42.0, longitude: -71.0) mapView.zoom = 8.0 diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/FeatureQueryingTest.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/FeatureQueryingTest.swift index ad1a6f766a75..2297c83c8dca 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/FeatureQueryingTest.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/FeatureQueryingTest.swift @@ -17,7 +17,7 @@ internal class FeatureQueryingTest: MapViewIntegrationTestCase { longitude: -122.341647) internal func testQueryAtPoint() { - style?.styleURI = .streets + style?.uri = .streets let featureQueryExpectation = XCTestExpectation(description: "Wait for features to be queried.") @@ -51,7 +51,7 @@ internal class FeatureQueryingTest: MapViewIntegrationTestCase { } internal func testQueryInRectWithFilter() { - style?.styleURI = .streets + style?.uri = .streets let featureQueryExpectation = XCTestExpectation(description: "Wait for features to be queried.") diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/HTTP/HTTPIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/HTTP/HTTPIntegrationTests.swift index c372d7974f51..3f34581707a9 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/HTTP/HTTPIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/HTTP/HTTPIntegrationTests.swift @@ -123,7 +123,7 @@ class HTTPIntegrationTests: MapViewIntegrationTestCase { serviceExpectation.fulfill() } - style.styleURI = .streets + style.uri = .streets wait(for: [serviceExpectation], timeout: 5.0) } @@ -144,7 +144,7 @@ class HTTPIntegrationTests: MapViewIntegrationTestCase { serviceExpectation.fulfill() } - style.styleURI = .streets + style.uri = .streets didFailLoadingMap = { (_, error2) in XCTAssertNotNil(error2) diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/LocationManagerIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/LocationManagerIntegrationTests.swift index f4443e9f8461..03c078e94318 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/LocationManagerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/LocationManagerIntegrationTests.swift @@ -12,7 +12,7 @@ internal class LocationManagerIntegrationTestCase: MapViewIntegrationTestCase { will update the existing `locationManager` */ internal func testOverrideLocationProvider() { - style?.styleURI = .outdoors + style?.uri = .outdoors let locationManagerOverrideProvider = XCTestExpectation(description: "Checks that a new location provider can be set successfully") diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift index c8cbe930a8a2..dd86ec24cd7c 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/DidIdleFailureIntegrationTest.swift @@ -173,7 +173,7 @@ internal class DidIdleFailureIntegrationTest: IntegrationTestCase { let expectation = XCTestExpectation(description: "Wait for map to idle") expectation.expectedFulfillmentCount = 2 - style.styleURI = .streets + style.uri = .streets mapView.centerCoordinate = CLLocationCoordinate2D(latitude: 42.0, longitude: -71.0) mapView.zoom = 8.0 diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/ObservableIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/ObservableIntegrationTests.swift index 3a3436a7e9a5..ffdc8d8f1e8c 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/Map/ObservableIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/Map/ObservableIntegrationTests.swift @@ -48,7 +48,7 @@ class ObservableIntegrationTests: MapViewIntegrationTestCase { try! mapView.__map.subscribe(for: observer, events: ["resource-request"]) - style.styleURI = .streets + style.uri = .streets let styleLoadExpectation = XCTestExpectation(description: "Style should have been loaded") diff --git a/Tests/MapboxMapsTests/MapView/Integration Tests/Style/StyleLoadIntegrationTests.swift b/Tests/MapboxMapsTests/MapView/Integration Tests/Style/StyleLoadIntegrationTests.swift index 84055880bd98..995b64e14215 100644 --- a/Tests/MapboxMapsTests/MapView/Integration Tests/Style/StyleLoadIntegrationTests.swift +++ b/Tests/MapboxMapsTests/MapView/Integration Tests/Style/StyleLoadIntegrationTests.swift @@ -53,7 +53,7 @@ class StyleLoadIntegrationTests: MapViewIntegrationTestCase { expectation.fulfill() } - style.styleURI = styleURI + style.uri = styleURI wait(for: [expectation], timeout: 5) } } diff --git a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift index 730784a70b9d..605568d7ee09 100644 --- a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift +++ b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift @@ -13,7 +13,7 @@ internal class ExpressionTests: XCTestCase { 12 } - if case let Exp.Element.op(sumOp) = sumExp.elements[0], + if case let Exp.Element.operator(sumOp) = sumExp.elements[0], sumOp.rawValue == Exp.Operator.sum.rawValue { } else { XCTFail("First element is not the 'sum' expression operator") } @@ -35,7 +35,7 @@ internal class ExpressionTests: XCTestCase { // Validates basic expression semantics internal func expressionValidator(exp: Exp) { if exp.elements.count == 1 { - if case Exp.Element.op(_) = exp.elements[0] { + if case Exp.Element.operator(_) = exp.elements[0] { // First element is an operator } else { XCTFail("In an expression with one element, the element MUST be an operator") @@ -44,7 +44,7 @@ internal class ExpressionTests: XCTestCase { if exp.elements.count > 1 { - if case Exp.Element.op(_) = exp.elements[0] { + if case Exp.Element.operator(_) = exp.elements[0] { // First element is an operator } else { XCTFail("In all expressions, the first element MUST be an operator") diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/BackgroundLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/BackgroundLayerIntegrationTests.swift index ea1e33e60ddb..567a7bb4e54b 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/BackgroundLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/BackgroundLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class BackgroundLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved BackgroundLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/CircleLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/CircleLayerIntegrationTests.swift index 79e3a9130e31..53b80bceabe3 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/CircleLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/CircleLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class CircleLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved CircleLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillExtrusionLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillExtrusionLayerIntegrationTests.swift index b70c00521e70..c487d7765cbf 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillExtrusionLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillExtrusionLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class FillExtrusionLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved FillExtrusionLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillLayerIntegrationTests.swift index f7ff6d85e654..06d8f9a9f136 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/FillLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class FillLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved FillLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HeatmapLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HeatmapLayerIntegrationTests.swift index 316da6ba35e5..11e6237c6720 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HeatmapLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HeatmapLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class HeatmapLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved HeatmapLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HillshadeLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HillshadeLayerIntegrationTests.swift index f8f1264d3af8..c0dd30be5f5e 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HillshadeLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/HillshadeLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class HillshadeLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved HillshadeLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LineLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LineLayerIntegrationTests.swift index 8714c56599a8..95f85864826c 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LineLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LineLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class LineLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved LineLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LocationIndicatorLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LocationIndicatorLayerIntegrationTests.swift index 37f5586d365c..ec7c717f02fd 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LocationIndicatorLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/LocationIndicatorLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class LocationIndicatorLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved LocationIndicatorLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/ModelLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/ModelLayerIntegrationTests.swift index 804f5170987d..6c398a0a0870 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/ModelLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/ModelLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class ModelLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved ModelLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/RasterLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/RasterLayerIntegrationTests.swift index 083ae45cf2e7..c059a8bc9508 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/RasterLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/RasterLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class RasterLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved RasterLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SkyLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SkyLayerIntegrationTests.swift index 7a9db309fdbc..73446b2c863e 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SkyLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SkyLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class SkyLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved SkyLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SymbolLayerIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SymbolLayerIntegrationTests.swift index 0a8fd9dca7ab..008d37f37183 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SymbolLayerIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Layers/SymbolLayerIntegrationTests.swift @@ -25,7 +25,7 @@ class SymbolLayerIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedLayerExpectation = XCTestExpectation(description: "Successfully retrieved SymbolLayer from Map") successfullyRetrievedLayerExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/GeoJsonSourceIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/GeoJsonSourceIntegrationTests.swift index 1d14ca438665..db553371a422 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/GeoJsonSourceIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/GeoJsonSourceIntegrationTests.swift @@ -23,7 +23,7 @@ class GeoJSONSourceIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedSourceExpectation = XCTestExpectation(description: "Successfully retrieved GeoJSONSource from Map") successfullyRetrievedSourceExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in var source = GeoJSONSource() diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/ImageSourceIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/ImageSourceIntegrationTests.swift index 718652c69bc1..f17f27bfdf24 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/ImageSourceIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/ImageSourceIntegrationTests.swift @@ -23,7 +23,7 @@ class ImageSourceIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedSourceExpectation = XCTestExpectation(description: "Successfully retrieved ImageSource from Map") successfullyRetrievedSourceExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in var source = ImageSource() diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterDemSourceIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterDemSourceIntegrationTests.swift index aaefce8983c6..e8786a7ff3f7 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterDemSourceIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterDemSourceIntegrationTests.swift @@ -23,7 +23,7 @@ class RasterDemSourceIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedSourceExpectation = XCTestExpectation(description: "Successfully retrieved RasterDemSource from Map") successfullyRetrievedSourceExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in var source = RasterDemSource() diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterSourceIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterSourceIntegrationTests.swift index 46f9db5361e8..d5e41f8bb5be 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterSourceIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/RasterSourceIntegrationTests.swift @@ -23,7 +23,7 @@ class RasterSourceIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedSourceExpectation = XCTestExpectation(description: "Successfully retrieved RasterSource from Map") successfullyRetrievedSourceExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in var source = RasterSource() diff --git a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/VectorSourceIntegrationTests.swift b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/VectorSourceIntegrationTests.swift index 33d55589581a..cf2d7c0d3140 100644 --- a/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/VectorSourceIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/Generated/IntegrationTests/Sources/VectorSourceIntegrationTests.swift @@ -23,7 +23,7 @@ class VectorSourceIntegrationTests: MapViewIntegrationTestCase { let successfullyRetrievedSourceExpectation = XCTestExpectation(description: "Successfully retrieved VectorSource from Map") successfullyRetrievedSourceExpectation.expectedFulfillmentCount = 1 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in var source = VectorSource() diff --git a/Tests/MapboxMapsTests/Style/StyleIntegrationTests.swift b/Tests/MapboxMapsTests/Style/StyleIntegrationTests.swift index fac5d71f41db..2f737e9546c2 100644 --- a/Tests/MapboxMapsTests/Style/StyleIntegrationTests.swift +++ b/Tests/MapboxMapsTests/Style/StyleIntegrationTests.swift @@ -18,7 +18,7 @@ internal class StyleIntegrationTests: MapViewIntegrationTestCase { let expectation = XCTestExpectation(description: "Manipulating style succeeded") expectation.expectedFulfillmentCount = 3 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in @@ -71,7 +71,7 @@ internal class StyleIntegrationTests: MapViewIntegrationTestCase { let expectation = XCTestExpectation(description: "Move style layer succeeded") expectation.expectedFulfillmentCount = 2 - style.styleURI = .streets + style.uri = .streets didFinishLoadingStyle = { _ in diff --git a/Tests/MapboxMapsTests/Style/StyleURITests.swift b/Tests/MapboxMapsTests/Style/StyleURITests.swift index 9dee36d06da0..43b95ca09b46 100644 --- a/Tests/MapboxMapsTests/Style/StyleURITests.swift +++ b/Tests/MapboxMapsTests/Style/StyleURITests.swift @@ -55,7 +55,7 @@ class StyleURITests: XCTestCase { } XCTAssertEqual(destURL, sourceURL, line: line) - XCTAssertEqual(destURL, styleURI.url, line: line) + XCTAssertEqual(destURL, styleURI.rawValue.absoluteURL, line: line) } private func checkDefaultStyleURI(with URLString: String, expected: StyleURI, line: UInt = #line) { From ab2bcf94fc0d8614c710e1f4c25a4a38b325ac42 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Thu, 8 Apr 2021 16:13:36 -0400 Subject: [PATCH 12/19] remaining expressions public API cleanup --- .../AnnotationSupportableMap.swift | 10 +++++-- .../MapboxMaps/Style/Types/Expression.swift | 15 +++-------- .../Style/Types/ExpressionBuilder.swift | 2 +- .../Style/Types/ExpressionOptions.swift | 6 ++--- .../ExpressionTests/ExpressionTests.swift | 27 ++----------------- 5 files changed, 18 insertions(+), 42 deletions(-) diff --git a/Sources/MapboxMaps/Annotations/AnnotationSupportableMap.swift b/Sources/MapboxMaps/Annotations/AnnotationSupportableMap.swift index dd4dc92d0b93..2ea22b426bff 100644 --- a/Sources/MapboxMaps/Annotations/AnnotationSupportableMap.swift +++ b/Sources/MapboxMaps/Annotations/AnnotationSupportableMap.swift @@ -50,7 +50,7 @@ extension BaseMapView: AnnotationSupportableMap { if let exp = filter { do { - jsonExpression = try exp.jsonObject() + jsonExpression = try jsonObject(exp: exp) } catch { completion(.failure(.invalidFilter(error))) return @@ -101,7 +101,7 @@ extension BaseMapView: AnnotationSupportableMap { if let exp = filter { do { - jsonExpression = try exp.jsonObject() + jsonExpression = try jsonObject(exp: exp) } catch { completion(.failure(.invalidFilter(error))) return @@ -131,4 +131,10 @@ extension BaseMapView: AnnotationSupportableMap { } }) } + + private func jsonObject(exp: Expression) throws -> Any { + let data = try JSONEncoder().encode(exp.self) + let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) + return jsonObject + } } diff --git a/Sources/MapboxMaps/Style/Types/Expression.swift b/Sources/MapboxMaps/Style/Types/Expression.swift index d27eb4d8465a..e478cec000a9 100644 --- a/Sources/MapboxMaps/Style/Types/Expression.swift +++ b/Sources/MapboxMaps/Style/Types/Expression.swift @@ -9,7 +9,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { // swiftlint:disable identifier_name public init(_ op: Expression.Operator, - @ExpressionBuilder content: () -> Expression = { Expression(with: [.argument(.null)])}) { + @FunctionBuilder content: () -> Expression = { Expression(with: [.argument(.null)])}) { var elements = content().elements if elements.count == 1 && elements[0] == .argument(.null) { @@ -20,13 +20,6 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { self.init(with: elements) } - /// Returns a jsonObject representation of this expression if serialization is successful, throws otherwise - public func jsonObject() throws -> Any { - let data = try JSONEncoder().encode(self) - let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) - return jsonObject - } - public func encode(to encoder: Encoder) throws { var container = encoder.unkeyedContainer() @@ -118,7 +111,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { case number(Double) case string(String) case boolean(Bool) - case array([Double]) + case numberArray([Double]) case option(Option) case null case expression(Expression) @@ -179,7 +172,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { try container.encode(option) case .null: try container.encodeNil() - case .array(let array): + case .numberArray(let array): try container.encode(array) } } @@ -199,7 +192,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { } else if let validOption = try? container.decode(Option.self) { self = .option(validOption) } else if let validArray = try? container.decode([Double].self) { - self = .array(validArray) + self = .numberArray(validArray) } else if let dict = try? container.decode([String: String].self), dict.isEmpty { self = .null } else { diff --git a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift index 5e786aa598ce..717b277e9994 100644 --- a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift +++ b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift @@ -2,7 +2,7 @@ import Foundation import UIKit @_functionBuilder -public struct ExpressionBuilder { +public struct FunctionBuilder { public static func buildBlock(_ arguments: ExpressionArgumentConvertible...) -> Expression { diff --git a/Sources/MapboxMaps/Style/Types/ExpressionOptions.swift b/Sources/MapboxMaps/Style/Types/ExpressionOptions.swift index bfbdfa64e9c2..0336bcd6ef32 100644 --- a/Sources/MapboxMaps/Style/Types/ExpressionOptions.swift +++ b/Sources/MapboxMaps/Style/Types/ExpressionOptions.swift @@ -43,7 +43,7 @@ extension Expression { } -public struct FormatOptions: Codable, Equatable, ValidExpressionArgument { +public struct FormatOptions: Codable, Equatable, ExpressionArgumentConvertible { /// Applies a scaling factor on text-size as specified by the root layout property. public var fontScale: Double? @@ -74,7 +74,7 @@ public struct FormatOptions: Codable, Equatable, ValidExpressionArgument { } } -public struct NumberFormatOptions: Codable, Equatable, ValidExpressionArgument { +public struct NumberFormatOptions: Codable, Equatable, ExpressionArgumentConvertible { /// Specifies the locale to use, as a BCP 47 language tag. public var locale: String? @@ -107,7 +107,7 @@ public struct NumberFormatOptions: Codable, Equatable, ValidExpressionArgument { } } -public struct CollatorOptions: Codable, Equatable, ValidExpressionArgument { +public struct CollatorOptions: Codable, Equatable, ExpressionArgumentConvertible { /// Whether comparison option is case sensitive. public var caseSensitive: Bool? diff --git a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift index 605568d7ee09..2aab053a8704 100644 --- a/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift +++ b/Tests/MapboxMapsTests/Style/ExpressionTests/ExpressionTests.swift @@ -75,29 +75,6 @@ internal class ExpressionTests: XCTestCase { expressionValidator(exp: expression) } - internal func testPerformanceOfRoundtripExpressionConversion() throws { - // This is an example of a performance test case. - measure { - let expression = Exp(.interpolate) { - Exp(.linear) - Exp(.zoom) - 0 - UIColor.red - 14 - UIColor.blue - } - - do { - let expressionAsJSON = try expression.jsonObject() - let expressionAgain = Expression(from: expressionAsJSON) - XCTAssert(expressionAgain != nil) - XCTAssert(expression == expressionAgain!) - } catch { - XCTFail("Failed to convert expression to JSON and back") - } - } - } - internal func testExpressionDecodingOnEmptyJSON() throws { let jsonString = @@ -125,7 +102,7 @@ internal class ExpressionTests: XCTestCase { // MARK: - Helpers internal func verifyExpressionOperator(for expression: Expression, toMatch type: Expression.Operator) { - guard let op = expression.elements.first, case let .op(validOp) = op else { + guard let op = expression.elements.first, case let .operator(validOp) = op else { XCTFail("There was no valid operator in the first element of the expression array") return } @@ -135,7 +112,7 @@ internal class ExpressionTests: XCTestCase { internal func verifyExpressionArgument(for expression: Expression, toMatch argument: Expression.Argument, at index: Int) { - guard let op = expression.elements.first, case .op = op else { + guard let op = expression.elements.first, case .operator = op else { XCTFail("There was no valid operator in the first element of the expression array") return } From 407aa3c1251703fcbb9027df1dbde9d284f74a33 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Thu, 8 Apr 2021 17:00:45 -0400 Subject: [PATCH 13/19] fixing examples and stress test --- .../Examples/All Examples/ColorExpressionExample.swift | 3 ++- Apps/StressTest/StressTest/ViewController.swift | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift index 36cf47c1a5d0..b4494466ff74 100644 --- a/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift +++ b/Apps/Examples/Examples/All Examples/ColorExpressionExample.swift @@ -54,7 +54,8 @@ public class ColorExpressionExample: UIViewController, ExampleProtocol { stops } - if let jsonObject = try? exp.jsonObject() { + if let data = try? JSONEncoder().encode(exp.self), + let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) { try! mapView.__map.setStyleLayerPropertyForLayerId("land", property: "background-color", value: jsonObject) diff --git a/Apps/StressTest/StressTest/ViewController.swift b/Apps/StressTest/StressTest/ViewController.swift index b5206cc5f581..8540ace89a7c 100644 --- a/Apps/StressTest/StressTest/ViewController.swift +++ b/Apps/StressTest/StressTest/ViewController.swift @@ -246,7 +246,8 @@ class ViewController: UIViewController { } do { - let jsonObject = try exp.jsonObject() + let data = try JSONEncoder().encode(exp.self) + let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) color = try mapView.__map.getStyleLayerProperty(forLayerId: land, property: "background-color") print("Setting background color expression") From edbf08e37975c81c7ee1cbc4bb046c48d522d306 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Thu, 8 Apr 2021 18:22:53 -0400 Subject: [PATCH 14/19] fixing Mapbox.xcworkspace --- Mapbox/MapboxMaps.xcodeproj/project.pbxproj | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/Mapbox/MapboxMaps.xcodeproj/project.pbxproj b/Mapbox/MapboxMaps.xcodeproj/project.pbxproj index c74270c1e5f8..dd533068ada7 100644 --- a/Mapbox/MapboxMaps.xcodeproj/project.pbxproj +++ b/Mapbox/MapboxMaps.xcodeproj/project.pbxproj @@ -31,7 +31,6 @@ 07BA35E825157A0E003E1B55 /* AnnotationSupportableMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07BA35E625157A0E003E1B55 /* AnnotationSupportableMap.swift */; }; 07D2C7DB2523EBE60025C2BA /* PolygonAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07D2C7DA2523EBE60025C2BA /* PolygonAnnotation.swift */; }; 07D7150425798CD70025BF61 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07D7150325798CD70025BF61 /* UIImage.swift */; }; - 07D71591257994430025BF61 /* MapboxLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07D71590257994430025BF61 /* MapboxLogoView.swift */; }; 07E816DA256D72E500ACFA73 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 07182014256C1F6100F22489 /* Assets.xcassets */; }; 0C01C0B925486E7200E4AA46 /* ExpressionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C01C08825486E6100E4AA46 /* ExpressionTests.swift */; }; 0C1AF55C244DF500008D2A10 /* MapOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C1AF55B244DF500008D2A10 /* MapOptions.swift */; }; @@ -111,7 +110,6 @@ 0C9DE3B3252C2A1F00880CC8 /* GeoJSONSourceDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C9DE382252C299800880CC8 /* GeoJSONSourceDataTests.swift */; }; 0CA3DD61257AAE3B00B12C8F /* SkyLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CA3DD5E257AAE3B00B12C8F /* SkyLayer.swift */; }; 0CAC3CAA2534E8CC00D031E7 /* ResourceOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC3CA92534E8CC00D031E7 /* ResourceOptions.swift */; }; - 0CAC3CC32534E90500D031E7 /* MapSnapshotOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CAC3CC22534E90500D031E7 /* MapSnapshotOptions.swift */; }; 0CBCF28E25409F030025F7B3 /* ResolvedImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CBCF28D25409F030025F7B3 /* ResolvedImage.swift */; }; 0CC6EF0B25C3263400BFB153 /* ModelLayerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC6EEFC25C3263400BFB153 /* ModelLayerIntegrationTests.swift */; }; 0CC6EF0E25C3263400BFB153 /* BackgroundLayerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CC6EEFD25C3263400BFB153 /* BackgroundLayerIntegrationTests.swift */; }; @@ -164,8 +162,6 @@ 2B8637E62463F36400698135 /* DistanceFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B8637D72461992200698135 /* DistanceFormatter.swift */; }; 5A35924524644C5E00E67344 /* CompassDirectionFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A359243246448E600E67344 /* CompassDirectionFormatter.swift */; }; 5A3592B3246C1FA000E67344 /* MapboxInfoButtonOrnament.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3592AC246AD45500E67344 /* MapboxInfoButtonOrnament.swift */; }; - 5A3593B6247FD9AD00E67344 /* LayoutVisibility.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3593B5247FD9AC00E67344 /* LayoutVisibility.swift */; }; - 5A3593B9247FDA4800E67344 /* LayoutPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A3593B8247FDA4800E67344 /* LayoutPosition.swift */; }; 5A9648FE246429C3001FF05D /* MapboxCompassOrnamentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A9648FC2462F07B001FF05D /* MapboxCompassOrnamentView.swift */; }; B506A5A025E023E90097ADB7 /* Bundle+MapboxMapsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B506A59E25E023E90097ADB7 /* Bundle+MapboxMapsTests.swift */; }; B506A5A125E023E90097ADB7 /* Bundle+MapboxMapsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B506A59E25E023E90097ADB7 /* Bundle+MapboxMapsTests.swift */; }; @@ -201,6 +197,7 @@ C69F0142254358B3001AB49B /* LocationManagerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69F011125431AF4001AB49B /* LocationManagerIntegrationTests.swift */; }; C69F015A254358C5001AB49B /* AnnotationManagerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07958C23253A2AE50043ECC0 /* AnnotationManagerIntegrationTests.swift */; }; C69F017525435C55001AB49B /* LocationProviderMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69F017325435C55001AB49B /* LocationProviderMock.swift */; }; + C6F256EF261FB99C0093D353 /* LogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6F256EE261FB99C0093D353 /* LogoView.swift */; }; CA0492D6261382E900CF458A /* StyleURI.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA0492D5261382E900CF458A /* StyleURI.swift */; }; CA050571259104E200FF7D02 /* FeatureQueryingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07B82A652548C1320048D0F2 /* FeatureQueryingTest.swift */; }; CA05A7202551C89600ABF902 /* CacheManagerIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA05A71E2551C89600ABF902 /* CacheManagerIntegrationTests.swift */; }; @@ -396,7 +393,6 @@ 07D2C7DA2523EBE60025C2BA /* PolygonAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolygonAnnotation.swift; sourceTree = ""; }; 07D2C80B2523ECC40025C2BA /* PolygonAnnotationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PolygonAnnotationTests.swift; sourceTree = ""; }; 07D7150325798CD70025BF61 /* UIImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIImage.swift; sourceTree = ""; }; - 07D71590257994430025BF61 /* MapboxLogoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapboxLogoView.swift; sourceTree = ""; }; 07E4FD1A24E4A35600D734D1 /* MapboxMapsAnnotations.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MapboxMapsAnnotations.h; sourceTree = ""; }; 07E4FD1B24E4A35600D734D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 07E4FD2724E4A35600D734D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -490,7 +486,6 @@ 0C9DE382252C299800880CC8 /* GeoJSONSourceDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeoJSONSourceDataTests.swift; sourceTree = ""; }; 0CA3DD5E257AAE3B00B12C8F /* SkyLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SkyLayer.swift; sourceTree = ""; }; 0CAC3CA92534E8CC00D031E7 /* ResourceOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResourceOptions.swift; sourceTree = ""; }; - 0CAC3CC22534E90500D031E7 /* MapSnapshotOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapSnapshotOptions.swift; sourceTree = ""; }; 0CBCF28D25409F030025F7B3 /* ResolvedImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResolvedImage.swift; sourceTree = ""; }; 0CBCF2D7254229630025F7B3 /* STYLE_README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; name = STYLE_README.md; path = ../../../Mapbox/STYLE_README.md; sourceTree = ""; }; 0CC6EEFC25C3263400BFB153 /* ModelLayerIntegrationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelLayerIntegrationTests.swift; sourceTree = ""; }; @@ -572,8 +567,6 @@ 5A35924F246598F600E67344 /* CompassDirectionFormatterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompassDirectionFormatterTests.swift; sourceTree = ""; }; 5A3592AC246AD45500E67344 /* MapboxInfoButtonOrnament.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapboxInfoButtonOrnament.swift; sourceTree = ""; }; 5A3593792476DEB800E67344 /* MapboxCompassOrnamentViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapboxCompassOrnamentViewTests.swift; sourceTree = ""; }; - 5A3593B5247FD9AC00E67344 /* LayoutVisibility.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutVisibility.swift; sourceTree = ""; }; - 5A3593B8247FDA4800E67344 /* LayoutPosition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutPosition.swift; sourceTree = ""; }; 5A9648FC2462F07B001FF05D /* MapboxCompassOrnamentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapboxCompassOrnamentView.swift; sourceTree = ""; }; A43D7B5125196D1C00951460 /* Annotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Annotation.swift; sourceTree = ""; }; A44EE617244ED578006FE97E /* QuickZoomGestureHandlerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuickZoomGestureHandlerTests.swift; sourceTree = ""; }; @@ -612,6 +605,7 @@ C64ED33B253F819B00ADADFB /* LocationConsumerMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationConsumerMock.swift; sourceTree = ""; }; C69F011125431AF4001AB49B /* LocationManagerIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManagerIntegrationTests.swift; sourceTree = ""; }; C69F017325435C55001AB49B /* LocationProviderMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationProviderMock.swift; sourceTree = ""; }; + C6F256EE261FB99C0093D353 /* LogoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogoView.swift; sourceTree = ""; }; CA0492D5261382E900CF458A /* StyleURI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StyleURI.swift; sourceTree = ""; }; CA05A71E2551C89600ABF902 /* CacheManagerIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheManagerIntegrationTests.swift; sourceTree = ""; }; CA0B374325C4BEAE00B3396E /* MapboxMapsHTTPTestsWithHost.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MapboxMapsHTTPTestsWithHost.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -884,9 +878,6 @@ children = ( 0C1AF55B244DF500008D2A10 /* MapOptions.swift */, 0C1AF564244F65E6008D2A10 /* OrnamentOptions.swift */, - 5A3593B5247FD9AC00E67344 /* LayoutVisibility.swift */, - 5A3593B8247FDA4800E67344 /* LayoutPosition.swift */, - 0CAC3CC22534E90500D031E7 /* MapSnapshotOptions.swift */, 0CC9937D25D46B7100650CC1 /* RenderOptions.swift */, ); path = Configuration; @@ -1118,12 +1109,12 @@ 1F11C1102421B05600F8397B /* MapboxMapsFoundation */ = { isa = PBXGroup; children = ( + C6F256EE261FB99C0093D353 /* LogoView.swift */, 07855E29258BFCD90060A870 /* Extensions */, 1F11C1112421B05600F8397B /* MapboxMapsFoundation.h */, 1F11C1122421B05600F8397B /* Info.plist */, 1F2AD70A2421BCBF006592F4 /* AccountManager.swift */, 0C95DBB8257A92F90018252C /* BaseMapView.swift */, - 07D71590257994430025BF61 /* MapboxLogoView.swift */, 07A0BC9D2582F15B00B8E109 /* GeoJSONManager.swift */, 1F4B7D7A2464C36E00745F05 /* Camera */, 07625BB42587F273002EEBCC /* Events */, @@ -1819,7 +1810,6 @@ 07980ECE251D5B5D00730DB7 /* LineAnnotation.swift in Sources */, 0742060024E4A598000A8932 /* AnnotationManager.swift in Sources */, 0C708F5324EB23C7003CE791 /* RasterSource.swift in Sources */, - 5A3593B9247FDA4800E67344 /* LayoutPosition.swift in Sources */, 0CE8ED6125890F870066E56C /* ModelSource.swift in Sources */, C64994A9258D5ADE0052C21C /* LocationPuckManager.swift in Sources */, 5A35924524644C5E00E67344 /* CompassDirectionFormatter.swift in Sources */, @@ -1850,7 +1840,6 @@ CA0492D6261382E900CF458A /* StyleURI.swift in Sources */, 0C708F5924EB2927003CE791 /* Sources.swift in Sources */, 0C708F2524EB1EE2003CE791 /* HillshadeLayer.swift in Sources */, - 0CAC3CC32534E90500D031E7 /* MapSnapshotOptions.swift in Sources */, 0C708F2124EB1EE2003CE791 /* FillExtrusionLayer.swift in Sources */, 0C26425524EECD14001FE2E3 /* AllExpressions.swift in Sources */, 0782B1A3258C250400D5FCE5 /* Geometry.swift in Sources */, @@ -1863,6 +1852,7 @@ 0C3B1E9224DDADD000CC29E8 /* MapboxMobileEvents+TelemetryProtocol.swift in Sources */, 0C9640E12531056700CABD3E /* LocationConsumer.swift in Sources */, 0C708F4D24EB23C7003CE791 /* RasterDemSource.swift in Sources */, + C6F256EF261FB99C0093D353 /* LogoView.swift in Sources */, 0CD62F23245887C8006421D1 /* OrnamentsManager.swift in Sources */, CA0C427E2602BECE0054D9D0 /* LayerPosition.swift in Sources */, 07A0BCCB2582F16300B8E109 /* GeoJSONManager.swift in Sources */, @@ -1895,7 +1885,6 @@ B5B55D45260E4D1500EBB589 /* AnimationOwner.swift in Sources */, 0CD34FE8242AAE0900943687 /* MapView+Managers.swift in Sources */, B5B55D44260E4D1500EBB589 /* CameraAnimator.swift in Sources */, - 5A3593B6247FD9AD00E67344 /* LayoutVisibility.swift in Sources */, 0CD62F12245885AA006421D1 /* AccountManager.swift in Sources */, 5A9648FE246429C3001FF05D /* MapboxCompassOrnamentView.swift in Sources */, 0C8AA1F3257FE1830037FD6B /* MapEvents.swift in Sources */, @@ -1932,7 +1921,6 @@ 1FECC9E02474519D00B63910 /* Expression.swift in Sources */, B52050A8260538240003E5BB /* ModelLayer.swift in Sources */, 0CD62F1124588532006421D1 /* GestureHandlerDelegate.swift in Sources */, - 07D71591257994430025BF61 /* MapboxLogoView.swift in Sources */, 0782B061258C16B200D5FCE5 /* Utils.swift in Sources */, 0CD62F2C24588937006421D1 /* Style.swift in Sources */, 0CAC3CAA2534E8CC00D031E7 /* ResourceOptions.swift in Sources */, From 33cf35d2c4182ff2bc3fb66d1d394a2d46e468c2 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Fri, 9 Apr 2021 11:46:32 -0400 Subject: [PATCH 15/19] update changelog to reflect breaking changes --- CHANGELOG.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71323c37799e..c1152d648f64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,51 @@ Mapbox welcomes participation and contributions from everyone. - `AnnotationManager` no longer conforms to `Observer` and no longer has a `peer` ([#246](https://github.com/mapbox/mapbox-maps-ios/pull/246)) - `AnnotationSupportableMap` is now internal ([#246](https://github.com/mapbox/mapbox-maps-ios/pull/246)) +- #### MapView + * Initializer has been change to `public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets)`. + * The following 4 functions have been removed: + * `public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D` + * `public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint` + * `public func coordinateBounds(for view: UIView) -> CoordinateBounds` + * `public func rect(for coordinateBounds: CoordinateBounds, in view: UIView? = nil) -> CGRect` + * `OrnamentSupportableMapView` is not internal. + +- #### Ornaments + * `LayoutPosition` has been deprecated in favor of `OrnamentPosition`. + * `LayoutVisibility` has been depracted in favor of `OrnamentVisibility`. + * `showsLogoView` has been renamed to `_showsLogoView`. + * `showsCompass` and `showsScale` have been depracted. You should now use the visibility properties to set how the Compass and Scale Bar should be shown. + +- #### Foundation + * `cancelTransitions` has been renamed to `cancelAnimations`. + * [`setCamera()`](https://github.com/mapbox/mapbox-maps-ios/pull/250/files#diff-8fa667141ac423a208a6e7036ed759e7e52fc6940bd58834c1935c2c6ead9c65L177) with individual params,has been deprecated in favor of [this](https://github.com/mapbox/mapbox-maps-ios/blob/edbf08e37975c81c7ee1cbc4bb046c48d522d306/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift#L140) one that requires `CameraOptions`. + * The following camera convenience functions have been deprecated: + * `public func transitionCoordinateBounds(newCoordinateBounds: CoordinateBounds, animated: Bool = false)` + * `public func transitionCoordinateBounds(to newCoordinateBounds: CoordinateBounds, edgePadding: UIEdgeInsets, animated: Bool = false, completion: ((UIViewAnimatingPosition) -> Void)? = nil)` + * `public func transitionVisibleCoordinates(newCoordinates: [CLLocationCoordinate2D], edgePadding: UIEdgeInsets, animated: Bool = false)` + * `public func transitionVisibleCoordinates(to newCoordinates: [CLLocationCoordinate2D], edgePadding: UIEdgeInsets, bearing: CLLocationDirection, duration: TimeInterval, animated: Bool = false, completion: ((UIViewAnimatingPosition) -> Void)? = nil)` + * `public func resetPosition()` + * `public func resetNorth(_ animated: Bool = false)` + * In `CameraAnimator`, `fractionComplete` is now of type `Double`, and `delayFactor` now returns a `Double`. + * `EventType` is internal. + * `MBXEdgeInsets` extension is internal. + * `ScreenCoordinate` extension is internal. + * `MapboxLogoView` has been renamed to `LogoView`. + * `MapboxLogoSize` has been renamed to `LogoSize`. + +- #### Style + * Initializer is now marked as internal. + * `styleUri` has been renamed to `uri`. + * The `url` property from `StyleURL` has been removed. + +- #### Expressions + * `ExpressionBuilder` has been renamed to `FunctionBuilder`. + * `init(from: jsonObject)` and `public func jsonObject()` have been deprecated. + * `Element.op` has been renamed to `Element.operator`. + * `Argument.array` has been renamed to `Argument.numberArray`. + * `ValidExpressionArgument` has been renamed to `ExpressionArgumentConvertible` + + ### Bug fixes 🐞 - Fixes an issue that could cause issues with annotations including causing them to not be selectable ([#246](https://github.com/mapbox/mapbox-maps-ios/pull/246)) From f78302640762b0a81c326136aec29c04ef0f4e77 Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Fri, 9 Apr 2021 14:06:40 -0400 Subject: [PATCH 16/19] pr comments --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1152d648f64..c8df87ad782c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Mapbox welcomes participation and contributions from everyone. - `AnnotationSupportableMap` is now internal ([#246](https://github.com/mapbox/mapbox-maps-ios/pull/246)) - #### MapView - * Initializer has been change to `public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets)`. + * Initializer has been changed to `public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets)`. * The following 4 functions have been removed: * `public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D` * `public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint` @@ -20,19 +20,19 @@ Mapbox welcomes participation and contributions from everyone. * `LayoutPosition` has been deprecated in favor of `OrnamentPosition`. * `LayoutVisibility` has been depracted in favor of `OrnamentVisibility`. * `showsLogoView` has been renamed to `_showsLogoView`. - * `showsCompass` and `showsScale` have been depracted. You should now use the visibility properties to set how the Compass and Scale Bar should be shown. + * `showsCompass` and `showsScale` have been deprecated. Visibility properties can be used to set how the Compass and Scale Bar should be shown. - #### Foundation * `cancelTransitions` has been renamed to `cancelAnimations`. - * [`setCamera()`](https://github.com/mapbox/mapbox-maps-ios/pull/250/files#diff-8fa667141ac423a208a6e7036ed759e7e52fc6940bd58834c1935c2c6ead9c65L177) with individual params,has been deprecated in favor of [this](https://github.com/mapbox/mapbox-maps-ios/blob/edbf08e37975c81c7ee1cbc4bb046c48d522d306/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift#L140) one that requires `CameraOptions`. - * The following camera convenience functions have been deprecated: + * [`setCamera()`](https://github.com/mapbox/mapbox-maps-ios/pull/250/files#diff-8fa667141ac423a208a6e7036ed759e7e52fc6940bd58834c1935c2c6ead9c65L177) with individual parameters has been deprecated in favor of [`setCamera(to targetCamera: CameraOptions...)`](https://github.com/mapbox/mapbox-maps-ios/blob/edbf08e37975c81c7ee1cbc4bb046c48d522d306/Sources/MapboxMaps/Foundation/Camera/CameraManager.swift#L140) which requires `CameraOptions`. + * The following camera convenience functions have been removed: * `public func transitionCoordinateBounds(newCoordinateBounds: CoordinateBounds, animated: Bool = false)` * `public func transitionCoordinateBounds(to newCoordinateBounds: CoordinateBounds, edgePadding: UIEdgeInsets, animated: Bool = false, completion: ((UIViewAnimatingPosition) -> Void)? = nil)` * `public func transitionVisibleCoordinates(newCoordinates: [CLLocationCoordinate2D], edgePadding: UIEdgeInsets, animated: Bool = false)` * `public func transitionVisibleCoordinates(to newCoordinates: [CLLocationCoordinate2D], edgePadding: UIEdgeInsets, bearing: CLLocationDirection, duration: TimeInterval, animated: Bool = false, completion: ((UIViewAnimatingPosition) -> Void)? = nil)` * `public func resetPosition()` * `public func resetNorth(_ animated: Bool = false)` - * In `CameraAnimator`, `fractionComplete` is now of type `Double`, and `delayFactor` now returns a `Double`. + * In `CameraAnimator`, `fractionComplete` is now of type `Double` and `delayFactor` now returns a `Double`. * `EventType` is internal. * `MBXEdgeInsets` extension is internal. * `ScreenCoordinate` extension is internal. From d1efbd25b3ab66ccf791e8f2941fede880561ecd Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Fri, 9 Apr 2021 14:21:06 -0400 Subject: [PATCH 17/19] Changelog cleanup --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8df87ad782c..831919acd3e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ Mapbox welcomes participation and contributions from everyone. - #### Expressions * `ExpressionBuilder` has been renamed to `FunctionBuilder`. - * `init(from: jsonObject)` and `public func jsonObject()` have been deprecated. + * `init(from: jsonObject)` and `public func jsonObject()` have been removed. * `Element.op` has been renamed to `Element.operator`. * `Argument.array` has been renamed to `Argument.numberArray`. * `ValidExpressionArgument` has been renamed to `ExpressionArgumentConvertible` From 5a8d63c9c1c9d714c1348efca44373599287592e Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Fri, 9 Apr 2021 14:29:22 -0400 Subject: [PATCH 18/19] reverting removal for coordinate for functions --- ...UpdatePointAnnotationPositionExample.swift | 4 +- CHANGELOG.md | 5 - .../MapboxMaps/Foundation/BaseMapView.swift | 74 +++++++++ .../MapboxMapsFoundationTests.swift | 157 ++++++++++++++++++ 4 files changed, 232 insertions(+), 8 deletions(-) diff --git a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift index 691b7009a040..2c0f9e22ad50 100644 --- a/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift +++ b/Apps/Examples/Examples/All Examples/UpdatePointAnnotationPositionExample.swift @@ -40,9 +40,7 @@ public class UpdatePointAnnotationPositionExample: UIViewController, ExampleProt } @objc public func updatePosition(_ sender: UITapGestureRecognizer) { - let point = mapView.convert(sender.location(in: mapView), to: mapView) - let screenCoordinate = ScreenCoordinate(x: Double(point.x), y: Double(point.y)) - let newCoordinate = try! mapView.__map.coordinateForPixel(forPixel: screenCoordinate) + let newCoordinate = mapView.coordinate(for: sender.location(in: mapView)) pointAnnotation.coordinate = newCoordinate do { diff --git a/CHANGELOG.md b/CHANGELOG.md index 831919acd3e3..eb0526411574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,6 @@ Mapbox welcomes participation and contributions from everyone. - #### MapView * Initializer has been changed to `public init(frame: CGRect, resourceOptions: ResourceOptions, glyphsRasterizationOptions: GlyphsRasterizationOptions = GlyphsRasterizationOptions.default, styleURI: StyleURI? = .streets)`. - * The following 4 functions have been removed: - * `public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D` - * `public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint` - * `public func coordinateBounds(for view: UIView) -> CoordinateBounds` - * `public func rect(for coordinateBounds: CoordinateBounds, in view: UIView? = nil) -> CGRect` * `OrnamentSupportableMapView` is not internal. - #### Ornaments diff --git a/Sources/MapboxMaps/Foundation/BaseMapView.swift b/Sources/MapboxMaps/Foundation/BaseMapView.swift index ee1521bae517..b17897bd66da 100644 --- a/Sources/MapboxMaps/Foundation/BaseMapView.swift +++ b/Sources/MapboxMaps/Foundation/BaseMapView.swift @@ -440,6 +440,80 @@ open class BaseMapView: UIView, MapClient, MBMMetalViewProvider, CameraViewDeleg return metalView } + + // MARK: Conversion utilities + /** + Converts a point in a given view’s coordinate system to a geographic coordinate. + + - Parameter point: The point to convert. + - Parameter view: An optional view the `point` is relative to. + Omitting this value assumes the point is relative to the `MapView`. + - Returns: A CLLocationCoordinate that represents the geographic location of the point. + */ + public func coordinate(for point: CGPoint, in view: UIView? = nil) -> CLLocationCoordinate2D { + let view = view ?? self + let screenCoordinate = convert(point, from: view).screenCoordinate // Transform to view's coordinate space + return try! __map.coordinateForPixel(forPixel: screenCoordinate) + } + + /** + Converts a map coordinate to a `CGPoint`, relative to the map view. + + - Parameter coordinate: The coordinate to convert. + - Parameter view: An optional view the resulting point will be relative to. + Omitting this value assumes resulting `CGPoint` will be expressed + relative to the `MapView`. + - Returns: A `CGPoint` relative to the `UIView`. + */ + public func point(for coordinate: CLLocationCoordinate2D, in view: UIView? = nil) -> CGPoint { + let view = view ?? self + let point = try! __map.pixelForCoordinate(for: coordinate).point + let transformedPoint = convert(point, to: view) + return transformedPoint + } + + /** + Transforms a view's frame into a set of coordinate bounds. + + - Parameter view: The `UIView` whose bounds will be transformed into a set of map coordinate bounds. + - Returns: A `CoordinateBounds` object that represents the southwest and northeast corners of the view's bounds. + */ + public func coordinateBounds(for view: UIView) -> CoordinateBounds { + let rect = view.bounds + + let topRight = coordinate(for: CGPoint(x: rect.maxX, y: rect.minY), in: view).wrap() + let bottomLeft = coordinate(for: CGPoint(x: rect.minX, y: rect.maxY), in: view).wrap() + + let southwest = CLLocationCoordinate2D(latitude: bottomLeft.latitude, longitude: bottomLeft.longitude) + let northeast = CLLocationCoordinate2D(latitude: topRight.latitude, longitude: topRight.longitude) + + return CoordinateBounds(southwest: southwest, northeast: northeast) + } + + /** + Transforms a set of map coordinate bounds to a `CGRect`. + + - Parameter view: An optional `UIView` whose coordinate space the resulting `CGRect` will be relative to. + Omitting this value assumes the resulting `CGRect` will be expressed + relative to the `MapView`. + - Returns: A `CGRect` whose corners represent the vertices of a set of `CoordinateBounds`. + */ + public func rect(for coordinateBounds: CoordinateBounds, in view: UIView? = nil) -> CGRect { + let view = view ?? self + let southwest = coordinateBounds.southwest.wrap() + let northeast = coordinateBounds.northeast.wrap() + + var rect = CGRect.zero + + let swPoint = point(for: southwest, in: view) + let nePoint = point(for: northeast, in: view) + + rect = CGRect(origin: swPoint, size: CGSize.zero) + + rect = rect.extend(from: nePoint) + + return rect + } } private class BaseMapViewProxy: NSObject { diff --git a/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift b/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift index 6c389a86a8d1..7ea71295b708 100644 --- a/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift +++ b/Tests/MapboxMapsTests/Foundation/MapboxMapsFoundationTests.swift @@ -56,6 +56,125 @@ class MapboxMapsFoundationTests: XCTestCase { XCTAssertEqual(coordinate.longitude, coordinate.wrap().longitude) } + // MARK: Converting between points and coordinates + + func testCoordinateToPoint() { + let centerCoordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) + let convertedPoint = mapView.point(for: centerCoordinate, in: mapView) + + XCTAssertEqual(convertedPoint.x, mapView.bounds.midX, accuracy: 0.01) + XCTAssertEqual(convertedPoint.y, mapView.bounds.midY, accuracy: 0.01) + } + + func testPointToCoordinateInSubviewWithEqualCenter() { + let subView = UIView(frame: mapView.bounds) + mapView.addSubview(subView) + + // Convert the subview's center to a coordinate. + // The subview's center is expected to be at the center coordinate of the map. + let center = CGPoint(x: subView.bounds.midX, y: subView.bounds.midY) + let coordinate = mapView.coordinate(for: center, in: subView) + + XCTAssertEqual(coordinate.latitude, CLLocationDegrees(0), accuracy: accuracy) + XCTAssertEqual(coordinate.longitude, CLLocationDegrees(0), accuracy: accuracy) + } + + func testPointToCoordinateInSubViewEqualOrigins() { + let subViewRect = CGRect(x: 0, + y: 0, + width: mapView.bounds.size.width / 2, + height: mapView.bounds.size.height / 2) + let subview = UIView(frame: subViewRect) + + mapView.addSubview(subview) + + /** + We shouldn't expect the centers to be the same, since now that the + mapView is offset. The "center" is in the space of the parent view. + */ + subview.center = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) + XCTAssertNotEqual(subview.center, mapView.center, "Center of both views are not equal") + XCTAssertEqual(subview.frame.origin.x, 25.0) + XCTAssertEqual(subview.frame.origin.y, 25.0) + + let updatedSubViewOrigin = subview.frame.origin + let originCoordinateA = mapView.coordinate(for: updatedSubViewOrigin, in: mapView) + let originCoordinateB = mapView.coordinate(for: CGPoint.zero, in: subview) + + XCTAssertEqual(originCoordinateA.latitude, originCoordinateB.latitude, accuracy: accuracy) + XCTAssertEqual(originCoordinateA.longitude, originCoordinateB.longitude, accuracy: accuracy) + + // The subview's origin is expected to be 1/4 of the map view's height and width +// let expectedSubViewOrigin = CGPoint(x: mapView.bounds.width * 0.25, y: mapView.bounds.height * 0.25) +// let convertedSubViewOrigin = mapView.convert(expectedSubViewOrigin, to: subview) +// // So this should be zero +// XCTAssertEqual(convertedSubViewOrigin, .zero) +// +// let originCoordinateC = mapView.convert(convertedSubViewOrigin, toCoordinateFrom: subview) +// +// XCTAssertEqual(originCoordinateB.latitude, originCoordinateC.latitude, accuracy: accuracy) +// XCTAssertEqual(originCoordinateB.longitude, originCoordinateC.longitude, accuracy: accuracy) +// +// XCTAssertEqual(originCoordinateA.latitude, originCoordinateC.latitude, accuracy: accuracy) +// XCTAssertEqual(originCoordinateA.longitude, originCoordinateC.longitude, accuracy: accuracy) + } + + func testPointToCoordinateWithBoundsShifted() { + // Shift bounds down and right 1/2 of the map's size + mapView.bounds = CGRect(x: mapView.frame.midX, + y: mapView.frame.midY, + width: mapView.frame.width, + height: mapView.frame.height) + + let mapViewFrameCenterPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) + let mapViewFrameCenterCoordinate = mapView.coordinate(for: mapViewFrameCenterPoint, in: mapView) + let mapViewBoundsOriginCoordinate = mapView.coordinate(for: mapView.bounds.origin, in: mapView) + + XCTAssertEqual(mapViewFrameCenterCoordinate.latitude, + mapViewBoundsOriginCoordinate.latitude, + accuracy: accuracy) + XCTAssertEqual(mapViewFrameCenterCoordinate.longitude, + mapViewBoundsOriginCoordinate.longitude, + accuracy: accuracy) + } + + func testPointToCoordinateWithBoundsShifted2() { + let originalCenter = mapView.center + let originalMapViewBoundsCenterPoint = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) + let originalMapViewBoundsCenterCoordinate = mapView.coordinate(for: originalMapViewBoundsCenterPoint, + in: mapView) + + // Shift bounds by some arbitrary offset + mapView.bounds = CGRect(x: 30, + y: -30, + width: mapView.frame.width, + height: mapView.frame.height) + + let mapViewFrameCenterPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) + let mapViewBoundsCenterPoint = CGPoint(x: mapView.bounds.midX, y: mapView.bounds.midY) + + // Frame should not have changed, since we're only changing the bounds + XCTAssertEqual(originalCenter, mapView.center) + XCTAssertEqual(originalCenter, mapViewFrameCenterPoint) + + let mapViewBoundsCenterCoordinate = mapView.coordinate(for: mapViewBoundsCenterPoint, in: mapView) + + // Adjusting the bounds should affect the coordinate conversion + XCTAssertNotEqual(originalMapViewBoundsCenterCoordinate.latitude, mapViewBoundsCenterCoordinate.latitude) + XCTAssertNotEqual(originalMapViewBoundsCenterCoordinate.longitude, mapViewBoundsCenterCoordinate.longitude) + } + + func testConvertCoordinateRoundTrip() { + // Convert a point to a coordinate and back to a point + let originalPoint = CGPoint(x: mapView.frame.midX, y: mapView.frame.midY) + + let coordinate = mapView.coordinate(for: originalPoint, in: mapView) + let point = mapView.point(for: coordinate, in: mapView) + + XCTAssertEqual(originalPoint.x, point.x, accuracy: CGFloat(accuracy)) + XCTAssertEqual(originalPoint.y, point.y, accuracy: CGFloat(accuracy)) + } + // MARK: Converting between CGRect and coordinate bounds func testRectExtend() { @@ -70,6 +189,44 @@ class MapboxMapsFoundationTests: XCTestCase { XCTAssertEqual(expectedRect, actualRect) } + func testCoordinateBoundsToRect() { + let southwest = CLLocationCoordinate2D(latitude: -20, longitude: -20) + let northeast = CLLocationCoordinate2D(latitude: 20, longitude: 20) + + let bounds = CoordinateBounds(southwest: southwest, northeast: northeast) + + let southeast = bounds.southeast + let northwest = bounds.northwest + + let rect = mapView.rect(for: bounds, in: mapView) + + // Test southwest points + let swPoint = mapView.point(for: southwest, in: mapView) + let swRect = CGPoint(x: rect.minX, y: rect.maxY) + + XCTAssertEqual(swPoint.x, swRect.x, accuracy: 0.1) + XCTAssertEqual(swPoint.y, swRect.y, accuracy: 0.1) + + // Test southeast points + let sePoint = mapView.point(for: southeast, in: mapView) + let seRect = CGPoint(x: rect.maxX, y: rect.maxY) + + XCTAssertEqual(sePoint.x, seRect.x, accuracy: 0.1) + XCTAssertEqual(sePoint.y, seRect.y, accuracy: 0.1) + + // Test northwest points + let nwPoint = mapView.point(for: northwest, in: mapView) + let nwRect = CGPoint(x: rect.minX, y: rect.minY) + XCTAssertEqual(nwPoint.x, nwRect.x, accuracy: 0.1) + XCTAssertEqual(nwPoint.y, nwRect.y, accuracy: 0.1) + + // Test northeast points + let nePoint = mapView.point(for: northeast, in: mapView) + let neRect = CGPoint(x: rect.maxX, y: rect.minY) + XCTAssertEqual(nePoint.x, neRect.x, accuracy: 0.1) + XCTAssertEqual(nePoint.y, neRect.y, accuracy: 0.1) + } + func testImageConversion() { guard let original = UIImage(named: "green-star", in: .mapboxMapsTests, compatibleWith: nil) else { XCTFail("Could not load test image from bundle") From b03de0991f6917e10c8afb37d127a033a38aec2a Mon Sep 17 00:00:00 2001 From: Neel Mistry Date: Fri, 9 Apr 2021 15:16:46 -0400 Subject: [PATCH 19/19] Reverting function builder change and final changelog cleanup --- CHANGELOG.md | 4 ---- .../Foundation/Extensions/Core/ResourceOptions.swift | 2 +- Sources/MapboxMaps/Style/Types/Expression.swift | 2 +- Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift | 2 +- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb0526411574..06d066f03d1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,9 +28,6 @@ Mapbox welcomes participation and contributions from everyone. * `public func resetPosition()` * `public func resetNorth(_ animated: Bool = false)` * In `CameraAnimator`, `fractionComplete` is now of type `Double` and `delayFactor` now returns a `Double`. - * `EventType` is internal. - * `MBXEdgeInsets` extension is internal. - * `ScreenCoordinate` extension is internal. * `MapboxLogoView` has been renamed to `LogoView`. * `MapboxLogoSize` has been renamed to `LogoSize`. @@ -40,7 +37,6 @@ Mapbox welcomes participation and contributions from everyone. * The `url` property from `StyleURL` has been removed. - #### Expressions - * `ExpressionBuilder` has been renamed to `FunctionBuilder`. * `init(from: jsonObject)` and `public func jsonObject()` have been removed. * `Element.op` has been renamed to `Element.operator`. * `Argument.array` has been renamed to `Argument.numberArray`. diff --git a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift index 9b823097eff5..5f78e2883c18 100644 --- a/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift +++ b/Sources/MapboxMaps/Foundation/Extensions/Core/ResourceOptions.swift @@ -11,7 +11,7 @@ extension ResourceOptions { /// - assetPath: The path to the assets. /// - tileStorePath: The path to the tile store. /// - loadTilePacksFromNetwork: Detemines if tiles pack should or should not be avoided from the network. - /// - cacheSize: The size of the cahce. + /// - cacheSize: The size of the cache. public convenience init(accessToken: String, baseUrl: String? = nil, cachePath: String? = nil, diff --git a/Sources/MapboxMaps/Style/Types/Expression.swift b/Sources/MapboxMaps/Style/Types/Expression.swift index e478cec000a9..d29b1c647282 100644 --- a/Sources/MapboxMaps/Style/Types/Expression.swift +++ b/Sources/MapboxMaps/Style/Types/Expression.swift @@ -9,7 +9,7 @@ public struct Expression: Codable, CustomStringConvertible, Equatable { // swiftlint:disable identifier_name public init(_ op: Expression.Operator, - @FunctionBuilder content: () -> Expression = { Expression(with: [.argument(.null)])}) { + @ExpressionBuilder content: () -> Expression = { Expression(with: [.argument(.null)])}) { var elements = content().elements if elements.count == 1 && elements[0] == .argument(.null) { diff --git a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift index 717b277e9994..5e786aa598ce 100644 --- a/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift +++ b/Sources/MapboxMaps/Style/Types/ExpressionBuilder.swift @@ -2,7 +2,7 @@ import Foundation import UIKit @_functionBuilder -public struct FunctionBuilder { +public struct ExpressionBuilder { public static func buildBlock(_ arguments: ExpressionArgumentConvertible...) -> Expression {