Skip to content

Commit

Permalink
Replace ModelLayer with dictionary (#1445)
Browse files Browse the repository at this point in the history
  • Loading branch information
OdNairy committed Mar 28, 2023
1 parent a8267fa commit 315679f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 413 deletions.
18 changes: 11 additions & 7 deletions Sources/MapboxMaps/Location/Puck/Puck3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,17 @@ internal final class Puck3D: Puck {

// create the layer if needed
if !style.layerExists(withId: Self.layerID) {
var modelLayer = ModelLayer(id: Self.layerID)
modelLayer.source = Self.sourceID
modelLayer.modelScale = modelScale
modelLayer.modelType = .constant(.locationIndicator)
modelLayer.modelRotation = configuration.modelRotation
modelLayer.modelOpacity = configuration.modelOpacity
try! style.addPersistentLayer(modelLayer, layerPosition: nil)
var modelLayer: [String: Any] = [
"id": Self.layerID,
"type": "model",
"source": Self.sourceID,
"model-type": "location-indicator"
]
modelLayer["model-scale"] = try? modelScale?.toJSON()
modelLayer["model-rotation"] = try? configuration.modelRotation?.toJSON()
modelLayer["model-opacity"] = try? configuration.modelOpacity?.toJSON()

try! style.addPersistentLayer(with: modelLayer, layerPosition: nil)
} else if needsUpdateModelScale {
try? style.setLayerProperty(
for: Self.layerID,
Expand Down
184 changes: 0 additions & 184 deletions Sources/MapboxMaps/Style/Generated/Layers/ModelLayer.swift

This file was deleted.

31 changes: 16 additions & 15 deletions Tests/MapboxMapsTests/Location/Puck/Puck3DTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ final class Puck3DTests: XCTestCase {
XCTAssertEqual(actualSource.models, ["puck-model": expectedModel])
XCTAssertEqual(style.addSourceStub.invocations.first?.parameters.id, "puck-model-source")

XCTAssertEqual(style.addPersistentLayerWithPropertiesStub.invocations.count, 0)
XCTAssertEqual(style.addPersistentLayerStub.invocations.count, 1)
let actualLayer = try XCTUnwrap(style.addPersistentLayerStub.invocations.first?.parameters.layer as? ModelLayer)
XCTAssertEqual(actualLayer.id, "puck-model-layer")
XCTAssertEqual(actualLayer.modelType, .constant(.locationIndicator))
XCTAssertEqual(actualLayer.source, "puck-model-source")
XCTAssertEqual(style.addPersistentLayerStub.invocations.first?.parameters.layerPosition, nil)
XCTAssertEqual(style.addPersistentLayerStub.invocations.count, 0)
XCTAssertEqual(style.addPersistentLayerWithPropertiesStub.invocations.count, 1)
let actualLayer = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties)
XCTAssertEqual(actualLayer["id"] as? String, "puck-model-layer")
XCTAssertEqual(actualLayer["model-type"] as? String, "location-indicator")
XCTAssertEqual(actualLayer["source"] as? String, "puck-model-source")
XCTAssertEqual(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.layerPosition, nil)
}

func testModelOrientationBasedOnHeading() throws {
Expand Down Expand Up @@ -205,8 +205,8 @@ final class Puck3DTests: XCTestCase {

puck3D.isActive = true

let actualLayer = try XCTUnwrap(style.addPersistentLayerStub.invocations.first?.parameters.layer as? ModelLayer)
XCTAssertEqual(actualLayer.modelRotation, configuration.modelRotation)
let actualLayer = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties)
XCTAssertEqual(actualLayer["model-rotation"] as? String, try? configuration.modelRotation?.toJSON() as? String)
}

func testModelOpacity() throws {
Expand All @@ -217,8 +217,8 @@ final class Puck3DTests: XCTestCase {

puck3D.isActive = true

let actualLayer = try XCTUnwrap(style.addPersistentLayerStub.invocations.first?.parameters.layer as? ModelLayer)
XCTAssertEqual(actualLayer.modelOpacity, configuration.modelOpacity)
let actualLayer = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties)
XCTAssertEqual(actualLayer["model-opacity"] as? String, try? configuration.modelOpacity?.toJSON() as? String)
}

func testDefaultModelScale() throws {
Expand All @@ -233,8 +233,9 @@ final class Puck3DTests: XCTestCase {
style.layerExistsStub.defaultReturnValue = false
puck3D.isActive = true

let modelLayer = try XCTUnwrap(style.addPersistentLayerStub.invocations.first?.parameters.layer as? ModelLayer)
let modelScaleString = try XCTUnwrap(try modelLayer.modelScale?.jsonString())
let modelLayer = try XCTUnwrap(style.addPersistentLayerWithPropertiesStub.invocations.first?.parameters.properties)
let modelScale = try XCTUnwrap(modelLayer["model-scale"] as? [Any])
let modelScaleString = try XCTUnwrap(String(data: JSONSerialization.data(withJSONObject: modelScale), encoding: .utf8))

let modelScalePattern =
#"^\["interpolate","# +
Expand Down Expand Up @@ -293,7 +294,7 @@ final class Puck3DTests: XCTestCase {
style.layerExistsStub.defaultReturnValue = true
style.addSourceStub.reset()
style.setSourcePropertiesStub.reset()
style.addPersistentLayerStub.reset()
style.addPersistentLayerWithPropertiesStub.reset()

puck3D.puckBearingSource = [.heading, .course].randomElement()!

Expand All @@ -310,7 +311,7 @@ final class Puck3DTests: XCTestCase {
style.layerExistsStub.defaultReturnValue = true
style.addSourceStub.reset()
style.setSourcePropertiesStub.reset()
style.addPersistentLayerStub.reset()
style.addPersistentLayerWithPropertiesStub.reset()
let handler = try XCTUnwrap(interpolatedLocationProducer.observeStub.invocations.first?.parameters)

let wantsMoreUpdates = handler(interpolatedLocationProducer.location!)
Expand Down

This file was deleted.

Loading

0 comments on commit 315679f

Please sign in to comment.