bump waht3words package

add msg.payload{lat:lon} option
This commit is contained in:
Dave Conway-Jones 2017-10-22 11:00:48 +01:00
parent 2f14b17948
commit 3e8353fa0e
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 21 additions and 5 deletions

View File

@ -27,6 +27,11 @@ To convert position to words it requires
- `msg.location.lat`
- `msg.location.lon`
or
- `msg.payload.lat`
- `msg.payload.lon`
or
- `msg.payload` containing a string lat,lon
@ -36,6 +41,8 @@ To convert words to position it requires
- `msg.payload` containing a string of _unique.three.words_
A 3 word string separated by dots.
The API-key is stored in a separate credentials file.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-what3words",
"version" : "0.0.5",
"version" : "0.0.7",
"description" : "A Node-RED node to convert locations to/from what3words",
"dependencies" : {
"geo.what3words" : "^2.0.0"

View File

@ -12,10 +12,19 @@ module.exports = function(RED) {
var w1 = /^\*\w{6,31}$/;
var w3 = /^\w+\.\w+\.\w+$/;
this.on("input", function(msg) {
if (msg.hasOwnProperty("location")) {
var lat = msg.location.lat;
var lon = msg.location.lon;
node.w3w.positionToWords({ position:lat + "," + lon, lang:node.lang })
if (msg.hasOwnProperty("location") && msg.location.hasOwnProperty("lat") && msg.location.hasOwnProperty("lon")) {
node.w3w.positionToWords({ position:msg.location.lat + "," + msg.location.lon, lang:node.lang })
.then(function(response) {
msg.payload = response; // prom.cape.pump
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }
node.send(msg);
})
.catch(function(err) {
node.warn(err)
});
}
else if (msg.hasOwnProperty("payload") && msg.payload.hasOwnProperty("lat") && msg.payload.hasOwnProperty("lon")) {
node.w3w.positionToWords({ position:msg.payload.lat + "," + msg.payload.lon, lang:node.lang })
.then(function(response) {
msg.payload = response; // prom.cape.pump
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }