Skip to content

Commit

Permalink
replace the 3D puck model with a Curiosity model, clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanMa1991 committed Jun 30, 2021
1 parent 6d69dfd commit 7b77383
Show file tree
Hide file tree
Showing 4 changed files with 11,071 additions and 446 deletions.
8 changes: 4 additions & 4 deletions Navigation-Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
9639244A22E02A520010FE73 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C58FB85D1FE899B800C4B491 /* Main.storyboard */; };
9639244B22E02A820010FE73 /* EmbeddedExamples.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8D6D36A620001F0400C2B61B /* EmbeddedExamples.storyboard */; };
B40ADDC9ABB7E7F6703997CA /* Pods_DocsCode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B796D93B6E7934BFD326FA8 /* Pods_DocsCode.framework */; };
B4747F58268CE9C800BE884B /* MSL_clean.gltf in Resources */ = {isa = PBXBuildFile; fileRef = B4747F57268CE9C800BE884B /* MSL_clean.gltf */; };
B480E424261E4C3500C16FA0 /* Predictive-Caching.swift in Sources */ = {isa = PBXBuildFile; fileRef = B480E423261E4C3500C16FA0 /* Predictive-Caching.swift */; };
B480E428261E4C4600C16FA0 /* Route-Alerts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B480E427261E4C4600C16FA0 /* Route-Alerts.swift */; };
B4F805EC2679139A00D5F1C8 /* race_car_model.gltf in Resources */ = {isa = PBXBuildFile; fileRef = B4F805EB2679139A00D5F1C8 /* race_car_model.gltf */; };
B4F805EE26791AD900D5F1C8 /* Custom-User-Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4F805ED26791AD900D5F1C8 /* Custom-User-Location.swift */; };
C3893F1C25F96BDC0058A987 /* Custom-Waypoints.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3893F1B25F96BDC0058A987 /* Custom-Waypoints.swift */; };
C52BAA782040D5030086EC6B /* Custom-Destination-Marker.swift in Sources */ = {isa = PBXBuildFile; fileRef = C52BAA772040D5030086EC6B /* Custom-Destination-Marker.swift */; };
Expand Down Expand Up @@ -86,9 +86,9 @@
9A4F31D3A4350E716451A486 /* Pods-DocsCode.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocsCode.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DocsCode/Pods-DocsCode.debug.xcconfig"; sourceTree = "<group>"; };
9B796D93B6E7934BFD326FA8 /* Pods_DocsCode.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DocsCode.framework; sourceTree = BUILT_PRODUCTS_DIR; };
B33B5E4C0AD283368D51EEDA /* Pods-DocsCode.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocsCode.release.xcconfig"; path = "Pods/Target Support Files/Pods-DocsCode/Pods-DocsCode.release.xcconfig"; sourceTree = "<group>"; };
B4747F57268CE9C800BE884B /* MSL_clean.gltf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MSL_clean.gltf; sourceTree = "<group>"; };
B480E423261E4C3500C16FA0 /* Predictive-Caching.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Predictive-Caching.swift"; sourceTree = "<group>"; };
B480E427261E4C4600C16FA0 /* Route-Alerts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Route-Alerts.swift"; sourceTree = "<group>"; };
B4F805EB2679139A00D5F1C8 /* race_car_model.gltf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = race_car_model.gltf; sourceTree = "<group>"; };
B4F805ED26791AD900D5F1C8 /* Custom-User-Location.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Custom-User-Location.swift"; sourceTree = "<group>"; };
BFEC70FB9C884A4DDD80E7D9 /* Pods-Navigation-Examples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Navigation-Examples.release.xcconfig"; path = "Pods/Target Support Files/Pods-Navigation-Examples/Pods-Navigation-Examples.release.xcconfig"; sourceTree = "<group>"; };
C3893F1B25F96BDC0058A987 /* Custom-Waypoints.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Custom-Waypoints.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -176,7 +176,7 @@
8AC9129E2494118400B6941E /* TestData */ = {
isa = PBXGroup;
children = (
B4F805EB2679139A00D5F1C8 /* race_car_model.gltf */,
B4747F57268CE9C800BE884B /* MSL_clean.gltf */,
8A96379B2492B366008DEF2A /* route.json */,
);
path = TestData;
Expand Down Expand Up @@ -395,8 +395,8 @@
2B521D522409242A00984CF8 /* CustomBottomBannerView.xib in Resources */,
C58FB8611FE899B800C4B491 /* Assets.xcassets in Resources */,
8A0B182326553482005107DE /* CustomSegue.storyboard in Resources */,
B4F805EC2679139A00D5F1C8 /* race_car_model.gltf in Resources */,
9639244A22E02A520010FE73 /* Main.storyboard in Resources */,
B4747F58268CE9C800BE884B /* MSL_clean.gltf in Resources */,
9639244B22E02A820010FE73 /* EmbeddedExamples.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
20 changes: 10 additions & 10 deletions Navigation-Examples/Examples/Custom-User-Location.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg

var waypoints: [Waypoint] = []

var startButtonHighlighted:Bool = false {
var startButtonHighlighted: Bool = false {
didSet {
startButton.backgroundColor = startButtonHighlighted ? .clear : .blue
}
Expand Down Expand Up @@ -118,7 +118,6 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg
navigationMapView.addGestureRecognizer(longPressGestureRecognizer)
}


@objc private func startButtonChangeColor() {
startButtonHighlighted = !startButtonHighlighted
}
Expand All @@ -143,18 +142,18 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg

func requestRoute() {
guard waypoints.count > 0 else { return }
guard let currentLocation = navigationMapView.mapView.location.latestLocation?.internalLocation else {
guard let currentCoordinate = navigationMapView.mapView.location.latestLocation?.coordinate else {
print("User location is not valid. Make sure to enable Location Services.")
return
}
let userWaypoint = Waypoint(location: currentLocation)

let userWaypoint = Waypoint(coordinate: currentCoordinate)
// Change the coordinate accuracy of `Waypoint` to negative beofre add it to the `waypoints`. Thus the route requested on the `waypoints` is considered viable.
userWaypoint.coordinateAccuracy = -1
waypoints.insert(userWaypoint, at: 0)
let navigationRouteOptions = NavigationRouteOptions(waypoints: waypoints)

Directions.shared.calculate(navigationRouteOptions) { [weak self] (session, result) in
Directions.shared.calculate(navigationRouteOptions) { [weak self] (_, result) in
switch result {
case .failure(let error):
print(error.localizedDescription)
Expand Down Expand Up @@ -226,13 +225,14 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg
}

func setupPuck3D() {
// It's required to provide a `Puck3DConfiguration` to the `UserLocationStyle.puck3D`.
let uri = Bundle.main.url(forResource: "race_car_model",
// It's required to provide a `Puck3DConfiguration` to the `UserLocationStyle.puck3D`, a `gltf` 3D asset will be used as the `Model` source.
// The model source is from NASA's curiosity(clean) in https://github.com/nasa/NASA-3D-Resources/blob/master/3D%20Models/Curiosity%20(Clean)/MSL_clean.blend
let uri = Bundle.main.url(forResource: "MSL_clean",
withExtension: "gltf")
// Instantiating the model. The position is the coordinates of the model in `[longitude, latitude]` format.
let myModel = Model(uri: uri,
position: [-122.396152, 37.79129],
orientation: [0, 0, 90])
orientation: [0, 0, 0])
// Setting an expression to scale the model based on camera zoom
let scalingExpression = Exp(.interpolate) {
Exp(.linear)
Expand All @@ -259,7 +259,7 @@ class CustomUserLocationViewController: UIViewController, NavigationMapViewDeleg
}
20
Exp(.literal) {
[2.0, 2.0, 2.0]
[3.0, 3.0, 3.0]
}
}

Expand Down
Loading

0 comments on commit 7b77383

Please sign in to comment.