Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update add step one by one #306

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions Sources/ARKit-CoreLocation/SceneLocationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ public extension SceneLocationView {
/// - Parameters:
/// - routes: The MKRoute of directions
/// - boxBuilder: A block that will customize how a box is built.
func addRoutes(routes: [MKRoute], boxBuilder: BoxBuilder? = nil) {
func addRoutes(routes: [MKRoute], altitude: CLLocationDistance = -2.0, boxBuilder: BoxBuilder? = nil) {
addRoutes(polylines: routes.map { AttributedType(type: $0.polyline,
attribute: $0.name) },
Δaltitude: altitude,
boxBuilder: boxBuilder)
}

Expand All @@ -364,7 +365,7 @@ public extension SceneLocationView {
/// - Δaltitude: difference between box and current user altitude
/// - boxBuilder: A block that will customize how a box is built.
func addRoutes(polylines: [AttributedType<MKPolyline>],
Δaltitude: CLLocationDistance = -2.0,
Δaltitude: CLLocationDistance,
boxBuilder: BoxBuilder? = nil) {
guard let altitude = sceneLocationManager.currentLocation?.altitude else {
return assertionFailure("we don't have an elevation")
Expand All @@ -375,20 +376,50 @@ public extension SceneLocationView {
tag: $0.attribute,
boxBuilder: boxBuilder)
}

polylineNodes.append(contentsOf: polyNodes)
polyNodes.forEach {
$0.locationNodes.forEach {
let locationNodeLocation = self.locationOfLocationNode($0)
$0.updatePositionAndScale(setup: true,
scenePosition: currentScenePosition,
locationNodeLocation: locationNodeLocation,
locationManager: sceneLocationManager,
onCompletion: {})
sceneNode?.addChildNode($0)
}
}
}

func addStep(step: MKRoute.Step, altitude: CLLocationDistance = -2.0, boxBuilder: BoxBuilder? = nil) {
addStep(polyline: AttributedType(type: step.polyline, attribute: step.description),
Δaltitude: altitude,
boxBuilder: boxBuilder)
}

func addStep(polyline: AttributedType<MKPolyline>,
Δaltitude: CLLocationDistance,
boxBuilder: BoxBuilder? = nil) {
guard let altitude = sceneLocationManager.currentLocation?.altitude else {
return assertionFailure("we don't have an elevation")
}
let polyNode = PolylineNode(polyline: polyline.type,
altitude: altitude + Δaltitude,
tag: polyline.attribute,
boxBuilder: boxBuilder)

polylineNodes.append(polyNode)

polyNode.locationNodes.forEach {
let locationNodeLocation = self.locationOfLocationNode($0)
$0.updatePositionAndScale(setup: true,
scenePosition: currentScenePosition,
locationNodeLocation: locationNodeLocation,
locationNodeLocation: locationNodeLocation,
locationManager: sceneLocationManager,
onCompletion: {})
sceneNode?.addChildNode($0)
}
}
}

func removeRoutes(routes: [MKRoute]) {
routes.forEach { route in
Expand Down