mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
bump waht3words package
add msg.payload{lat:lon} option
This commit is contained in:
parent
2f14b17948
commit
3e8353fa0e
@ -27,6 +27,11 @@ To convert position to words it requires
|
|||||||
- `msg.location.lat`
|
- `msg.location.lat`
|
||||||
- `msg.location.lon`
|
- `msg.location.lon`
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
- `msg.payload.lat`
|
||||||
|
- `msg.payload.lon`
|
||||||
|
|
||||||
or
|
or
|
||||||
|
|
||||||
- `msg.payload` containing a string lat,lon
|
- `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_
|
- `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.
|
The API-key is stored in a separate credentials file.
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "node-red-node-what3words",
|
"name" : "node-red-node-what3words",
|
||||||
"version" : "0.0.5",
|
"version" : "0.0.7",
|
||||||
"description" : "A Node-RED node to convert locations to/from what3words",
|
"description" : "A Node-RED node to convert locations to/from what3words",
|
||||||
"dependencies" : {
|
"dependencies" : {
|
||||||
"geo.what3words" : "^2.0.0"
|
"geo.what3words" : "^2.0.0"
|
||||||
|
@ -12,10 +12,19 @@ module.exports = function(RED) {
|
|||||||
var w1 = /^\*\w{6,31}$/;
|
var w1 = /^\*\w{6,31}$/;
|
||||||
var w3 = /^\w+\.\w+\.\w+$/;
|
var w3 = /^\w+\.\w+\.\w+$/;
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if (msg.hasOwnProperty("location")) {
|
if (msg.hasOwnProperty("location") && msg.location.hasOwnProperty("lat") && msg.location.hasOwnProperty("lon")) {
|
||||||
var lat = msg.location.lat;
|
node.w3w.positionToWords({ position:msg.location.lat + "," + msg.location.lon, lang:node.lang })
|
||||||
var lon = msg.location.lon;
|
.then(function(response) {
|
||||||
node.w3w.positionToWords({ position:lat + "," + lon, lang:node.lang })
|
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) {
|
.then(function(response) {
|
||||||
msg.payload = response; // prom.cape.pump
|
msg.payload = response; // prom.cape.pump
|
||||||
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }
|
if (!msg.hasOwnProperty("topic") || (msg.topic === "")) { msg.topic = "what3words"; }
|
||||||
|
Loading…
Reference in New Issue
Block a user