add bezier smoothing to tracks

This commit is contained in:
Dave Conway-Jones 2021-03-15 13:26:02 +00:00
parent 2d2ef08ce2
commit 1934c7ccbe
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
5 changed files with 21 additions and 4 deletions

View File

@ -1,5 +1,6 @@
### Change Log for Node-RED Worldmap
- v2.11.0 - Add option to smooth tracks using bezier curves.
- v2.10.0 - Save latest position to browser for refresh if in iframe/dashboard. Allow fractional Zoom levels.
- v2.9.0 - Let weblinks be an array of links. Add more info to readme about Mapservers.
- v2.8.9 - Only load cgi module if we have a local mapserv file

View File

@ -11,6 +11,7 @@ map web page for plotting "things" on.
### Updates
- v2.11.0 - Add option to smooth tracks using bezier curves.
- v2.10.0 - Save latest position to browser for refresh if in iframe/dashboard. Allow fractional Zoom levels.
- v2.9.0 - Let weblinks be an array of links. Add more info to readme about Mapservers.
- v2.8.9 - Only load cgi module if we have a local mapserv file.

View File

@ -1,12 +1,13 @@
{
"name": "node-red-contrib-web-worldmap",
"version": "2.10.0",
"version": "2.11.0",
"description": "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies": {
"cgi": "0.3.1",
"compression": "^1.7.4",
"express": "^4.16.4",
"sockjs": "~0.3.21"
"sockjs": "~0.3.21",
"@turf/bezier-spline": "*"
},
"bundledDependencies": [
"cgi",

View File

@ -528,6 +528,11 @@ then by default <code>⌘⇧m</code> - <code>ctrl-shift-m</code> will load the m
<option value="single">single Track layer</option>
</select>
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-smooth" style="display:inline-block; width:auto; vertical-align:top;">
<label for="node-input-smooth" style="width:70%;">Smooth tracks using bezier curves.</label>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-file"></i> Name</label>
<input type="text" id="node-input-name" placeholder="name">
@ -553,7 +558,8 @@ then by default <code>⌘⇧m</code> - <code>ctrl-shift-m</code> will load the m
defaults: {
name: {value:""},
depth: {value:20},
layer: {value:"combined"}
layer: {value:"combined"},
smooth: {value:false}
},
inputs:1,
outputs:1,

View File

@ -273,7 +273,9 @@ module.exports = function(RED) {
this.depth = parseInt(Number(n.depth) || 20);
this.pointsarray = {};
this.layer = n.layer || "combined"; // separate, single
this.smooth = n.smooth || false;
var node = this;
var bezierSpline = require("@turf/bezier-spline").default;
var doTrack = function(msg) {
if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("name")) {
@ -335,7 +337,13 @@ module.exports = function(RED) {
}
}
if (line.length > 1) { // only send track if two points or more
newmsg.payload.line = line;
if (node.smooth) {
var curved = bezierSpline({"type":"Feature", "properties":{}, "geometry":{"type":"LineString", "coordinates":line }});
newmsg.payload.line = curved.geometry.coordinates;
}
else {
newmsg.payload.line = line;
}
newmsg.payload.name = msg.payload.name + "_";
if (node.layer === "separate") {
newmsg.payload.layer = msg.payload.layer + " tracks";