# Worldmap setting icon colour twice makes markers disappear

**URL:** <https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334>\
**Category:** Dashboard\
**Created:** [17 April 2021 21:29 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334 "2021-04-17T21:29:19Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [17 April 2021 21:29 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/1 "2021-04-17T21:29:20Z")

</div>

I am changing the the iconcolor of markers to indicate status changes, using this bit of javascript.

```auto
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [17 April 2021 21:42 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/2 "2021-04-17T21:42:12Z")

</div>

where are you setting the lat and lon and icon ?

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [17 April 2021 22:39 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/3 "2021-04-17T22:39:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [18 April 2021 07:29 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/4 "2021-04-18T07:29:32Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [18 April 2021 07:30 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/5 "2021-04-18T07:30:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [18 April 2021 07:36 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/6 "2021-04-18T07:36:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [18 April 2021 07:58 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/7 "2021-04-18T07:58:54Z")

</div>

about 18-20 🙂  
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.

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [18 April 2021 08:24 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/8 "2021-04-18T08:24:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [18 April 2021 16:44 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/9 "2021-04-18T16:44:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [19 April 2021 21:32 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/10 "2021-04-19T21:32:15Z")

</div>

Ok - so a simple test here seems to work

```auto
[{"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...

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [20 April 2021 06:32 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/11 "2021-04-20T06:32:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 April 2021 06:38 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/12 "2021-04-20T06:38:44Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 April 2021 07:06 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/13 "2021-04-20T07:06:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [20 April 2021 08:09 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/14 "2021-04-20T08:09:01Z")

</div>

Quick answer is both. But in slightly different ways.

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [20 April 2021 08:11 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/15 "2021-04-20T08:11:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [20 April 2021 12:46 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/16 "2021-04-20T12:46:35Z")

</div>

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.

```auto
[
    {
        "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
    }
]

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 April 2021 14:11 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/17 "2021-04-20T14:11:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rogerjames99](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rogerjames99/32/25201_2.png) [@rogerjames99](https://discourse.nodered.org/u/rogerjames99)\
**Post date:** [20 April 2021 17:47 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/18 "2021-04-20T17:47:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 May 2021 17:47 UTC](https://discourse.nodered.org/t/worldmap-setting-icon-colour-twice-makes-markers-disappear/44334/19 "2021-05-04T17:47:42Z")

</div>

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