Worldmap Input Arguments node-red-contrib-web-worldmap 2.27.1

Hi!

I have a question. I currently am logging my GPS data to a .txt file in this format:

{"name":"8XEhx", "lat":40505, "lon":16, "time":"16:33:45"}
{"name":"6YgrX", "lat":40505, "lon":11296, "time":"16:33:45"}
{"name":"Ihg8J", "lat":5, "lon":196, "time":"16:33:46"}
{"name":"WvFme", "lat":430505, "lon":16, "time":"16:33:46"}
{"name":"Hn8TA", "lat":40505, "lon":161667, "time":"16:33:47"}
{"name":"ieLH7", "lat":40505, "lon":192961667, "time":"16:33:47"}

Now I would like to have a function to show those Points on a map.
Somehow it doesnt work properly.

What I thought is, that if you want to put points to a map you have to have something like this:

msg.payload = [
{"name":"8XEhx", lat:45, lon:19296},
{"name":"6YgrX", lat:8.130505, lon:1296},
{"name":"Ihg8J", lat:0505, lon:19296},
{"name":"WvFme", lat:0505, lon:1296},
{"name":"Hn8TA", lat:4505, lon:167},
{"name":"ieLH7", lat:48505, lon:11667}]
return msg;

Note that those are not my actual coordinates in the example.
this is my flow:

[
    {
        "id": "1874e22aa1362f24",
        "type": "ui_button",
        "z": "b423c3276f31428e",
        "name": "",
        "group": "160e81fb.f1c86e",
        "order": 9,
        "width": 2,
        "height": 1,
        "passthru": false,
        "label": "Plot",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "show_chart",
        "payload": "",
        "payloadType": "str",
        "topic": "",
        "topicType": "str",
        "x": 90,
        "y": 1300,
        "wires": [
            [
                "382bea699b9b89f9"
            ]
        ]
    },
    {
        "id": "382bea699b9b89f9",
        "type": "function",
        "z": "b423c3276f31428e",
        "name": "Get filename",
        "func": "// Get the filename from the flow context\nlet filename = flow.get(\"fileselected\");\n\n// check, if the filename is undefined that means it does not exist yet, nothing is selected yet\n// return: do not output anything\nif (filename===undefined) {\n    return;\n}\n\n// return the filename to the file-in node to delete\nmsg.filename = filename;\n\nif (msg.filename.replace(/^.*(\\\\|\\/|\\:)/, '')[0]!==\".\") {\n    // Only do this if this is a file, we don't delete folders\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 1300,
        "wires": [
            [
                "02f194100e923b62"
            ]
        ]
    },
    {
        "id": "02f194100e923b62",
        "type": "file in",
        "z": "b423c3276f31428e",
        "name": "",
        "filename": "",
        "format": "utf8",
        "chunk": false,
        "sendError": false,
        "encoding": "none",
        "allProps": false,
        "x": 440,
        "y": 1300,
        "wires": [
            [
                "491e65281f27f4d8"
            ]
        ]
    },
    {
        "id": "d701d7d889e4b605",
        "type": "debug",
        "z": "b423c3276f31428e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 630,
        "y": 1220,
        "wires": []
    },
    {
        "id": "3113ccc41272a67f",
        "type": "function",
        "z": "b423c3276f31428e",
        "name": "Format data for chart",
        "func": "var lines = msg.payload.split(\"\\n\");\n\nvar list_points = []\n\nvar arrayLength = lines.length;\nfor (var i = 0; i < arrayLength; i++) {\n\tline = JSON.parse(lines[i])\n\t\n\tout = line.split(\",\");\n    name_value = out[0].substring(9,14)\n    lat_value = out[1].substring(7,17)\n    lon_value = out[2].substring(6,14)\n\n\nvar dict_point = {\n  name: name_value,\n  lat: lat_value,\n  lon: lon_value,\n  icon : \":diamonds:\",\n\n};\nlist_points.push(dict_point)\n}\n\nmsg.payload = list_points;\n\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 1300,
        "wires": [
            [
                "a6bd82958e8706b1",
                "e5671c6fbb83163d"
            ]
        ]
    },
    {
        "id": "a6bd82958e8706b1",
        "type": "ui_worldmap",
        "z": "b423c3276f31428e",
        "group": "160e81fb.f1c86e",
        "order": 10,
        "width": 18,
        "height": 9,
        "name": "",
        "lat": "",
        "lon": "",
        "zoom": "18",
        "layer": "OSMC",
        "cluster": "17",
        "maxage": "",
        "usermenu": "show",
        "layers": "hide",
        "panit": "true",
        "panlock": "false",
        "zoomlock": "false",
        "hiderightclick": "false",
        "coords": "deg",
        "showgrid": "true",
        "allowFileDrop": "false",
        "path": "/worldmap3",
        "overlist": "DR,CO,RA,DN,HM",
        "maplist": "OSMG,OSMC,EsriC,EsriS,EsriT,EsriO,EsriDG,NatGeo,UKOS,OpTop,SW",
        "mapname": "",
        "mapurl": "",
        "mapopt": "",
        "mapwms": false,
        "x": 950,
        "y": 1300,
        "wires": []
    },
    {
        "id": "e5671c6fbb83163d",
        "type": "debug",
        "z": "b423c3276f31428e",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 870,
        "y": 1220,
        "wires": []
    },
    {
        "id": "491e65281f27f4d8",
        "type": "json",
        "z": "b423c3276f31428e",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 570,
        "y": 1380,
        "wires": [
            [
                "3113ccc41272a67f",
                "d701d7d889e4b605"
            ]
        ]
    },
    {
        "id": "160e81fb.f1c86e",
        "type": "ui_group",
        "name": "Download / Plot",
        "tab": "b63d1f91.68095",
        "order": 1,
        "disp": true,
        "width": "18",
        "collapse": false,
        "className": ""
    },
    {
        "id": "b63d1f91.68095",
        "type": "ui_tab",
        "name": "File Download",
        "icon": "fa-download",
        "order": 4,
        "disabled": false,
        "hidden": false
    }
]

Maybe my function is not correct or I am thinking the wrong way.

Another question would be, if there is a maximum for input arguments for the worldmap?

Thanks in advance!!

You can not pass the file text through a json node as it is not valid json.

Here is the low code option to get your world map object

[{"id":"25294b3a.49abf4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":240,"wires":[["f67d8d4e.c54438"]]},{"id":"f67d8d4e.c54438","type":"template","z":"bf9e1e33.030598","name":"simulate read file","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"name\":\"8XEhx\", \"lat\":40505, \"lon\":16, \"time\":\"16:33:45\"}\n{\"name\":\"6YgrX\", \"lat\":40505, \"lon\":11296, \"time\":\"16:33:45\"}\n{\"name\":\"Ihg8J\", \"lat\":5, \"lon\":196, \"time\":\"16:33:46\"}\n{\"name\":\"WvFme\", \"lat\":430505, \"lon\":16, \"time\":\"16:33:46\"}\n{\"name\":\"Hn8TA\", \"lat\":40505, \"lon\":161667, \"time\":\"16:33:47\"}","output":"str","x":400,"y":240,"wires":[["a660e2a4.ac75a"]]},{"id":"a660e2a4.ac75a","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":230,"y":300,"wires":[["97892549.7f8568"]]},{"id":"97892549.7f8568","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":300,"wires":[["5c30d5a3.8bc28c"]]},{"id":"5c30d5a3.8bc28c","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"[{{{payload}}}]","output":"str","x":490,"y":300,"wires":[["491e65281f27f4d8"]]},{"id":"491e65281f27f4d8","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":630,"y":300,"wires":[["d701d7d889e4b605"]]},{"id":"d701d7d889e4b605","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":300,"wires":[]}]

as i do not have your file i have simulated the read file.

Or if you wish to remove or add properties something like this

[{"id":"25294b3a.49abf4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":240,"wires":[["f67d8d4e.c54438"]]},{"id":"f67d8d4e.c54438","type":"template","z":"bf9e1e33.030598","name":"simulate read file","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"name\":\"8XEhx\", \"lat\":40505, \"lon\":16, \"time\":\"16:33:45\"}\n{\"name\":\"6YgrX\", \"lat\":40505, \"lon\":11296, \"time\":\"16:33:45\"}\n{\"name\":\"Ihg8J\", \"lat\":5, \"lon\":196, \"time\":\"16:33:46\"}\n{\"name\":\"WvFme\", \"lat\":430505, \"lon\":16, \"time\":\"16:33:46\"}\n{\"name\":\"Hn8TA\", \"lat\":40505, \"lon\":161667, \"time\":\"16:33:47\"}","output":"str","x":400,"y":240,"wires":[["a660e2a4.ac75a"]]},{"id":"a660e2a4.ac75a","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":230,"y":300,"wires":[["9bcfa087.ad65b"]]},{"id":"9bcfa087.ad65b","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":350,"y":300,"wires":[["85cb9482.6128f"]]},{"id":"85cb9482.6128f","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"delete","p":"payload.time","pt":"msg"},{"t":"set","p":"payload.icon","pt":"msg","to":":diamonds:","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[["97892549.7f8568"]]},{"id":"97892549.7f8568","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":300,"wires":[["d701d7d889e4b605"]]},{"id":"d701d7d889e4b605","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":300,"wires":[]}]

[edit] added icon property.

heyy great that works!! I am new to NR so I have to get to used to everything.

Now I tried to insert my txt file insted of the simulated file.
I added a debugging node after the function and json node.
The debugging after the function looks somethin like this ...."time":"16:33:47"},,]"
Do you have an Idea why this happens? because the debugging node after the json node says "unexpected token"

does your file have newlines at end. You need to show us as we do not have all info you have.
if so check the split part is not empty
eg.

[{"id":"25294b3a.49abf4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":240,"wires":[["f67d8d4e.c54438"]]},{"id":"f67d8d4e.c54438","type":"template","z":"bf9e1e33.030598","name":"simulate read file","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"name\":\"8XEhx\", \"lat\":40505, \"lon\":16, \"time\":\"16:33:45\"}\n{\"name\":\"6YgrX\", \"lat\":40505, \"lon\":11296, \"time\":\"16:33:45\"}\n{\"name\":\"Ihg8J\", \"lat\":5, \"lon\":196, \"time\":\"16:33:46\"}\n{\"name\":\"WvFme\", \"lat\":430505, \"lon\":16, \"time\":\"16:33:46\"}\n{\"name\":\"Hn8TA\", \"lat\":40505, \"lon\":161667, \"time\":\"16:33:47\"}\n","output":"str","x":400,"y":240,"wires":[["a660e2a4.ac75a"]]},{"id":"a660e2a4.ac75a","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":110,"y":300,"wires":[["f96721d.4a6a26"]]},{"id":"f96721d.4a6a26","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":240,"y":300,"wires":[["9bcfa087.ad65b"]]},{"id":"9bcfa087.ad65b","type":"json","z":"bf9e1e33.030598","name":"","property":"payload","action":"","pretty":false,"x":370,"y":300,"wires":[["85cb9482.6128f"]]},{"id":"85cb9482.6128f","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"delete","p":"payload.time","pt":"msg"},{"t":"set","p":"payload.icon","pt":"msg","to":":diamonds:","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":300,"wires":[["97892549.7f8568"]]},{"id":"97892549.7f8568","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":710,"y":300,"wires":[["d701d7d889e4b605"]]},{"id":"d701d7d889e4b605","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":300,"wires":[]}]

Yes the file ends with a new line... not sure but I think its because textfiles always end with a new line?

Okay so the change nodes debug looks fine.
The join nodes debug doesnt say anything.

[edit] I restarted node red and now it works!!

Thank you very very much for helping me!!! Learned a lot from it :slight_smile:

Do you know by any chance how many "markers" or points you can give the world map?
Let's say I would like to add a whole days log to the map. (new mark every second)

Thanks

Not sure but the limiting factor of a new marker every second would put a lot of workload on the browser, i would think. 3600 x 24 hr is a lot of points and most would be on top of each other. Maybe limit points to significant movements.

How much memory do you have, how big a processor, how long is a piece of string ?
(no idea - I suspect that is rather too many - and the display would be somewhat overcrowded if there are 86400 markers on the map at one time)

Hmm yeah well I think the file will be just too big... might add a field, where the user can select the timeframe, which then will be plotted

Thank you for your input

Do you really need every second ? could you ore-process the data to smooth/average/decimate it ?

I selected every second because gpsd sends it every second but it absolutely is a good idea to think about not getting every second

Often people do things like only send if the device moves more than x metres and/or some long time interval. So you get updates when it moves but just heartbeats if it stays still.

How do I do that? I guess with a filter node?

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