Created by Ko Nagase, Georepublic Japan
?loc=34.944479,135.702857&loc=34.944916,135.702972&loc=34.944530,135.703476
Value | Meaning |
---|---|
1 | Edge start node is source(origin) point |
2 | Edge end node is target(destination) point |
4 | Edge start node is intermediate way point |
8 | Edge end node is intermediate way point |
CREATE OR REPLACE FUNCTION routing.viaPoints(
IN points text, -- Format: "Lng,Lat|Lng,Lat|..."
IN tbl varchar DEFAULT 'osm_2po_4pgr'::varchar, -- Edge table name
: -- Other default values
OUT seq integer,
OUT gid integer,
OUT name text, -- Road name
OUT heading double precision, -- Angle from edge start to edge end (not used)
OUT cost double precision,
OUT geom geometry, -- Edge geometry (ordered)
OUT distance double precision,
OUT point_type smallint -- Point type
)
RETURNS SETOF record AS
:
options: {
serviceUrl: 'http://localhost:8080/geoserver/pgrouting/wfs',
timeout: 30 * 1000,
urlParameters: {
version: '1.0.0',
request: 'GetFeature',
outputFormat: 'application/json'
}
},
:
route: function(waypoints, callback, context, options) {
:
url = this.buildRouteUrl(waypoints, options);
:
corslite(url, L.bind(function(err, resp) {
:
buildRouteUrl: function(waypoints, options) {
var points = [],
i,
baseUrl;
for (i = 0; i < waypoints.length; i++) {
points.push(waypoints[i].latLng.lng + '\\,' + waypoints[i].latLng.lat);
}
baseUrl = this.options.serviceUrl + L.Util.getParamString(L.extend({
typeName: this._typeName,
viewparams: 'points:' + points.join('|')
}, this.options.urlParameters), baseUrl);
return baseUrl;
},
route: function(waypoints, callback, context, options) {
:
corslite(url, L.bind(function(err, resp) {
:
if (!timedOut) {
if (!err) {
data = JSON.parse(resp.responseText);
this._routeDone(data, wps, callback, context);
:
_routeDone: function(response, inputWaypoints, callback, context) {
var alts = [],
:
for (i = 0; i < response.features.length; i++) {
feature = response.features[i];
edgeCoords = this._coordsToLatLngs(feature.geometry.coordinates);
if ((feature.properties.pointType & 1) || (feature.properties.pointType & 4)) {
viaCoords.push(edgeCoords[0]);
viaIndices.push(routeCoords.length);
}
if (feature.properties.pointType & 2) {
viaCoords.push(edgeCoords[edgeCoords.length - 1]);
viaIndices.push(routeCoords.length + edgeCoords.length - 1);
}
instructions = instructions.concat(this._convertInstructions(feature.properties, routeCoords, edgeCoords));
routeCoords = routeCoords.concat(edgeCoords);
totalDistance += feature.properties.distance;
totalTime += feature.properties.cost * 3600;
}
actualWaypoints = this._toWaypoints(inputWaypoints, viaCoords);
alts.push({
name: '',
coordinates: routeCoords,
instructions: instructions,
summary: {
totalDistance: totalDistance,
totalTime: Math.round(totalTime)
},
inputWaypoints: inputWaypoints,
waypoints: actualWaypoints,
waypointIndices: viaIndices
});
callback.call(context, null, alts);
},