Skip to content

Commit 34ea7ad

Browse files
authored
Set model-type to location-indicator for 3D puck (#641)
- Delete unneeded LocationSupportableMapView protocol - Rename LocationStyleDelegate to LocationStyleProtocol - Remove ModelLayerTests from Generated directory
1 parent 1660b25 commit 34ea7ad

21 files changed

+75
-122
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Mapbox welcomes participation and contributions from everyone.
2121
* Use `syncAnnotationsIfNeeded()` to force the sync to happen earlier if needed.
2222
* Enable instant transitions for data driven paint layer properties ([#628](https://github.com/mapbox/mapbox-maps-ios/pull/628))
2323
* Offload networking tasks at the init phase ([#631](https://github.com/mapbox/mapbox-maps-ios/pull/631))
24+
* 3D pucks will now be rendered over other 3D content and occluded by terrain ([#641](https://github.com/mapbox/mapbox-maps-ios/pull/641))
2425

2526
### Bug fixes 🐞
2627

Sources/MapboxMaps/Foundation/MapView+Supportable.swift

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,4 @@ extension MapView: OrnamentSupportableView {
3131
}
3232
}
3333

34-
@available(iOSApplicationExtension, unavailable)
35-
extension MapView: LocationSupportableMapView {
36-
37-
public func point(for coordinate: CLLocationCoordinate2D) -> CGPoint {
38-
return mapboxMap.point(for: coordinate)
39-
}
40-
41-
public func metersPerPointAtLatitude(latitude: CLLocationDegrees) -> CLLocationDistance {
42-
return Projection.metersPerPoint(for: latitude, zoom: cameraState.zoom)
43-
}
44-
45-
public func subscribeRenderFrameHandler(_ handler: @escaping (MapboxCoreMaps.Event) -> Void) {
46-
mapboxMap.onEvery(.renderFrameStarted) { (event) in
47-
handler(event)
48-
}
49-
}
50-
51-
}
52-
53-
extension Style: LocationStyleDelegate { }
34+
extension Style: LocationStyleProtocol { }

Sources/MapboxMaps/Foundation/MapView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ open class MapView: UIView {
231231
ornaments = OrnamentsManager(view: self, options: OrnamentOptions(), infoButtonOrnamentDelegate: attributionDialogManager)
232232

233233
// Initialize/Configure location manager
234-
location = LocationManager(locationSupportableMapView: self, style: mapboxMap.style)
234+
location = LocationManager(style: mapboxMap.style)
235235

236236
// Initialize/Configure annotations orchestrator
237237
annotations = AnnotationOrchestrator(view: self, mapFeatureQueryable: mapboxMap, style: mapboxMap.style, displayLinkCoordinator: self)

Sources/MapboxMaps/Location/LocationManager.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ public class LocationManager: NSObject {
2828
return hashTable
2929
}()
3030

31-
/// `MapView` that has specific functionality to support location
32-
internal weak var locationSupportableMapView: LocationSupportableMapView!
33-
3431
/// Style that has limited functionality to support location
35-
internal weak var style: LocationStyleDelegate?
32+
internal weak var style: LocationStyleProtocol?
3633

3734
/// Manager that handles the visual puck element.
3835
/// Only created if `showsUserLocation` is `true`
@@ -57,10 +54,7 @@ public class LocationManager: NSObject {
5754
}
5855
}
5956

60-
internal init(locationSupportableMapView: LocationSupportableMapView, style: LocationStyleDelegate) {
61-
62-
/// Allows location updates to be reflected on screen using delegate method
63-
self.locationSupportableMapView = locationSupportableMapView
57+
internal init(style: LocationStyleProtocol) {
6458

6559
self.style = style
6660

@@ -200,8 +194,7 @@ private extension LocationManager {
200194
// This serves as a reset and handles the case if permissions were changed for accuracy
201195
locationPuckManager.changePuckStyle(to: currentPuckStyle)
202196
} else {
203-
let locationPuckManager = LocationPuckManager(locationSupportableMapView: locationSupportableMapView,
204-
style: style,
197+
let locationPuckManager = LocationPuckManager(style: style,
205198
puckType: puckType,
206199
puckBearingSource: options.puckBearingSource)
207200
consumers.add(locationPuckManager)

Sources/MapboxMaps/Location/LocationStyleDelegate.swift renamed to Sources/MapboxMaps/Location/LocationStyleProtocol.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
internal protocol LocationStyleDelegate: AnyObject {
1+
internal protocol LocationStyleProtocol: AnyObject {
22
func _addPersistentLayer(_ layer: Layer, layerPosition: LayerPosition?) throws
33
func removeLayer(withId id: String) throws
44
func layerExists(withId id: String) -> Bool
@@ -11,7 +11,7 @@ internal protocol LocationStyleDelegate: AnyObject {
1111
func addImage(_ image: UIImage, id: String, sdf: Bool, stretchX: [ImageStretches], stretchY: [ImageStretches], content: ImageContent?) throws
1212
}
1313

14-
extension LocationStyleDelegate {
14+
extension LocationStyleProtocol {
1515
internal func _addPersistentLayer(_ layer: Layer, layerPosition: LayerPosition? = nil) throws {
1616
try _addPersistentLayer(layer, layerPosition: layerPosition)
1717
}

Sources/MapboxMaps/Location/LocationSupportableMapView.swift

Lines changed: 0 additions & 11 deletions
This file was deleted.

Sources/MapboxMaps/Location/Pucks/LocationPuckManager.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,8 @@ internal class LocationPuckManager: LocationConsumer {
3939
/// The visual representation of a location on a map
4040
private var puck: Puck?
4141

42-
/// MapView that supports location events
43-
internal private(set) weak var locationSupportableMapView: LocationSupportableMapView?
44-
4542
/// Style protocol that supports limited style APIs
46-
internal private(set) weak var style: LocationStyleDelegate?
43+
internal private(set) weak var style: LocationStyleProtocol?
4744

4845
/// The current puck style
4946
internal private(set) var puckStyle: PuckStyle
@@ -58,14 +55,12 @@ internal class LocationPuckManager: LocationConsumer {
5855
}
5956
}
6057

61-
internal init(locationSupportableMapView: LocationSupportableMapView,
62-
style: LocationStyleDelegate?,
58+
internal init(style: LocationStyleProtocol?,
6359
puckType: PuckType,
6460
puckBearingSource: PuckBearingSource) {
6561
puckStyle = .precise
6662
self.puckType = puckType
6763
self.puckBearingSource = puckBearingSource
68-
self.locationSupportableMapView = locationSupportableMapView
6964
self.style = style
7065
}
7166

@@ -82,8 +77,7 @@ internal class LocationPuckManager: LocationConsumer {
8277
}
8378

8479
internal func createPuck() {
85-
guard let locationSupportableMapView = locationSupportableMapView,
86-
let style = style else {
80+
guard let style = style else {
8781
return
8882
}
8983

@@ -93,13 +87,11 @@ internal class LocationPuckManager: LocationConsumer {
9387
case let .puck2D(configuration):
9488
puck = Puck2D(puckStyle: puckStyle,
9589
puckBearingSource: puckBearingSource,
96-
locationSupportableMapView: locationSupportableMapView,
9790
style: style,
9891
configuration: configuration)
9992
case let .puck3D(configuration):
10093
puck = Puck3D(puckStyle: puckStyle,
10194
puckBearingSource: puckBearingSource,
102-
locationSupportableMapView: locationSupportableMapView,
10395
style: style,
10496
configuration: configuration)
10597
}

Sources/MapboxMaps/Location/Pucks/Puck.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ internal protocol Puck {
77
/// Property that stores the current `PuckBearingSource` of the puck
88
var puckBearingSource: PuckBearingSource { get set }
99

10-
/// Property that references the mapView that the puck should be draw
11-
var locationSupportableMapView: LocationSupportableMapView? { get }
12-
1310
/// This function takes in a location object and will update the current `Puck` with that location
1411
func updateLocation(location: Location)
1512

Sources/MapboxMaps/Location/Pucks/Puck2D.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,15 @@ internal class Puck2D: Puck {
5050
internal var puckStyle: PuckStyle
5151
internal var puckBearingSource: PuckBearingSource
5252

53-
internal weak var locationSupportableMapView: LocationSupportableMapView?
54-
internal weak var style: LocationStyleDelegate?
53+
internal weak var style: LocationStyleProtocol?
5554

5655
// MARK: Initializers
5756
internal init(puckStyle: PuckStyle,
5857
puckBearingSource: PuckBearingSource,
59-
locationSupportableMapView: LocationSupportableMapView,
60-
style: LocationStyleDelegate,
58+
style: LocationStyleProtocol,
6159
configuration: Puck2DConfiguration) {
6260
self.puckStyle = puckStyle
6361
self.puckBearingSource = puckBearingSource
64-
self.locationSupportableMapView = locationSupportableMapView
6562
self.style = style
6663
self.configuration = configuration
6764
}

Sources/MapboxMaps/Location/Pucks/Puck3D.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ internal class Puck3D: Puck {
3232
// MARK: Protocol Properties
3333
internal var puckStyle: PuckStyle
3434
internal var puckBearingSource: PuckBearingSource
35-
internal weak var locationSupportableMapView: LocationSupportableMapView?
36-
internal weak var style: LocationStyleDelegate?
35+
internal weak var style: LocationStyleProtocol?
3736

3837
// MARK: Initializers
3938
internal init(puckStyle: PuckStyle,
4039
puckBearingSource: PuckBearingSource,
41-
locationSupportableMapView: LocationSupportableMapView,
42-
style: LocationStyleDelegate,
40+
style: LocationStyleProtocol,
4341
configuration: Puck3DConfiguration) {
4442
self.puckStyle = puckStyle
4543
self.puckBearingSource = puckBearingSource
46-
self.locationSupportableMapView = locationSupportableMapView
4744
self.style = style
4845
self.configuration = configuration
4946
modelLayer = ModelLayer(id: "puck-model-layer")
47+
modelLayer.paint?.modelLayerType = .constant(.locationIndicator)
5048
modelSource = ModelSource()
5149
setup()
5250
}

Sources/MapboxMaps/Style/ModelLayer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ internal struct ModelLayer: Layer {
4646

4747
internal init() {}
4848

49+
/// Defines rendering behavior of model in respect to other 3D scene objects. Defaults to .common3D.
50+
internal var modelLayerType: Value<ModelLayerType>?
51+
4952
/// The opacity of the model layer.
5053
internal var modelOpacity: Value<Double>?
5154

@@ -65,6 +68,7 @@ internal struct ModelLayer: Layer {
6568
internal var modelTranslation: Value<[Double]>?
6669

6770
enum CodingKeys: String, CodingKey {
71+
case modelLayerType = "model-type"
6872
case modelOpacity = "model-opacity"
6973
case modelOpacityTransition = "model-opacity-transition"
7074
case modelRotation = "model-rotation"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// Defines rendering behavior of model in respect to other 3D scene objects.
2+
internal enum ModelLayerType: String, Codable {
3+
/// Integrated to 3D scene, using depth testing, along with terrain, fill-extrusions and custom layer.
4+
case common3D = "common-3d"
5+
/// Displayed over other 3D content, occluded by terrain.
6+
case locationIndicator = "location-indicator"
7+
}

Tests/MapboxMapsTests/Foundation/Integration Tests/LocationManagerIntegrationTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ internal class LocationManagerIntegrationTestCase: MapViewIntegrationTestCase {
7373
}
7474

7575
private func setupLocationManager(with mapView: MapView) -> LocationManager {
76-
let locationManager = LocationManager(locationSupportableMapView: mapView, style: mapView.mapboxMap.style)
77-
return locationManager
76+
return LocationManager(style: mapView.mapboxMap.style)
7877
}
7978

8079
private func setupLocationProviderMock() -> LocationProviderMock {

Tests/MapboxMapsTests/Location/LocationManagerTests.swift

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
11
import XCTest
22
@testable import MapboxMaps
33

4-
internal class LocationManagerTests: XCTestCase {
4+
final class LocationManagerTests: XCTestCase {
55

6-
var locationSupportableMapView: LocationSupportableMapViewMock!
7-
var locationSupportableStyle: MockLocationStyleDelegate!
6+
var style: MockLocationStyle!
87

98
override func setUp() {
10-
locationSupportableMapView = LocationSupportableMapViewMock()
11-
locationSupportableStyle = MockLocationStyleDelegate()
129
super.setUp()
10+
style = MockLocationStyle()
1311
}
1412

1513
override func tearDown() {
16-
locationSupportableMapView = nil
17-
locationSupportableStyle = nil
14+
style = nil
1815
super.tearDown()
1916
}
2017

2118
func testLocationManagerDefaultInitialization() {
2219
let locationOptions = LocationOptions()
2320

24-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
25-
style: locationSupportableStyle)
21+
let locationManager = LocationManager(style: style)
2622

2723
XCTAssertEqual(locationManager.options, locationOptions)
28-
XCTAssertTrue(locationManager.locationSupportableMapView === locationSupportableMapView)
2924
XCTAssertNil(locationManager.delegate)
3025
}
3126

3227
func testAddLocationConsumer() {
33-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
34-
style: locationSupportableStyle)
28+
let locationManager = LocationManager(style: style)
3529
let locationConsumer = LocationConsumerMock()
3630

3731
locationManager.addLocationConsumer(newConsumer: locationConsumer)
@@ -42,8 +36,7 @@ internal class LocationManagerTests: XCTestCase {
4236
func testUpdateLocationOptionsWithModifiedPuckType() {
4337
var locationOptions = LocationOptions()
4438
locationOptions.puckType = .puck2D(Puck2DConfiguration(scale: .constant(1.0)))
45-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
46-
style: locationSupportableStyle)
39+
let locationManager = LocationManager(style: style)
4740

4841
var locationOptions2 = LocationOptions()
4942
locationOptions2.puckType = .puck2D(Puck2DConfiguration(scale: .constant(2.0)))
@@ -56,8 +49,7 @@ internal class LocationManagerTests: XCTestCase {
5649
func testUpdateLocationOptionsWithPuckTypeSetToNil() {
5750
var locationOptions = LocationOptions()
5851
locationOptions.puckType = .puck2D()
59-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
60-
style: locationSupportableStyle)
52+
let locationManager = LocationManager(style: style)
6153

6254
var locationOptions2 = LocationOptions()
6355
locationOptions2.puckType = nil
@@ -70,8 +62,7 @@ internal class LocationManagerTests: XCTestCase {
7062
func testUpdateLocationOptionsWithPuckTypeSetToNonNil() {
7163
var locationOptions = LocationOptions()
7264
locationOptions.puckType = nil
73-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
74-
style: locationSupportableStyle)
65+
let locationManager = LocationManager(style: style)
7566

7667
var locationOptions2 = LocationOptions()
7768
locationOptions2.puckType = .puck2D()
@@ -84,8 +75,7 @@ internal class LocationManagerTests: XCTestCase {
8475
func testUpdateLocationOptionsWithCoursePuckBearingSource() {
8576
var locationOptions = LocationOptions()
8677
locationOptions.puckType = .puck2D()
87-
let locationManager = LocationManager(locationSupportableMapView: locationSupportableMapView,
88-
style: locationSupportableStyle)
78+
let locationManager = LocationManager(style: style)
8979

9080
locationManager.options = locationOptions
9181
XCTAssertEqual(locationManager.locationPuckManager?.puckBearingSource, .heading)

Tests/MapboxMapsTests/Location/LocationSupportableMapViewMock.swift

Lines changed: 0 additions & 14 deletions
This file was deleted.

Tests/MapboxMapsTests/Location/MockLocationStyleDelegate.swift renamed to Tests/MapboxMapsTests/Location/MockLocationStyle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22
@testable import MapboxMaps
33

4-
class MockLocationStyleDelegate: LocationStyleDelegate {
4+
final class MockLocationStyle: LocationStyleProtocol {
55
func _addPersistentLayer(_ layer: Layer, layerPosition: LayerPosition?) throws {}
66
func removeLayer(withId id: String) throws {}
77
func layerExists(withId id: String) -> Bool { return false }

Tests/MapboxMapsTests/Location/Pucks/Puck2DIntegrationTests.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
1919
didFinishLoadingStyle = { _ in
2020
let puck = Puck2D(puckStyle: .precise,
2121
puckBearingSource: .heading,
22-
locationSupportableMapView: self.mapView!,
2322
style: style,
2423
configuration: Puck2DConfiguration())
2524
do {
@@ -47,7 +46,6 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
4746
didFinishLoadingStyle = { _ in
4847
let puck = Puck2D(puckStyle: .approximate,
4948
puckBearingSource: .heading,
50-
locationSupportableMapView: self.mapView!,
5149
style: style,
5250
configuration: Puck2DConfiguration())
5351
do {
@@ -74,7 +72,6 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
7472
didFinishLoadingStyle = { _ in
7573
let puck = Puck2D(puckStyle: .precise,
7674
puckBearingSource: .heading,
77-
locationSupportableMapView: self.mapView!,
7875
style: style,
7976
configuration: Puck2DConfiguration())
8077

@@ -107,7 +104,6 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
107104
didFinishLoadingStyle = { _ in
108105
let puck = Puck2D(puckStyle: .precise,
109106
puckBearingSource: .heading,
110-
locationSupportableMapView: self.mapView!,
111107
style: style,
112108
configuration: Puck2DConfiguration())
113109
do {
@@ -139,7 +135,6 @@ class Puck2DIntegrationTests: MapViewIntegrationTestCase {
139135
mapView?.mapboxMap.onNext(.mapLoaded, handler: { _ in
140136
let puck = Puck2D(puckStyle: .approximate,
141137
puckBearingSource: .heading,
142-
locationSupportableMapView: self.mapView!,
143138
style: style,
144139
configuration: Puck2DConfiguration())
145140
do {

0 commit comments

Comments
 (0)