Skip to content

Commit

Permalink
GH Maps: enable turn costs (#1834)
Browse files Browse the repository at this point in the history
  • Loading branch information
karussell committed Dec 28, 2019
1 parent ba2d181 commit 9913296
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Expand Up @@ -17,6 +17,7 @@
*/
package com.graphhopper.resources;

import com.graphhopper.routing.weighting.TurnWeighting;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.util.CmdArgs;
import com.graphhopper.util.Constants;
Expand Down Expand Up @@ -51,6 +52,7 @@ public InfoResource(CmdArgs config, GraphHopperStorage storage, @Named("hasEleva
public static class Info {
public static class PerVehicle {
public boolean elevation;
public boolean turn_costs;
}

public BBox bbox;
Expand All @@ -76,6 +78,7 @@ public Info getInfo() {
for (String v : info.supported_vehicles) {
Info.PerVehicle perVehicleJson = new Info.PerVehicle();
perVehicleJson.elevation = hasElevation;
perVehicleJson.turn_costs = storage.getEncodingManager().getEncoder(v).supports(TurnWeighting.class);
info.features.put(v, perVehicleJson);
}
if (config.has("gtfs.file")) {
Expand Down
15 changes: 3 additions & 12 deletions web/src/main/resources/assets/js/graphhopper/GHRequest.js
Expand Up @@ -81,13 +81,7 @@ GHRequest.prototype.init = function (params) {

// overwrite elevation e.g. important if not supported from feature set
this.api_params.elevation = false;
var featureSet = this.features[this.api_params.vehicle];
if (featureSet && featureSet.elevation) {
if ('elevation' in params)
this.api_params.elevation = params.elevation;
else
this.api_params.elevation = true;
}
this.initVehicle(this.api_params.vehicle);

if (params.q) {
var qStr = params.q;
Expand Down Expand Up @@ -130,11 +124,8 @@ GHRequest.prototype.getEarliestDepartureTime = function () {
GHRequest.prototype.initVehicle = function (vehicle) {
this.api_params.vehicle = vehicle;
var featureSet = this.features[vehicle];

if (featureSet && featureSet.elevation)
this.api_params.elevation = true;
else
this.api_params.elevation = false;
this.api_params.elevation = featureSet && featureSet.elevation;
this.api_params.turn_costs = this.hasTCSupport();
};

GHRequest.prototype.hasElevation = function () {
Expand Down
23 changes: 17 additions & 6 deletions web/src/main/resources/assets/js/main-template.js
Expand Up @@ -30,10 +30,18 @@ if (!host) {
}

var AutoComplete = require('./autocomplete.js');
if (ghenv.environment === 'development')
if (ghenv.environment === 'development') {
var autocomplete = AutoComplete.prototype.createStub();
else
GHRequest.prototype.hasTCSupport = function() {
var featureSet = this.features[this.api_params.vehicle];
this.api_params.turn_costs = featureSet && featureSet.turn_costs;
};
} else {
var autocomplete = new AutoComplete(ghenv.geocoding.host, ghenv.geocoding.api_key);
GHRequest.prototype.hasTCSupport = function() {
return new Set(["car", "truck", "small_truck", "scooter"]).has(this.api_params.vehicle);
};
}

var mapLayer = require('./map.js');
var nominatim = require('./nominatim.js');
Expand All @@ -50,7 +58,6 @@ var tileLayers = require('./config/tileLayers.js');
var debug = false;
var ghRequest = new GHRequest(host, ghenv.routing.api_key);
var bounds = {};

var metaVersionInfo;

// usage: log('inside coolFunc',this,arguments);
Expand Down Expand Up @@ -123,7 +130,8 @@ $(document).ready(function (e) {
button.click(function () {
ghRequest.initVehicle(vehicle);
resolveAll();
routeLatLng(ghRequest);
if (ghRequest.route.isResolved())
routeLatLng(ghRequest);
});
return button;
}
Expand Down Expand Up @@ -154,7 +162,7 @@ $(document).ready(function (e) {
hiddenVehicles[i].show();
}
});
vehiclesDiv.append($("<a class='vehicle-info-link' href='https://graphhopper.com/api/1/docs/supported-vehicle-profiles/'>?</a>"));
vehiclesDiv.append($("<a class='vehicle-info-link' href='https://docs.graphhopper.com/#section/Map-Data-and-Routing-Profiles/OpenStreetMap'>?</a>"));
vehiclesDiv.append(moreBtn);
}
}
Expand Down Expand Up @@ -461,6 +469,8 @@ function resolveTo() {
}

function resolveIndex(index) {
if(!ghRequest.route.getIndex(index))
return;
setFlag(ghRequest.route.getIndex(index), index);
if (index === 0) {
if (!ghRequest.to.isResolved())
Expand Down Expand Up @@ -598,7 +608,8 @@ function routeLatLng(request, doQuery) {
mapLayer.updateScale(useMiles);
ghRequest.useMiles = useMiles;
resolveAll();
routeLatLng(ghRequest);
if (ghRequest.route.isResolved())
routeLatLng(ghRequest);
};
};

Expand Down

0 comments on commit 9913296

Please sign in to comment.