align 3d shapes with direction

This commit is contained in:
Dave Conway-Jones 2021-02-12 18:12:47 +00:00
parent 0ce0f87aed
commit fe394a02f8
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
2 changed files with 16 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-web-worldmap", "name": "node-red-contrib-web-worldmap",
"version": "2.8.2", "version": "2.8.3",
"description": "A Node-RED node to provide a web page of a world map for plotting things on.", "description": "A Node-RED node to provide a web page of a world map for plotting things on.",
"dependencies": { "dependencies": {
"cgi": "0.3.1", "cgi": "0.3.1",

View File

@ -142,7 +142,8 @@ map.on('load', function() {
} }
var setMarker = function(d) { var setMarker = function(d) {
//console.log("DATA",d); if (d.hasOwnProperty("area")) { return; } // ignore areas for now.
console.log("DATA",d);
if (people.hasOwnProperty(d.name)) { if (people.hasOwnProperty(d.name)) {
map.getSource(d.name).setData(getPoints(d)); // Just update existing marker map.getSource(d.name).setData(getPoints(d)); // Just update existing marker
} }
@ -198,7 +199,14 @@ map.on('load', function() {
else if (t === "block") { fac = fac * 4; tall = 5; } // block large and cube else if (t === "block") { fac = fac * 4; tall = 5; } // block large and cube
else { tall = 2; fac = fac * 2; } // else small cube else { tall = 2; fac = fac * 2; } // else small cube
//console.log({p},{t},{fac},{base},{tall}); //console.log({p},{t},{fac},{base},{tall});
var fac2 = fac / Math.cos( Math.PI / 180 * p.lat ); var sin = 1;
var cos = 0;
if (p.hasOwnProperty("hdg")) {
sin = Math.sin((90 - p.hdg) * Math.PI / 180);
cos = Math.cos((90 - p.hdg) * Math.PI / 180);
}
var dx = 1 * cos - 1 * sin;
var dy = 1 * sin + 1 * cos;
var d = { var d = {
"type": "Feature", "type": "Feature",
"properties": { "properties": {
@ -212,11 +220,11 @@ map.on('load', function() {
"type": "Polygon", "type": "Polygon",
"coordinates": [ "coordinates": [
[ [
[ p.lon - fac2, p.lat - fac ], [ p.lon + (fac * dx ) / Math.cos( Math.PI / 180 * p.lat ), p.lat + (fac * dy) ],
[ p.lon - fac2, p.lat + fac ], [ p.lon - (fac * dy ) / Math.cos( Math.PI / 180 * p.lat ), p.lat + (fac * dx) ],
[ p.lon + fac2, p.lat + fac ], [ p.lon - (fac * dx ) / Math.cos( Math.PI / 180 * p.lat ), p.lat - (fac * dy) ],
[ p.lon + fac2, p.lat - fac ], [ p.lon + (fac * dy ) / Math.cos( Math.PI / 180 * p.lat ), p.lat - (fac * dx) ],
[ p.lon - fac2, p.lat - fac ], [ p.lon + (fac * dx ) / Math.cos( Math.PI / 180 * p.lat ), p.lat + (fac * dy) ],
] ]
] ]
} }