Skip to content

Commit

Permalink
add max_hiking_difficulty configuration to valhalla router (#129)
Browse files Browse the repository at this point in the history
* add max_hiking_difficulty configuration to valhalla router

* provide hikingdifficulty documentation and fixup method name
  • Loading branch information
sashei authored Jun 26, 2020
1 parent 05501f5 commit 2d4e582
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/src/main/java/com/mapzen/valhalla/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public class JSON {
@SerializedName("directions_options")
public DirectionOptions directionsOptions = new DirectionOptions();

@SerializedName("costing_options")
public CostingOptions costingOptions = new CostingOptions();

public static class CostingOptions {
@SerializedName("max_hiking_difficulty")
public String maxHikingDifficulty;
}

public static class Location {
public double lat;
public double lon;
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/java/com/mapzen/valhalla/Router.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ interface Router {
city: String? = null,
state: String? = null): Router
fun setDistanceUnits(units: DistanceUnits): Router
/*
* Sets the difficulty for hiking route types
*
* This value indicates the maximum difficulty of hiking trails that is allowed. Values between
* 0 and 6 are allowed. The values correspond to sac_scale values within OpenStreetMap. The
* default value is 1 which means that well cleared trails that are mostly flat or slightly
* sloped are allowed. Higher difficulty trails can be allowed by specifying a higher value for
* maxHikingDifficulty.
*/
fun setMaxHikingDifficulty(difficulty: Int): Router
fun clearLocations(): Router
fun setCallback(callback: RouteCallback): Router
fun fetch(): Call<String>?
Expand Down
7 changes: 7 additions & 0 deletions library/src/main/java/com/mapzen/valhalla/ValhallaRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open class ValhallaRouter : Router {
private var language: String? = null
private var type = Router.Type.DRIVING
private val locations = ArrayList<JSON.Location>()
private var maxDifficulty = 1
private var callback: RouteCallback? = null
private var units: Router.DistanceUnits = Router.DistanceUnits.KILOMETERS

Expand Down Expand Up @@ -73,6 +74,11 @@ open class ValhallaRouter : Router {
return this
}

override fun setMaxHikingDifficulty(difficulty: Int): Router {
this.maxDifficulty = difficulty
return this
}

override fun clearLocations(): Router {
this.locations.clear()
return this
Expand Down Expand Up @@ -117,6 +123,7 @@ open class ValhallaRouter : Router {
json.costing = this.type.toString()
json.directionsOptions.language = language
json.directionsOptions.units = this.units.toString()
json.costingOptions.maxHikingDifficulty = this.maxDifficulty.toString()
return json
}

Expand Down

0 comments on commit 2d4e582

Please sign in to comment.