Worldmap setting icon colour twice makes markers disappear

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.

where are you setting the lat and lon and icon ?

The markers are initialised at startup using a msg.payload with name lat lon icon etc. Sorry no access to my development environment. I will post the code tomorrow.

Here is the the code I use to set up the markers.

nodes.forEach(function (node) {
    let index = 1
    mapMsg = {}
    mapMsg.payload = {}
    mapMsg.payload.name = node.properties.name
    while (marker_name_set.has(mapMsg.payload.name)) {
        mapMsg.payload.name = node.properties.name + `(${index})`
        index++;
    }
    marker_name_set.add(mapMsg.payload.name)
    address_to_marker_name_map.set(node.properties.mesh_address, mapMsg.payload.name)
    mapMsg.payload.lon = node.geometry.coordinates[0]
    mapMsg.payload.lat = node.geometry.coordinates[1]
    mapMsg.payload.id = node.properties.mesh_address
    mapMsg.payload.mesh_address = node.properties.mesh_address
    index = 1
    node.properties.node_inputs.forEach(function (input) {
        let sensor_name = findSensorMarkerName(input)
        mapMsg.payload[`sensor${index}`] = sensor_name
        address_to_marker_name_map.set(node.properties.mesh_address + '/' + index, sensor_name)
        index++
    })
    mapMsg.payload.layer = "Nodes"
    mapMsg.payload.icon = "fa-upload"
    mapMsg.payload.iconColor = "#ff0000"
    mapMsg.payload.type = "Node"
    messages.push(mapMsg)
})

All the different types of marker are set up similarly. This works fine.

They should always have name, lat, lon as per the sidebar info - and icon if you want to set iconColor. Anything else is undefined behaviour.

Crikey,

That was quick. How many hours a day do you monitor this forum :-).
I will stash the lat lon somewhere and try again. I was hoping to get away without that. Ah well.

Thanks.

about 18-20 :slight_smile:
you "may" be able to get away with it as it is undefined - but obviously you aren't lucky so far.. - it may be lat, lon or may be icon that is needed.

They say the older you get the less sleep you need. If think the less sleep you get is more accurate! I am 67 years old and still writing code. You may wonder why. When I started computers had doors on the side that you could open and walk into them(the computer not the doors, though it might be true now)! I also had long hair and a kaftan.

1 Like

I tried with name, lon, lat, iconColor and the result is even stranger.

The first message to each of the two markers I am working on work as expected. Both markers go green. The next pair of messages try to change them to green again, one of the markers disappears and the other is replaced with a standard location marker (upside down teardrop) which is green.

I started looking at the code in worldmap/worldmap.js function setMarker. That is on complex piece of code! My plan is to sprinkle it with a load of logging and see what is happening.

Ok - so a simple test here seems to work

[{"id":"599aad2c.d08ab4","type":"worldmap","z":"847a21f.bae23e","name":"","lat":"","lon":"","zoom":"","layer":"","cluster":"","maxage":"1000","usermenu":"show","layers":"show","panit":"true","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"none","showgrid":"false","path":"/worldmap","x":620,"y":440,"wires":[]},{"id":"9596c8de.3427b8","type":"inject","z":"847a21f.bae23e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":400,"wires":[["20f2f708.bdb088"]]},{"id":"20f2f708.bdb088","type":"function","z":"847a21f.bae23e","name":"","func":"msg.payload = {\n    name:\"Dave\",\n    lat:51.05,\n    lon:-1.35,\n    icon:\"male\",\n    iconColor:\"green\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":400,"wires":[["599aad2c.d08ab4"]]},{"id":"df91bdfe.f206","type":"inject","z":"847a21f.bae23e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":440,"wires":[["26e0a469.e9232c"]]},{"id":"26e0a469.e9232c","type":"function","z":"847a21f.bae23e","name":"","func":"msg.payload = {\n    name:\"Dave\",\n    iconColor:\"blue\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":440,"wires":[["599aad2c.d08ab4"]]},{"id":"e4ba06b2.6af828","type":"inject","z":"847a21f.bae23e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":480,"wires":[["1067fedf.5fef41"]]},{"id":"1067fedf.5fef41","type":"function","z":"847a21f.bae23e","name":"","func":"msg.payload = {\n    name:\"Dave\",\n    iconColor:\"red\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":480,"wires":[["599aad2c.d08ab4"]]}]

so something else must be going on...

I worked round it by stashing the whole message I sent to initialise the marker, and replaying it with just the colour changed. That worked. So it looks like it is something to do with the content of the original message.

Nodes

name, lon, lat, icon, iconColor, layer

id, mesh_address, type

Sensors

name, lon, lat, icon, iconColor, layer

type, parent, alarm, sensor_type, digital_alarm_trigger, analog_alarm_low, analog_alarm_high, analog_alarm_invert

My guess for the culprit is layer. Unless there is a clash between my custom properties and inbuilt ones.

Seeing as how the name is supposed to be unique map wide. It would be nice to be able to update just changed fields.

Yes, can you share a few actual messages . capture from a debug node in parallel to the map node. Which ones aren't working ? Nodes or sensors ?

Aha - layer... you may be on to something... will investigate later.

Quick answer is both. But in slightly different ways.

Unfortunately I seem to have deleted the test flow. I will try to get something later on today. Tip run to do first!

Test flow that illustrates the problem and solution(leave in the layer).
However, if name is really unique map wide, then we should not need the layer as well to identify the correct marker.

[
    {
        "id": "6421bd06.4bfa94",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "fb3dee28.dbbf48",
        "type": "ui_worldmap",
        "z": "6421bd06.4bfa94",
        "group": "c74dae99.7942b",
        "order": 0,
        "width": 0,
        "height": 0,
        "name": "Map",
        "lat": "52",
        "lon": "0",
        "zoom": "",
        "layer": "OSM",
        "cluster": "",
        "maxage": "",
        "usermenu": "show",
        "layers": "show",
        "panit": "false",
        "panlock": "false",
        "zoomlock": "false",
        "hiderightclick": "true",
        "coords": "dms",
        "showgrid": "false",
        "allowFileDrop": "false",
        "path": "/worldmap",
        "x": 490,
        "y": 600,
        "wires": []
    },
    {
        "id": "ec3d0708.a89b58",
        "type": "inject",
        "z": "6421bd06.4bfa94",
        "name": "inject_red",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"name\":\"Fred\",\"lon\":0,\"lat\":52,\"layer\":\"Nodes\",\"icon\":\"fa-upload\",\"iconColor\":\"#ff0000\"}",
        "payloadType": "json",
        "x": 160,
        "y": 520,
        "wires": [
            [
                "fb3dee28.dbbf48"
            ]
        ]
    },
    {
        "id": "ff3fd11.74e18b",
        "type": "inject",
        "z": "6421bd06.4bfa94",
        "name": "inject_green_bad",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"name\":\"Fred\",\"icon\":\"fa-upload\",\"iconColor\":\"#00ff00\"}",
        "payloadType": "json",
        "x": 160,
        "y": 620,
        "wires": [
            [
                "fb3dee28.dbbf48"
            ]
        ]
    },
    {
        "id": "b2bfdecb.adc95",
        "type": "inject",
        "z": "6421bd06.4bfa94",
        "name": "inject_green_good",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"name\":\"Fred\",\"layer\":\"Nodes\",\"icon\":\"fa-upload\",\"iconColor\":\"#00ff00\"}",
        "payloadType": "json",
        "x": 170,
        "y": 720,
        "wires": [
            [
                "fb3dee28.dbbf48"
            ]
        ]
    },
    {
        "id": "c74dae99.7942b",
        "type": "ui_group",
        "name": "Default",
        "tab": "941db6a3.d75318",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "941db6a3.d75318",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

Hi - I think I have now fixed in v2.13.3 - the layer was the culprit.

That has done the trick. Just sending name and colour works fine.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.