From d43827cdd2d69a7f1af2299f935a29659927bcc1 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Fri, 4 Jan 2019 23:08:54 +0100 Subject: [PATCH 1/3] Add support for nogo weights in BRouter interface --- js/router/BRouter.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/router/BRouter.js b/js/router/BRouter.js index 077221be..be1aa84b 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -218,6 +218,10 @@ L.BRouter = L.Class.extend({ s += this._formatLatLng(circle.getLatLng()); s += L.BRouter.NUMBER_SEPARATOR; s += Math.round(circle.getRadius()); + if (circle.options.weight) { + s += L.BRouter.NUMBER_SEPARATOR; + s += circle.options.weight; + } if (i < (nogos.length - 1)) { s += L.BRouter.GROUP_SEPARATOR; } @@ -236,11 +240,16 @@ L.BRouter = L.Class.extend({ groups = s.split(L.BRouter.GROUP_SEPARATOR); for (var i = 0; i < groups.length; i++) { - // lng,lat,radius + // lng,lat,radius(,weight) numbers = groups[i].split(L.BRouter.NUMBER_SEPARATOR); // TODO refactor: pass simple obj, create circle in NogoAreas; use shapeOptions of instance // [lat,lng],radius - nogos.push(L.circle([numbers[1], numbers[0]], {radius: numbers[2]})); + // Parse as a nogo circle + var nogoOptions = {radius: numbers[2]}; + if (numbers.length > 3) { + nogoOptions.weight = numbers[3]; + } + nogos.push(L.circle([numbers[1], numbers[0]], nogoOptions)); } return nogos; @@ -258,4 +267,4 @@ L.BRouter = L.Class.extend({ L.bRouter = function (options) { return new L.BRouter(options); -}; \ No newline at end of file +}; From e8b667ca0c956fec7bf0de63f804e2ea8b816066 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Fri, 4 Jan 2019 23:41:04 +0100 Subject: [PATCH 2/3] Add a build script entry in package.json to let dev use gulp version from node_modules easily --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 3eaabf9b..84f1b8e4 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Web client for BRouter", "main": "js/index.js", "scripts": { + "build": "gulp", "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { From 9a4dd7864462a6014d79a52639eb7f741c997909 Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sat, 5 Jan 2019 00:07:52 +0100 Subject: [PATCH 3/3] Add basic support for nogo polylines and polygons (no UI). --- js/router/BRouter.js | 108 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 5 deletions(-) diff --git a/js/router/BRouter.js b/js/router/BRouter.js index be1aa84b..7ed80568 100644 --- a/js/router/BRouter.js +++ b/js/router/BRouter.js @@ -2,7 +2,7 @@ L.BRouter = L.Class.extend({ statics: { // NOTE: the routing API used here is not public! // /brouter?lonlats=1.1,1.2|2.1,2.2|3.1,3.2|4.1,4.2&nogos=-1.1,-1.2,1|-2.1,-2.2,2&profile=shortest&alternativeidx=1&format=kml - URL_TEMPLATE: '/brouter?lonlats={lonlats}&nogos={nogos}&profile={profile}&alternativeidx={alternativeidx}&format={format}', + URL_TEMPLATE: '/brouter?lonlats={lonlats}&nogos={nogos}&polylines={polylines}&polygons={polygons}&profile={profile}&alternativeidx={alternativeidx}&format={format}', URL_PROFILE_UPLOAD: BR.conf.host + '/brouter/profile', PRECISION: 6, NUMBER_SEPARATOR: ',', @@ -41,9 +41,15 @@ L.BRouter = L.Class.extend({ if (this._getLonLatsString(latLngs) != null) params.lonlats = this._getLonLatsString(latLngs); - if (this._getNogosString(this.options.nogos).length > 0) + if (this.options.nogos && this._getNogosString(this.options.nogos).length > 0) params.nogos = this._getNogosString(this.options.nogos); + if (this.options.polylines && this._getNogosPolylinesString(this.options.polylines).length > 0) + params.polylines = this._getNogosPolylinesString(this.options.polylines); + + if (this.options.polygons && this._getNogosPolygonsString(this.options.polygons).length > 0) + params.polygons = this._getNogosPolygonsString(this.options.polygons); + if (this.options.profile != null) params.profile = this.options.profile; @@ -75,6 +81,12 @@ L.BRouter = L.Class.extend({ if (params.nogos) { opts.nogos = this._parseNogos(params.nogos); } + if (params.polylines) { + opts.polylines = this._parseNogosPolylines(params.polylines); + } + if (params.polygons) { + opts.polygons = this._parseNogosPolygons(params.polygons); + } if (params.alternativeidx) { opts.alternative = params.alternativeidx; } @@ -92,6 +104,10 @@ L.BRouter = L.Class.extend({ args.push(L.Util.template('lonlats={lonlats}', urlParams)); if (urlParams.nogos != null) args.push(L.Util.template('nogos={nogos}', urlParams)); + if (urlParams.polylines != null) + args.push(L.Util.template('polylines={polylines}', urlParams)); + if (urlParams.polygons != null) + args.push(L.Util.template('polygons={polygons}', urlParams)); if (urlParams.profile != null) args.push(L.Util.template('profile={profile}', urlParams)); if (urlParams.alternativeidx != null) @@ -218,9 +234,9 @@ L.BRouter = L.Class.extend({ s += this._formatLatLng(circle.getLatLng()); s += L.BRouter.NUMBER_SEPARATOR; s += Math.round(circle.getRadius()); - if (circle.options.weight) { + if (circle.options.nogoWeight) { s += L.BRouter.NUMBER_SEPARATOR; - s += circle.options.weight; + s += circle.options.nogoWeight; } if (i < (nogos.length - 1)) { s += L.BRouter.GROUP_SEPARATOR; @@ -247,7 +263,7 @@ L.BRouter = L.Class.extend({ // Parse as a nogo circle var nogoOptions = {radius: numbers[2]}; if (numbers.length > 3) { - nogoOptions.weight = numbers[3]; + nogoOptions.nogoWeight = numbers[3]; } nogos.push(L.circle([numbers[1], numbers[0]], nogoOptions)); } @@ -255,6 +271,88 @@ L.BRouter = L.Class.extend({ return nogos; }, + _getNogosPolylinesString: function(nogos) { + var s = ''; + for (var i = 0, polyline, vertices; i < nogos.length; i++) { + polyline = nogos[i]; + vertices = polyline.getLatLngs(); + for (var j = 0; j < vertices.length; j++) { + if (j > 0) { + s += L.BRouter.NUMBER_SEPARATOR; + } + s += this._formatLatLng(vertices[j]); + } + if (i < (nogos.length - 1)) { + s += L.BRouter.GROUP_SEPARATOR; + } + } + return s; + }, + + _parseNogosPolylines: function(s) { + var groups, + numbers, + latlngs, + nogos = []; + + groups = s.split(L.BRouter.GROUP_SEPARATOR); + for (var i = 0; i < groups.length; i++) + { + numbers = groups[i].split(L.BRouter.NUMBER_SEPARATOR); + if (numbers.length > 1) + { + latlngs = []; + for (var j = 0; j < numbers.length - 1;) + { + latlngs.push([numbers[j++], numbers[j++]]); + } + nogos.push(L.polyline(latlngs)); + } + } + return nogos; + }, + + _getNogosPolygonsString: function(nogos) { + var s = ''; + for (var i = 0, polygon, vertices; i < nogos.length; i++) { + polygon = nogos[i]; + vertices = polygon.getLatLngs()[0]; + for (var j = 0; j < vertices.length; j++) { + if (j > 0) { + s += L.BRouter.NUMBER_SEPARATOR; + } + s += this._formatLatLng(vertices[j]); + } + if (i < (nogos.length - 1)) { + s += L.BRouter.GROUP_SEPARATOR; + } + } + return s; + }, + + _parseNogosPolygons: function(s) { + var groups, + numbers, + latlngs, + nogos = []; + + groups = s.split(L.BRouter.GROUP_SEPARATOR); + for (var i = 0; i < groups.length; i++) + { + numbers = groups[i].split(L.BRouter.NUMBER_SEPARATOR); + if (numbers.length > 1) + { + latlngs = []; + for (var j = 0; j < numbers.length - 1;) + { + latlngs.push([numbers[j++], numbers[j++]]); + } + nogos.push(L.polygon(latlngs)); + } + } + return nogos; + }, + // formats L.LatLng object as lng,lat string _formatLatLng: function(latLng) { var s = '';