I am changing the the iconcolor of markers to indicate status changes, using this bit of javascript.
let address_to_marker_name_map = global.get("address_to_marker_name_map")
let topic_split = msg.topic.split('/')
if (topic_split < 3 || topic_split > 4) {
console.log(`Invalid MQTT topic received ${msg.topic}`)
return
}
let marker_address
if (topic_split.length == 3)
marker_address = topic_split[2]
else
marker_address = topic_split[2] + '/' + topic_split[3]
let marker_name = address_to_marker_name_map.get(marker_address)
if (marker_name) {
if (msg.payload.hasOwnProperty("value")) {
msg = {};
msg.payload = { "name":marker_name, "iconColor": "#00ff00", "ttl":31536000 }
} else if (msg.payload.hasOwnProperty("active")) {
if (msg.payload.active) {
msg = {};
msg.payload = { "name":marker_name, "iconColor": "#00ff00", "ttl":31536000 }
} else {
msg = {};
msg.payload = { "name":marker_name, "iconColor": "#ff0000", "ttl":31536000 }
}
}
return msg
}
It gets triggered by incoming mqtt messages. Only problem is if I send two consecutive message to marker with the same colour it disappears!
I though it was something to do with ttl but setting that in the message made no difference.
Anyone got any ideas.
R.