[gnome-maps/wip/routing2: 5/9] fixup routeQuery
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing2: 5/9] fixup routeQuery
- Date: Sat, 3 May 2014 22:45:50 +0000 (UTC)
commit 87894e042e0866362a8ab78f48aad9b540f35136
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Sat May 3 20:56:28 2014 +0200
fixup routeQuery
src/routeService.js | 52 +++++++++++++++++++++-----------------------------
1 files changed, 22 insertions(+), 30 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index 8f1e971..c41d17b 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -22,6 +22,7 @@
const Soup = imports.gi.Soup;
const Champlain = imports.gi.Champlain;
+const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Utils = imports.utils;
@@ -45,12 +46,11 @@ const GraphHopper = new Lang.Class({
_init: function() {
this._session = new Soup.Session({ user_agent : "gnome-maps" });
- this._key = "VCIHrHj0pDKb8INLpT4s5hVadNmJ1Q3vi0J4nJYP";
+ this._key = "VCIHrHj0pDKb8INLpT4s5hVadNmJ1Q3vi0J4nJYP";
this._baseURL = "http://graphhopper.com/api/1/route?";;
- this._locale = 'en_US'; // TODO: get this from env
-
- this._route = new Route.Route();
- this._query = new RouteQuery.RouteQuery();
+ this._locale = GLib.get_language_names()[0];
+ this._route = new Route.Route();
+ this._query = new RouteQuery.RouteQuery();
this._query.connect('change', (function() {
if(this._query.from && this._query.to)
@@ -76,25 +76,16 @@ const GraphHopper = new Lang.Class({
}).bind(this));
},
- _vehicle: function(transportationType) {
- switch(transportationType) {
- case RouteQuery.Transportation.CAR: return 'car';
- case RouteQuery.Transportation.BIKE: return 'bike';
- case RouteQuery.Transportation.PEDESTRIAN: return 'foot';
- default: return null;
- }
- },
-
_buildURL: function(viaPoints, transportation) {
let points = viaPoints.map(function(p) {
return [p.latitude, p.longitude].join(',');
});
-
- let query = new HTTP.Query({ type: 'json',
- key: this._key,
- vehicle: this._vehicle(transportation),
- locale: this._locale,
- point: points
+ let vehicle = RouteQuery.Transportation.toString(transportation);
+ let query = new HTTP.Query({ type: 'json',
+ key: this._key,
+ vehicle: vehicle,
+ locale: this._locale,
+ point: points
});
let url = this._baseURL + query.toString();
Utils.debug("Sending route request to: " + url);
@@ -104,10 +95,10 @@ const GraphHopper = new Lang.Class({
// TODO: error handling
_parseResult: function(result) {
// Always the first path until GH has alternate routes support
- let route = JSON.parse(result).paths[0],
- path = EPAF.decode(route.points),
- turnPoints = this._createTurnPoints(path, route.instructions),
- bbox = new Champlain.BoundingBox();
+ let route = JSON.parse(result).paths[0];
+ let path = EPAF.decode(route.points);
+ let turnPoints = this._createTurnPoints(path, route.instructions);
+ let bbox = new Champlain.BoundingBox();
// GH does lonlat-order and Champlain latlon-order
bbox.extend(route.bbox[1], route.bbox[0]);
@@ -140,11 +131,12 @@ const GraphHopper = new Lang.Class({
},
_createTurnPointType: function(sign) {
- let type = sign + 3,
- min = Route.TurnPointType.SHARP_LEFT,
- max = Route.TurnPointType.VIA;
- return min <= type && type <= max
- ? type
- : undefined;
+ let type = sign + 3;
+ let min = Route.TurnPointType.SHARP_LEFT;
+ let max = Route.TurnPointType.VIA;
+ if(min <= type && type <= max)
+ return type;
+ else
+ return undefined;
}
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]