Let geohash handle null island

and add test
This commit is contained in:
Dave Conway-Jones 2021-11-29 21:26:24 +00:00
parent 121da5deae
commit 1293a865c1
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 18 additions and 2 deletions

View File

@ -69,6 +69,7 @@ module.exports = function(RED) {
var len = parseInt(value.precision || 9);
if (len < 1) { len = 1; }
if (len > 9) { len = 9; }
value.precision = len;
if (typeof lat === 'number' && typeof lon === 'number') {
value.geohash = geohash.encode(lat, lon, len);
RED.util.setMessageProperty(msg,node.property,value);

View File

@ -1,9 +1,9 @@
{
"name" : "node-red-node-geohash",
"version" : "0.1.9",
"version" : "0.1.10",
"description" : "A Node-RED node to encode and decode lat,lon pairs to a geohash.",
"dependencies" : {
"ngeohash" : "0.6.0"
"ngeohash" : "^0.6.3"
},
"repository" : {
"type":"git",

View File

@ -111,6 +111,21 @@ describe('geohash node', function() {
});
});
it('should convert payload object lat,lon to geohash', function(done) {
var flow = [{"id":"n1", "type":"geohash", func:"geohash", gap:0, wires:[["n2"]] },
{id:"n2", type:"helper"} ];
helper.load(testNode, flow, function() {
var n1 = helper.getNode("n1");
var n2 = helper.getNode("n2");
n2.on("input", function(msg) {
msg.should.have.a.property("payload");
msg.payload.should.have.a.property("geohash", "7zzzzzzzz");
done();
});
n1.emit("input", {payload:{latitude:0,longitude:0,precision:10}});
});
});
it('should convert payload object lat,lon to geohash (low precision)', function(done) {
var flow = [{"id":"n1", "type":"geohash", func:"geohash", gap:0, wires:[["n2"]] },
{id:"n2", type:"helper"} ];