node-red-contrib-web-worldmap 4.9.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/README.md +7 -3
- package/examples/{feedback.json → Feedback.json} +1 -9
- package/examples/MouseCoordinates.json +159 -0
- package/examples/sidcEdgeIcon.json +158 -0
- package/node_modules/@turf/bezier-spline/README.md +15 -21
- package/node_modules/@turf/bezier-spline/dist/cjs/index.cjs +165 -0
- package/node_modules/@turf/bezier-spline/dist/cjs/index.cjs.map +1 -0
- package/node_modules/@turf/bezier-spline/dist/{es/index.js → cjs/index.d.cts} +9 -30
- package/node_modules/@turf/bezier-spline/dist/{js → esm}/index.d.ts +5 -3
- package/node_modules/@turf/bezier-spline/dist/esm/index.js +165 -0
- package/node_modules/@turf/bezier-spline/dist/esm/index.js.map +1 -0
- package/node_modules/@turf/bezier-spline/package.json +33 -25
- package/node_modules/@turf/helpers/README.md +231 -219
- package/node_modules/@turf/helpers/dist/cjs/index.cjs +308 -0
- package/node_modules/@turf/helpers/dist/cjs/index.cjs.map +1 -0
- package/node_modules/@turf/helpers/dist/{es/index.js → cjs/index.d.cts} +103 -303
- package/node_modules/@turf/helpers/dist/{js → esm}/index.d.ts +67 -53
- package/node_modules/@turf/helpers/dist/esm/index.js +308 -0
- package/node_modules/@turf/helpers/dist/esm/index.js.map +1 -0
- package/node_modules/@turf/helpers/package.json +32 -22
- package/node_modules/@turf/invariant/README.md +47 -58
- package/node_modules/@turf/invariant/dist/cjs/index.cjs +127 -0
- package/node_modules/@turf/invariant/dist/cjs/index.cjs.map +1 -0
- package/node_modules/@turf/invariant/dist/cjs/index.d.cts +108 -0
- package/node_modules/@turf/invariant/dist/{js → esm}/index.d.ts +12 -9
- package/node_modules/@turf/invariant/dist/esm/index.js +127 -0
- package/node_modules/@turf/invariant/dist/esm/index.js.map +1 -0
- package/node_modules/@turf/invariant/package.json +31 -22
- package/node_modules/@types/geojson/LICENSE +21 -0
- package/node_modules/@types/geojson/README.md +15 -0
- package/node_modules/@types/geojson/index.d.ts +165 -0
- package/node_modules/@types/geojson/package.json +45 -0
- package/node_modules/body-parser/HISTORY.md +7 -0
- package/node_modules/body-parser/README.md +11 -0
- package/node_modules/body-parser/lib/types/urlencoded.js +30 -7
- package/node_modules/body-parser/package.json +2 -2
- package/node_modules/encodeurl/README.md +19 -38
- package/node_modules/encodeurl/index.js +1 -1
- package/node_modules/encodeurl/package.json +7 -7
- package/node_modules/express/History.md +27 -0
- package/node_modules/express/Readme.md +100 -6
- package/node_modules/express/lib/response.js +11 -10
- package/node_modules/express/package.json +11 -11
- package/node_modules/finalhandler/HISTORY.md +15 -0
- package/node_modules/finalhandler/README.md +2 -2
- package/node_modules/finalhandler/index.js +7 -2
- package/node_modules/finalhandler/package.json +8 -7
- package/node_modules/merge-descriptors/README.md +4 -3
- package/node_modules/merge-descriptors/index.js +3 -3
- package/node_modules/merge-descriptors/package.json +14 -7
- package/node_modules/mime-db/HISTORY.md +14 -0
- package/node_modules/mime-db/README.md +27 -24
- package/node_modules/mime-db/db.json +646 -62
- package/node_modules/mime-db/package.json +9 -13
- package/node_modules/mime-types/node_modules/mime-db/HISTORY.md +507 -0
- package/node_modules/mime-types/node_modules/mime-db/LICENSE +23 -0
- package/node_modules/mime-types/node_modules/mime-db/README.md +100 -0
- package/node_modules/mime-types/node_modules/mime-db/db.json +8519 -0
- package/node_modules/mime-types/node_modules/mime-db/index.js +12 -0
- package/node_modules/mime-types/node_modules/mime-db/package.json +60 -0
- package/node_modules/object-inspect/CHANGELOG.md +15 -0
- package/node_modules/object-inspect/index.js +4 -1
- package/node_modules/object-inspect/package.json +14 -9
- package/node_modules/object-inspect/readme.markdown +9 -11
- package/node_modules/path-to-regexp/index.js +57 -40
- package/node_modules/path-to-regexp/package.json +2 -2
- package/node_modules/qs/.editorconfig +3 -0
- package/node_modules/qs/.eslintrc +2 -2
- package/node_modules/qs/CHANGELOG.md +59 -5
- package/node_modules/qs/README.md +133 -49
- package/node_modules/qs/dist/qs.js +56 -2020
- package/node_modules/qs/lib/parse.js +46 -13
- package/node_modules/qs/lib/stringify.js +53 -28
- package/node_modules/qs/lib/utils.js +47 -34
- package/node_modules/qs/package.json +26 -12
- package/node_modules/qs/test/empty-keys-cases.js +267 -0
- package/node_modules/qs/test/parse.js +347 -32
- package/node_modules/qs/test/stringify.js +436 -47
- package/node_modules/send/HISTORY.md +5 -0
- package/node_modules/send/index.js +1 -2
- package/node_modules/send/node_modules/encodeurl/LICENSE +22 -0
- package/node_modules/send/node_modules/encodeurl/README.md +128 -0
- package/node_modules/send/node_modules/encodeurl/index.js +60 -0
- package/node_modules/send/node_modules/encodeurl/package.json +40 -0
- package/node_modules/send/package.json +1 -1
- package/node_modules/serve-static/HISTORY.md +16 -0
- package/node_modules/serve-static/index.js +1 -2
- package/node_modules/serve-static/package.json +3 -3
- package/node_modules/tslib/CopyrightNotice.txt +15 -0
- package/node_modules/tslib/LICENSE.txt +12 -0
- package/node_modules/tslib/README.md +164 -0
- package/node_modules/tslib/SECURITY.md +41 -0
- package/node_modules/tslib/modules/index.d.ts +37 -0
- package/node_modules/tslib/modules/index.js +68 -0
- package/node_modules/tslib/modules/package.json +3 -0
- package/node_modules/tslib/package.json +47 -0
- package/node_modules/tslib/tslib.d.ts +453 -0
- package/node_modules/tslib/tslib.es6.html +1 -0
- package/node_modules/tslib/tslib.es6.js +379 -0
- package/node_modules/tslib/tslib.es6.mjs +378 -0
- package/node_modules/tslib/tslib.html +1 -0
- package/node_modules/tslib/tslib.js +429 -0
- package/package.json +5 -5
- package/worldmap/index.html +1 -1
- package/worldmap/leaflet/leaflet.mousecoordinate.js +3 -3
- package/worldmap/worldmap.js +123 -36
- package/worldmap.html +1 -1
- package/worldmap.js +23 -4
- package/node_modules/@turf/bezier-spline/dist/es/lib/spline.js +0 -158
- package/node_modules/@turf/bezier-spline/dist/es/package.json +0 -1
- package/node_modules/@turf/bezier-spline/dist/js/index.js +0 -65
- package/node_modules/@turf/bezier-spline/dist/js/lib/spline.d.ts +0 -62
- package/node_modules/@turf/bezier-spline/dist/js/lib/spline.js +0 -160
- package/node_modules/@turf/helpers/dist/es/lib/geojson.js +0 -7
- package/node_modules/@turf/helpers/dist/es/package.json +0 -1
- package/node_modules/@turf/helpers/dist/js/index.js +0 -724
- package/node_modules/@turf/helpers/dist/js/lib/geojson.d.ts +0 -193
- package/node_modules/@turf/helpers/dist/js/lib/geojson.js +0 -9
- package/node_modules/@turf/invariant/dist/es/index.js +0 -223
- package/node_modules/@turf/invariant/dist/es/package.json +0 -1
- package/node_modules/@turf/invariant/dist/js/index.js +0 -233
- package/node_modules/path-to-regexp/History.md +0 -36
- /package/node_modules/{encodeurl → send/node_modules/encodeurl}/HISTORY.md +0 -0
package/worldmap/worldmap.js
CHANGED
|
@@ -438,9 +438,9 @@ var Lgrid = L.latlngGraticule({
|
|
|
438
438
|
// Add small sidc icons around edge of map for things just outside of view
|
|
439
439
|
// This function based heavily on Game Aware code from Måns Beckman
|
|
440
440
|
// Copyright (c) 2013 Måns Beckman, All rights reserved.
|
|
441
|
-
var edgeAware = function() {
|
|
441
|
+
var edgeAware = function () {
|
|
442
|
+
map.removeLayer(edgeLayer);
|
|
442
443
|
if (!edgeEnabled) { return; }
|
|
443
|
-
map.removeLayer(edgeLayer)
|
|
444
444
|
edgeLayer = new L.layerGroup();
|
|
445
445
|
var mapBounds = map.getBounds();
|
|
446
446
|
var mapBoundsCenter = mapBounds.getCenter();
|
|
@@ -599,6 +599,30 @@ function setCluster(v) {
|
|
|
599
599
|
showMapCurrentZoom();
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
+
var typingTimer;
|
|
603
|
+
document.getElementById('search').addEventListener('keyup', () => {
|
|
604
|
+
clearTimeout(typingTimer);
|
|
605
|
+
if (document.getElementById('search').value.length >= 4) {
|
|
606
|
+
typingTimer = setTimeout(doneTyping, 700);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
function doneTyping () { doSearch(); }
|
|
611
|
+
|
|
612
|
+
async function readPhoton(url) {
|
|
613
|
+
const response = await fetch(url);
|
|
614
|
+
const reader = response.body.getReader();
|
|
615
|
+
let v = "";
|
|
616
|
+
while (true) {
|
|
617
|
+
const { done, value } = await reader.read();
|
|
618
|
+
if (done) {
|
|
619
|
+
if (value !== undefined) { v += new TextDecoder().decode(value); }
|
|
620
|
+
return v;
|
|
621
|
+
}
|
|
622
|
+
v += new TextDecoder().decode(value)
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
602
626
|
// Search for markers with names of ... or icons of ...
|
|
603
627
|
function doSearch() {
|
|
604
628
|
var value = document.getElementById('search').value;
|
|
@@ -615,17 +639,21 @@ function doSearch() {
|
|
|
615
639
|
moveToMarks();
|
|
616
640
|
if (marks.length === 0) {
|
|
617
641
|
// If no markers found let's try a geolookup...
|
|
642
|
+
|
|
618
643
|
var protocol = location.protocol;
|
|
619
644
|
if (protocol == "file:") { protocol = "https:"; }
|
|
620
|
-
var searchUrl = protocol + "//nominatim.openstreetmap.org/search?format=json&limit=
|
|
645
|
+
var searchUrl = protocol + "//nominatim.openstreetmap.org/search?format=json&limit=5&q=";
|
|
621
646
|
|
|
622
647
|
fetch(searchUrl + value) // Call the fetch function passing the url of the API as a parameter
|
|
623
648
|
.then(function(resp) { return resp.json(); })
|
|
624
649
|
.then(function(data) {
|
|
625
650
|
if (data.length > 0) {
|
|
651
|
+
// var l = data.map((x) => x.display_name);
|
|
652
|
+
// console.log("LIST",l)
|
|
626
653
|
var bb = data[0].boundingbox;
|
|
627
654
|
map.fitBounds([ [bb[0],bb[2]], [bb[1],bb[3]] ]);
|
|
628
655
|
map.panTo([data[0].lat, data[0].lon]);
|
|
656
|
+
document.getElementById('searchResult').innerHTML = "";
|
|
629
657
|
}
|
|
630
658
|
else {
|
|
631
659
|
document.getElementById('searchResult').innerHTML = " <font color='#ff0'>Not Found</font>";
|
|
@@ -636,6 +664,35 @@ function doSearch() {
|
|
|
636
664
|
document.getElementById('searchResult').innerHTML = " <font color='#ff0'>Not Found</font>";
|
|
637
665
|
}
|
|
638
666
|
});
|
|
667
|
+
|
|
668
|
+
// var searchUrl = 'https://photon.komoot.io/api?limit=5&q=';
|
|
669
|
+
// readPhoton(searchUrl + value).then(
|
|
670
|
+
// function(value) {
|
|
671
|
+
// if (value.length > 0 && typeof value === "string") {
|
|
672
|
+
// var s = JSON.parse(value);
|
|
673
|
+
// if (s?.features) {
|
|
674
|
+
// var l = s.features.map((x) => x.properties.name +', ' + x.properties.countrycode);
|
|
675
|
+
// console.log("LIST",l)
|
|
676
|
+
// if (s.features.length > 0) {
|
|
677
|
+
// if (s.features[0].properties?.extent) {
|
|
678
|
+
// var bb = s.features[0].properties.extent;
|
|
679
|
+
// map.fitBounds([ [bb[3],bb[0]], [bb[1],bb[2]] ]);
|
|
680
|
+
// }
|
|
681
|
+
// else {
|
|
682
|
+
// map.panTo([s.features[0].geometry.coordinates[1], s.features[0].geometry.coordinates[0]]);
|
|
683
|
+
// }
|
|
684
|
+
// document.getElementById('searchResult').innerHTML = "";
|
|
685
|
+
// }
|
|
686
|
+
// else {
|
|
687
|
+
// document.getElementById('searchResult').innerHTML = " <font color='#ff0'>Not Found</font>";}
|
|
688
|
+
// }
|
|
689
|
+
// }
|
|
690
|
+
// },
|
|
691
|
+
// function(error) {
|
|
692
|
+
// document.getElementById('searchResult').innerHTML = " <font color='#ff0'>Search Error</font>";
|
|
693
|
+
// }
|
|
694
|
+
// );
|
|
695
|
+
|
|
639
696
|
}
|
|
640
697
|
else {
|
|
641
698
|
if (lockit) {
|
|
@@ -864,30 +921,51 @@ var addThing = function() {
|
|
|
864
921
|
|
|
865
922
|
var form = {};
|
|
866
923
|
var addToForm = function(n,v) { form[n] = v; }
|
|
867
|
-
var feedback = function(n,v,a,c) {
|
|
924
|
+
var feedback = function(n = "map",v,a = "feedback",c) {
|
|
868
925
|
if (v === "_form") { v = form; }
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
926
|
+
// undefined is handled directly in the function declaration, but null/"" also requires explicit handling within the function.
|
|
927
|
+
n = (n === null || n === "") ? "map" : n;
|
|
928
|
+
var dataToSend = { "name": n, "action": a, "value": v };
|
|
929
|
+
//Kept only for backward compatibility, as the context menu should handle the click position values internally.
|
|
930
|
+
if (n == "map") {
|
|
931
|
+
dataToSend.lat = rclk.lat;
|
|
932
|
+
dataToSend.lon = rclk.lng;
|
|
933
|
+
}
|
|
934
|
+
ws.send(JSON.stringify(dataToSend));
|
|
935
|
+
|
|
936
|
+
//** The following lines left just to verify reasoning and clarifying why it was removed
|
|
937
|
+
|
|
938
|
+
//** the reasong to seperate entities uncleare
|
|
939
|
+
//if (markers[n]) {
|
|
940
|
+
// console.log("FB1",n,v,a,c)
|
|
941
|
+
//** Why are we even modifying `allData`?
|
|
942
|
+
// allData[n].action = a || "feedback";
|
|
872
943
|
//if (v !== undefined) { allData[n][a||"value"] = v; }
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
944
|
+
// if (v !== undefined) { allData[n]["value"] = v; }
|
|
945
|
+
//** Why are we sending back the `allData` object at all?
|
|
946
|
+
// ws.send(JSON.stringify(allData[n]));
|
|
947
|
+
///** Why are we updating the markers array from a feedback function?
|
|
948
|
+
// setMarker(allData[n]);
|
|
949
|
+
//}
|
|
950
|
+
|
|
951
|
+
//** what is so sppecial about feedback fomr polygons?
|
|
952
|
+
//else if (polygons[n]) {
|
|
878
953
|
// console.log("FB2", n, v, a);
|
|
879
|
-
|
|
954
|
+
// const polyData = { "name": n, "action": a || "feedback", "value": v || null };
|
|
880
955
|
//sendDrawing(n,v,a)
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
956
|
+
// ws.send(JSON.stringify(polyData));
|
|
957
|
+
//}
|
|
958
|
+
//** If neither a polygon nor a marker is found, assume it's a map and send the same data?
|
|
959
|
+
//else {
|
|
960
|
+
// if (n === undefined) { n = "map"; }
|
|
885
961
|
// console.log("FB3",n,v,a,c)
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
962
|
+
//** Modifying menu content inside feedback function is a bug!
|
|
963
|
+
// rmenudata = v;
|
|
964
|
+
// ws.send(JSON.stringify({action:a||"feedback", name:n, value:v, lat:rclk.lat, lon:rclk.lng}));
|
|
965
|
+
//}
|
|
966
|
+
//** Sending the same data again is redundant, as it could result in feedback being sent twice (except for the markers where we sent unnecessary data).
|
|
967
|
+
//const dataToSend = { "name": n, "action": a || "feedback", "value": v || null };
|
|
968
|
+
//ws.send(JSON.stringify(dataToSend));
|
|
891
969
|
if (c === true) { map.closePopup(); }
|
|
892
970
|
}
|
|
893
971
|
|
|
@@ -1347,18 +1425,18 @@ var addOverlays = function(overlist) {
|
|
|
1347
1425
|
}
|
|
1348
1426
|
|
|
1349
1427
|
// Add Air Corridors
|
|
1350
|
-
if (overlist.indexOf("AC")!==-1) {
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
}
|
|
1428
|
+
// if (overlist.indexOf("AC")!==-1) {
|
|
1429
|
+
// overlays["air corridors"] = L.tileLayer('https://api.tiles.openaip.net/api/data/openaip/{z}/{x}/{y}.png', {
|
|
1430
|
+
// attribution: '<a href="https://www.openaip.net/">openAIP Data</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-NC-SA</a>)',
|
|
1431
|
+
// ext: 'png',
|
|
1432
|
+
// minZoom: 4,
|
|
1433
|
+
// maxZoom: 15,
|
|
1434
|
+
// maxNativeZoom: 14,
|
|
1435
|
+
// tms: true,
|
|
1436
|
+
// detectRetina: true,
|
|
1437
|
+
// subdomains: '12'
|
|
1438
|
+
// });
|
|
1439
|
+
// }
|
|
1362
1440
|
|
|
1363
1441
|
// Add the OpenSea markers layer
|
|
1364
1442
|
if (overlist.indexOf("SN")!==-1) {
|
|
@@ -2452,8 +2530,10 @@ function doCommand(cmd) {
|
|
|
2452
2530
|
document.getElementById("toplink").setAttribute("style", "pointer-events:none");
|
|
2453
2531
|
}
|
|
2454
2532
|
}
|
|
2455
|
-
if (cmd.hasOwnProperty("clear")) {
|
|
2456
|
-
|
|
2533
|
+
if (cmd.hasOwnProperty("clearlayer") || cmd.hasOwnProperty("clear")) {
|
|
2534
|
+
var clr = cmd.clearlayer || cmd.clear;
|
|
2535
|
+
if (!Array.isArray(clr)) { clr = [ clr ]; }
|
|
2536
|
+
clr.forEach((el) => doTidyUp(el));
|
|
2457
2537
|
}
|
|
2458
2538
|
if (cmd.hasOwnProperty("panit")) {
|
|
2459
2539
|
if (cmd.panit == true || cmd.panit === "true") { panit = true; }
|
|
@@ -3066,6 +3146,13 @@ function doCommand(cmd) {
|
|
|
3066
3146
|
document.getElementById("maxage").value = cmd.maxage;
|
|
3067
3147
|
setMaxAge();
|
|
3068
3148
|
}
|
|
3149
|
+
if (cmd.hasOwnProperty("sidcEdgeIcon")) {
|
|
3150
|
+
if (typeof cmd.sidcEdgeIcon === 'boolean') {
|
|
3151
|
+
edgeEnabled = cmd.sidcEdgeIcon;
|
|
3152
|
+
} else {
|
|
3153
|
+
console.log("ERR - invalid sidcEdgeIcon command: ", cmd.sidcEdgeIcon);
|
|
3154
|
+
}
|
|
3155
|
+
}
|
|
3069
3156
|
// Replace heatmap layer with new array (and optionally options)
|
|
3070
3157
|
if (cmd.hasOwnProperty("heatmap") && heat) {
|
|
3071
3158
|
if (cmd.hasOwnProperty("options")) { heat.setOptions(cmd.options); }
|
package/worldmap.html
CHANGED
|
@@ -345,7 +345,7 @@ If <i>Web Path</i> is left empty, then by default <code>⌘⇧m</code> - <code>c
|
|
|
345
345
|
{ value: "BU", label: "Buildings" },
|
|
346
346
|
{ value: "RW", label: "Railways" },
|
|
347
347
|
{ value: "SN", label: "Ship Navigation" },
|
|
348
|
-
{ value: "AC", label: "Air Corridors" },
|
|
348
|
+
// { value: "AC", label: "Air Corridors" },
|
|
349
349
|
{ value: "TL", label: "Place Labels" },
|
|
350
350
|
{ value: "HM", label: "Heatmap" }
|
|
351
351
|
]
|
package/worldmap.js
CHANGED
|
@@ -493,13 +493,32 @@ module.exports = function(RED) {
|
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
if (msg?.payload?.command?.clear) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
496
|
+
if (!isArray(msg?.payload?.command?.clear)) {
|
|
497
|
+
msg.payload.command.clear = [ msg.payload.command.clear ]
|
|
498
|
+
}
|
|
499
|
+
msg.payload.command.clear.forEach(function(el) {
|
|
500
|
+
for (let p in node.pointsarray) {
|
|
501
|
+
if (node.pointsarray.hasOwnProperty(p)) {
|
|
502
|
+
if (node.pointsarray[p][0].layer === el) {
|
|
503
|
+
delete node.pointsarray[p];
|
|
504
|
+
}
|
|
500
505
|
}
|
|
501
506
|
}
|
|
507
|
+
})
|
|
508
|
+
}
|
|
509
|
+
if (msg?.payload?.command?.clearlayer) {
|
|
510
|
+
if (!isArray(msg?.payload?.command?.clearlayer)) {
|
|
511
|
+
msg.payload.command.clearlayer = [ msg.payload.command.clearlayer ]
|
|
502
512
|
}
|
|
513
|
+
msg.payload.command.clearlayer.forEach(function(el) {
|
|
514
|
+
for (let p in node.pointsarray) {
|
|
515
|
+
if (node.pointsarray.hasOwnProperty(p)) {
|
|
516
|
+
if (node.pointsarray[p][0].layer === el) {
|
|
517
|
+
delete node.pointsarray[p];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
})
|
|
503
522
|
}
|
|
504
523
|
}
|
|
505
524
|
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BezierSpline
|
|
3
|
-
* https://github.com/leszekr/bezier-spline-js
|
|
4
|
-
*
|
|
5
|
-
* @private
|
|
6
|
-
* @copyright
|
|
7
|
-
* Copyright (c) 2013 Leszek Rybicki
|
|
8
|
-
*
|
|
9
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
* in the Software without restriction, including without limitation the rights
|
|
12
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
-
* furnished to do so, subject to the following conditions:
|
|
15
|
-
*
|
|
16
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
-
* copies or substantial portions of the Software.
|
|
18
|
-
*
|
|
19
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
-
* SOFTWARE.
|
|
26
|
-
*/
|
|
27
|
-
var Spline = /** @class */ (function () {
|
|
28
|
-
function Spline(options) {
|
|
29
|
-
this.points = options.points || [];
|
|
30
|
-
this.duration = options.duration || 10000;
|
|
31
|
-
this.sharpness = options.sharpness || 0.85;
|
|
32
|
-
this.centers = [];
|
|
33
|
-
this.controls = [];
|
|
34
|
-
this.stepLength = options.stepLength || 60;
|
|
35
|
-
this.length = this.points.length;
|
|
36
|
-
this.delay = 0;
|
|
37
|
-
// this is to ensure compatibility with the 2d version
|
|
38
|
-
for (var i = 0; i < this.length; i++) {
|
|
39
|
-
this.points[i].z = this.points[i].z || 0;
|
|
40
|
-
}
|
|
41
|
-
for (var i = 0; i < this.length - 1; i++) {
|
|
42
|
-
var p1 = this.points[i];
|
|
43
|
-
var p2 = this.points[i + 1];
|
|
44
|
-
this.centers.push({
|
|
45
|
-
x: (p1.x + p2.x) / 2,
|
|
46
|
-
y: (p1.y + p2.y) / 2,
|
|
47
|
-
z: (p1.z + p2.z) / 2,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
this.controls.push([this.points[0], this.points[0]]);
|
|
51
|
-
for (var i = 0; i < this.centers.length - 1; i++) {
|
|
52
|
-
var dx = this.points[i + 1].x - (this.centers[i].x + this.centers[i + 1].x) / 2;
|
|
53
|
-
var dy = this.points[i + 1].y - (this.centers[i].y + this.centers[i + 1].y) / 2;
|
|
54
|
-
var dz = this.points[i + 1].z - (this.centers[i].y + this.centers[i + 1].z) / 2;
|
|
55
|
-
this.controls.push([
|
|
56
|
-
{
|
|
57
|
-
x: (1.0 - this.sharpness) * this.points[i + 1].x +
|
|
58
|
-
this.sharpness * (this.centers[i].x + dx),
|
|
59
|
-
y: (1.0 - this.sharpness) * this.points[i + 1].y +
|
|
60
|
-
this.sharpness * (this.centers[i].y + dy),
|
|
61
|
-
z: (1.0 - this.sharpness) * this.points[i + 1].z +
|
|
62
|
-
this.sharpness * (this.centers[i].z + dz),
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
x: (1.0 - this.sharpness) * this.points[i + 1].x +
|
|
66
|
-
this.sharpness * (this.centers[i + 1].x + dx),
|
|
67
|
-
y: (1.0 - this.sharpness) * this.points[i + 1].y +
|
|
68
|
-
this.sharpness * (this.centers[i + 1].y + dy),
|
|
69
|
-
z: (1.0 - this.sharpness) * this.points[i + 1].z +
|
|
70
|
-
this.sharpness * (this.centers[i + 1].z + dz),
|
|
71
|
-
},
|
|
72
|
-
]);
|
|
73
|
-
}
|
|
74
|
-
this.controls.push([
|
|
75
|
-
this.points[this.length - 1],
|
|
76
|
-
this.points[this.length - 1],
|
|
77
|
-
]);
|
|
78
|
-
this.steps = this.cacheSteps(this.stepLength);
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Caches an array of equidistant (more or less) points on the curve.
|
|
83
|
-
*/
|
|
84
|
-
Spline.prototype.cacheSteps = function (mindist) {
|
|
85
|
-
var steps = [];
|
|
86
|
-
var laststep = this.pos(0);
|
|
87
|
-
steps.push(0);
|
|
88
|
-
for (var t = 0; t < this.duration; t += 10) {
|
|
89
|
-
var step = this.pos(t);
|
|
90
|
-
var dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) +
|
|
91
|
-
(step.y - laststep.y) * (step.y - laststep.y) +
|
|
92
|
-
(step.z - laststep.z) * (step.z - laststep.z));
|
|
93
|
-
if (dist > mindist) {
|
|
94
|
-
steps.push(t);
|
|
95
|
-
laststep = step;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return steps;
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* returns angle and speed in the given point in the curve
|
|
102
|
-
*/
|
|
103
|
-
Spline.prototype.vector = function (t) {
|
|
104
|
-
var p1 = this.pos(t + 10);
|
|
105
|
-
var p2 = this.pos(t - 10);
|
|
106
|
-
return {
|
|
107
|
-
angle: (180 * Math.atan2(p1.y - p2.y, p1.x - p2.x)) / 3.14,
|
|
108
|
-
speed: Math.sqrt((p2.x - p1.x) * (p2.x - p1.x) +
|
|
109
|
-
(p2.y - p1.y) * (p2.y - p1.y) +
|
|
110
|
-
(p2.z - p1.z) * (p2.z - p1.z)),
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Gets the position of the point, given time.
|
|
115
|
-
*
|
|
116
|
-
* WARNING: The speed is not constant. The time it takes between control points is constant.
|
|
117
|
-
*
|
|
118
|
-
* For constant speed, use Spline.steps[i];
|
|
119
|
-
*/
|
|
120
|
-
Spline.prototype.pos = function (time) {
|
|
121
|
-
var t = time - this.delay;
|
|
122
|
-
if (t < 0) {
|
|
123
|
-
t = 0;
|
|
124
|
-
}
|
|
125
|
-
if (t > this.duration) {
|
|
126
|
-
t = this.duration - 1;
|
|
127
|
-
}
|
|
128
|
-
// t = t-this.delay;
|
|
129
|
-
var t2 = t / this.duration;
|
|
130
|
-
if (t2 >= 1) {
|
|
131
|
-
return this.points[this.length - 1];
|
|
132
|
-
}
|
|
133
|
-
var n = Math.floor((this.points.length - 1) * t2);
|
|
134
|
-
var t1 = (this.length - 1) * t2 - n;
|
|
135
|
-
return bezier(t1, this.points[n], this.controls[n][1], this.controls[n + 1][0], this.points[n + 1]);
|
|
136
|
-
};
|
|
137
|
-
return Spline;
|
|
138
|
-
}());
|
|
139
|
-
export default Spline;
|
|
140
|
-
function bezier(t, p1, c1, c2, p2) {
|
|
141
|
-
var b = B(t);
|
|
142
|
-
var pos = {
|
|
143
|
-
x: p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],
|
|
144
|
-
y: p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],
|
|
145
|
-
z: p2.z * b[0] + c2.z * b[1] + c1.z * b[2] + p1.z * b[3],
|
|
146
|
-
};
|
|
147
|
-
return pos;
|
|
148
|
-
}
|
|
149
|
-
function B(t) {
|
|
150
|
-
var t2 = t * t;
|
|
151
|
-
var t3 = t2 * t;
|
|
152
|
-
return [
|
|
153
|
-
t3,
|
|
154
|
-
3 * t2 * (1 - t),
|
|
155
|
-
3 * t * (1 - t) * (1 - t),
|
|
156
|
-
(1 - t) * (1 - t) * (1 - t),
|
|
157
|
-
];
|
|
158
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var helpers_1 = require("@turf/helpers");
|
|
7
|
-
var invariant_1 = require("@turf/invariant");
|
|
8
|
-
var spline_1 = __importDefault(require("./lib/spline"));
|
|
9
|
-
/**
|
|
10
|
-
* Takes a {@link LineString|line} and returns a curved version
|
|
11
|
-
* by applying a [Bezier spline](http://en.wikipedia.org/wiki/B%C3%A9zier_spline)
|
|
12
|
-
* algorithm.
|
|
13
|
-
*
|
|
14
|
-
* The bezier spline implementation is by [Leszek Rybicki](http://leszek.rybicki.cc/).
|
|
15
|
-
*
|
|
16
|
-
* @name bezierSpline
|
|
17
|
-
* @param {Feature<LineString>} line input LineString
|
|
18
|
-
* @param {Object} [options={}] Optional parameters
|
|
19
|
-
* @param {Object} [options.properties={}] Translate properties to output
|
|
20
|
-
* @param {number} [options.resolution=10000] time in milliseconds between points
|
|
21
|
-
* @param {number} [options.sharpness=0.85] a measure of how curvy the path should be between splines
|
|
22
|
-
* @returns {Feature<LineString>} curved line
|
|
23
|
-
* @example
|
|
24
|
-
* var line = turf.lineString([
|
|
25
|
-
* [-76.091308, 18.427501],
|
|
26
|
-
* [-76.695556, 18.729501],
|
|
27
|
-
* [-76.552734, 19.40443],
|
|
28
|
-
* [-74.61914, 19.134789],
|
|
29
|
-
* [-73.652343, 20.07657],
|
|
30
|
-
* [-73.157958, 20.210656]
|
|
31
|
-
* ]);
|
|
32
|
-
*
|
|
33
|
-
* var curved = turf.bezierSpline(line);
|
|
34
|
-
*
|
|
35
|
-
* //addToMap
|
|
36
|
-
* var addToMap = [line, curved]
|
|
37
|
-
* curved.properties = { stroke: '#0F0' };
|
|
38
|
-
*/
|
|
39
|
-
function bezier(line, options) {
|
|
40
|
-
if (options === void 0) { options = {}; }
|
|
41
|
-
// Optional params
|
|
42
|
-
var resolution = options.resolution || 10000;
|
|
43
|
-
var sharpness = options.sharpness || 0.85;
|
|
44
|
-
var coords = [];
|
|
45
|
-
var points = invariant_1.getGeom(line).coordinates.map(function (pt) {
|
|
46
|
-
return { x: pt[0], y: pt[1] };
|
|
47
|
-
});
|
|
48
|
-
var spline = new spline_1.default({
|
|
49
|
-
duration: resolution,
|
|
50
|
-
points: points,
|
|
51
|
-
sharpness: sharpness,
|
|
52
|
-
});
|
|
53
|
-
var pushCoord = function (time) {
|
|
54
|
-
var pos = spline.pos(time);
|
|
55
|
-
if (Math.floor(time / 100) % 2 === 0) {
|
|
56
|
-
coords.push([pos.x, pos.y]);
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
for (var i = 0; i < spline.duration; i += 10) {
|
|
60
|
-
pushCoord(i);
|
|
61
|
-
}
|
|
62
|
-
pushCoord(spline.duration);
|
|
63
|
-
return helpers_1.lineString(coords, options.properties);
|
|
64
|
-
}
|
|
65
|
-
exports.default = bezier;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export interface Point {
|
|
2
|
-
x: number;
|
|
3
|
-
y: number;
|
|
4
|
-
z: number;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* BezierSpline
|
|
8
|
-
* https://github.com/leszekr/bezier-spline-js
|
|
9
|
-
*
|
|
10
|
-
* @private
|
|
11
|
-
* @copyright
|
|
12
|
-
* Copyright (c) 2013 Leszek Rybicki
|
|
13
|
-
*
|
|
14
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
-
* in the Software without restriction, including without limitation the rights
|
|
17
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
-
* furnished to do so, subject to the following conditions:
|
|
20
|
-
*
|
|
21
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
-
* copies or substantial portions of the Software.
|
|
23
|
-
*
|
|
24
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
-
* SOFTWARE.
|
|
31
|
-
*/
|
|
32
|
-
export default class Spline {
|
|
33
|
-
duration: number;
|
|
34
|
-
points: Point[];
|
|
35
|
-
sharpness: number;
|
|
36
|
-
centers: Point[];
|
|
37
|
-
controls: Array<[Point, Point]>;
|
|
38
|
-
stepLength: number;
|
|
39
|
-
length: number;
|
|
40
|
-
delay: number;
|
|
41
|
-
steps: number[];
|
|
42
|
-
constructor(options?: any);
|
|
43
|
-
/**
|
|
44
|
-
* Caches an array of equidistant (more or less) points on the curve.
|
|
45
|
-
*/
|
|
46
|
-
cacheSteps(mindist: number): number[];
|
|
47
|
-
/**
|
|
48
|
-
* returns angle and speed in the given point in the curve
|
|
49
|
-
*/
|
|
50
|
-
vector(t: number): {
|
|
51
|
-
angle: number;
|
|
52
|
-
speed: number;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* Gets the position of the point, given time.
|
|
56
|
-
*
|
|
57
|
-
* WARNING: The speed is not constant. The time it takes between control points is constant.
|
|
58
|
-
*
|
|
59
|
-
* For constant speed, use Spline.steps[i];
|
|
60
|
-
*/
|
|
61
|
-
pos(time: number): Point;
|
|
62
|
-
}
|