dceejay / RedMap

A web map app for Node-RED to put blobs on
Apache License 2.0
110 stars 60 forks source link

Bug: Improper handling of 'layer' #292

Open phreed opened 1 month ago

phreed commented 1 month ago

In node-red-contrib-web-worldmap/worldmap.js :

https://github.com/dceejay/RedMap/blob/7d1782cc8b89537740921eb2c81123356c0d3a6d/worldmap.js#L354-L356

This gives me an error: TypeError: Cannot read properties of null (reading 'indexOf') The following change stopped the error.

   if ((node.events.indexOf("layer")!==-1) && (message.action === "layer") )  {
       setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
   }

Does 'message.action.indexOf(...)' make sense?

zafrirron commented 1 month ago

Can you give some more details about this error, how can I reproduce it? the reason for the message.action.indexOf("layer") is to capture addlayerand dellayer actions to be send back to backend

phreed commented 1 month ago

I can try to reproduce the error. It happened on initial load, possibly following the introduction of https://github.com/FreeTAKTeam/FreeTAKHub-Webmap/blob/main/freetakhub_webmap_v5.json by https://github.com/FreeTAKTeam/FreeTAKHub-Installation/tree/120-update-nodered-to-31.

I suspect it is related to the introduction of the following menu:

    {
        "id": "70c9a88a608c375e",
        "type": "function",
        "z": "2c12da721d40c6cc",
        "name": "Add The Menu",
        "func": "msg.payload = { \n  command: {\ncontextmenu: String.raw`\n<table border=0><tr>\n<th>Attitude</th><td><select id=\"myatt\">\n  <option value=\"friend\">Friend</option>\n  <option value=\"hostile\">Hostile</option>\n  <option value=\"neutral\">Neutral</option>\n  <option value=\"unknown\">Unknown</option>\n  <option value=\"pending\">Pending</option>\n  <option value=\"suspect\">Suspect</option>\n  <option value=\"assumed\">Assumed Friend</option>\n  </select></td>\n</tr><tr>\n<th>Type</th><td><select id=\"mytyp\" value=\"Ground\" onchange=\"document.getElementById('mynam').value = this.value+'-'+parseInt(Math.random()*9999);\">\n  <option value=\"Ground\">Ground</option>\n  <option value=\"Gnd Equip Vehicle\">Gnd Equip Vehicle</option>\n  <option value=\"Gnd Combat Infantry Rifleman\">Rifleman</option>\n  <option value=\"Gnd Combat Infantry grenadier\">Grenadier</option>\n  <option value=\"Gnd Combat Infantry Mortar\">Mortar</option>\n  <option value=\"Gnd Combat Infantry MachineGunner (LMG)\">LMG</option>\n  <option value=\"Gnd Combat Infantry Medic\">Medic</option>\n  <option value=\"Gnd Combat Infantry anti Tank\">anti Tank</option>\n  <option value=\"Gnd Combat Infantry Sniper\">Sniper</option>\n  <option value=\"Gnd Combat Infantry Recon\">Recon</option>\n  <option value=\"Gnd Combat Infantry air defense\">AA</option>\n  <option value=\"Gnd Combat Infantry Engineer\">Engineer</option>\n</select></td>\n</tr><tr>\n<th>Timeout</th>\n<td><input type=\"number\" id=\"mytout\" step=\"10\" value=\"600\">S</td>\n</tr><tr>\n<th>Name</th><td><input type=\"text\" id=\"mynam\"></td>\n</tr><tr>\n<th>\n  <input name=\"my_spot_report\"\n    type=\"button\" value=\"Send\"\n    onclick=\n'feedback(\"map\", {\n    \"attitude\":document.getElementById(\"myatt\").value,\n    \"geoObject\":document.getElementById(\"mytyp\").value,\n    \"timeout\":document.getElementById(\"mytout\").value,\n    \"name\":document.getElementById(\"mynam\").value,\n    \"bearing\": 0.0,\n    \"distance\": 1.0,\n    \"how\": \"nonCoT\",\n},\"feedback\",true)'\n></th>\n</tr></table>\n`\n}\n}\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 540,
        "y": 340,
        "wires": [
            [
                "68d5546bc74741de"
            ]
        ]
    },

However, I have not verified that this is the cause. I should be able to get back to it next week.