[gnome-maps/wip/routing: 7/8] RouteService: Add GraphHopper support
- From: Mattias Bengtsson <mattiasb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/routing: 7/8] RouteService: Add GraphHopper support
- Date: Wed, 28 Aug 2013 01:09:45 +0000 (UTC)
commit d1d3df9fd0d3ed547a7f73bfd97bd98e79eccaee
Author: Mattias Bengtsson <mattias jc bengtsson gmail com>
Date: Sun Aug 25 03:33:39 2013 +0200
RouteService: Add GraphHopper support
Add support for routing via GraphHopper HTTP REST interface.
src/routeService.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/src/routeService.js b/src/routeService.js
index 64caa63..c0d448e 100644
--- a/src/routeService.js
+++ b/src/routeService.js
@@ -63,3 +63,81 @@ const RouteService = new Lang.Class({
}).bind(this));
}
});
+
+const GraphHopper = new Lang.Class({
+ Name: 'GraphHopper',
+ Extends: RouteService,
+
+ _init: function(url) {
+ this._baseURL = url || "http://graphhopper.com/routing/api/route?";
+ this._locale = 'en_US';
+ this.parent();
+ },
+
+ _vehicle: function(transportationType) {
+ let keys = Object.keys(Transportation);
+ return keys.filter(function(key) {
+ return key === transportationType;
+ })[0];
+ },
+
+ _buildURL: function(viaPoints, transportation) {
+ let points = viaPoints.map(function(p) {
+ return [p.latitude, p.longitude].join(',');
+ });
+
+ let query = new HTTP.Query({
+ type: 'json',
+ vehicle: this._vehicle(transportation),
+ locale: this._locale,
+ point: points
+ });
+ return this._baseURL + query.toString();
+ },
+
+ _parseResults: function(result) {
+ let route = JSON.parse(result).route,
+ directions = this._createDirections(route.instructions.indications),
+ instructions = this._createInstructions(route.instructions.indications,
+ route.instructions.descriptions,
+ route.instructions.distances);
+
+ return new Route.Route({ coordinates: Polyline.decode(route.coordinates),
+ instructions: instructions,
+ distance: route.distance,
+ time: route.time,
+ bbox: route.bbox });
+ },
+
+ _createInstructions: function(directions, distances, descriptions) {
+ let result = [],
+ last = directions.length - 1;
+ result.push(new Route.Instruction({ coordinate: null,
+ type: Route.InstructionType.START,
+ direction: directions[0],
+ distance: distances[0],
+ description: descriptions[0] }));
+ for(let i=1; i < last; i++) {
+ result.push(new Route.Instruction({ coordinate: null,
+ type: Route.InstructionType.NORMAL,
+ direction: directions[i],
+ distance: distances[i],
+ description: descriptions[i] }));
+
+ }
+
+ result.push(new Route.Instruction({ coordinate: null,
+ type: Route.InstructionType.END,
+ direction: directions[last],
+ distance: distances[last],
+ description: descriptions[last] }));
+ return result;
+ },
+ _createDirections: function(indications) {
+ return indications.map(function(indication) {
+ switch(indication) {
+
+ };
+ });
+ }
+});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]