How to fix the locations in worldmap

Hello,

I have marked several locations in worldmap by injecting and simple function containing properties like lon,lat,icon etc. I defined those objects as global variables since I wanna change their color with external decisions later on. Also I was able to add that map to dashboard.

Where I face hard for me to solve is to keep those locations fix through out the project. Now when i refresh the worldmap or the dashboard all the locations get lost. I have to re-inject them again.

Instead of injecting what is the best method to mark the locations in worldmap which will last through out the project ? Kindly help me.

Thank you.

the worldmap in node provides events when client connect, disconnect, click on markers etc... The connect event can be used to trigger your flow to resend markers to set them up as you wish.

2 Likes

Hi ,

I'm sorry this is not clear. What I used was the worldmap node only.

thank you for introducing the woirldmap in node which I have forgotten. I will try it.

Mixing this with your other thread... I would use something like this - to feed the worldmap node.

[{"id":"94d4bb1f.9ba388","type":"function","z":"8eaef9ed.138468","name":"Add SS1","func":"var SS1  =  {\n    name:\"SS1 : Kurunegala\", \n    lat:7.486944, \n    lon:80.365045,\n    icon:\"tag\",\n    iconColor:\"dark\",\n    extrainfo:\"Hello ! this is station 1\"\n};\nmsg.payload = SS1;\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":360,"wires":[["b3b8baae.2865a8","ff59e95a.55d8e8"]]},{"id":"11aa64ec.18e4bb","type":"worldmap in","z":"8eaef9ed.138468","name":"","path":"/worldmap","x":100,"y":360,"wires":[["1c0dc03c.c30ec"]]},{"id":"1c0dc03c.c30ec","type":"switch","z":"8eaef9ed.138468","name":"","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"connected","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":250,"y":360,"wires":[["94d4bb1f.9ba388"]]}]
3 Likes

Well...I got it. :smiley:
I learnt another new thing. Thank you very much again :relaxed:

image

Doing like this?But this is when i fixed the location myself. What if the location is provided by other user? in which the location is changing.

And the injection only once. not repeatedly

not sure what you mean ? if you send a new msg with the same name but new lat and lon it will update the position.

image
previously im using this, but the marker will be gone after i refresh the map

image
This is the solution that you have provided right? so that the marker will not be gone after refresh.
But how to use this flow? do i need to add anything after the function "Add SS1"?

I have no idea what you are trying to do - so maybe yes - maybe no - certainly it will probably need to go to a worldmap out node.

The idea is to look at what worldmap-in returns. If msg.payload.action is 'connected' send what you want to show on the map to the worldmap node.

This will cause the information to display whenyou first open the map and when someone refreshes the browser.

if im using the flow provided by you. Does that mean i can only insert the location using this function node?
image

My problem is that now i have 1 main nodered server. All the other node-red server can send the location data to my main nodered server through MQTT cloud. But I dont know what is the location, might be US, canada or somewhere else. Meaning im not able to determine their location. My main nodered server is mainly doing the monitoring of the worldmap. If anything happen, people from other country can send their location to me through MQTT cloud and a marker should appear at my worldmap. But the problem here is that whenever i refresh my worldmap...all the pop up, markers will be gone. How can i solve this problem?

How about storing the information in a database then replace that function node with a call to the database to read everything and then have a function node build all the info to display and then send it to the world map

so to retain the markers after a refresh or open the map, should i implement a switch node after my funtion and the to world map in? cos it doesnt work, after refresh i cant retain my points.

where and how to save your points is up to you. You can use the worldmap-in node to detect a new client connecting (or refreshing) and use that to trigger resending whatever points you like.

I've placed a worldmap in but nothing, what do you mean to detect a new client, should not be connected to the current flow?

The flow in question

The tracks node is not a store. It holds tracks per each marker sent - so needs the name of a marker in order to be added to the track (and thus trigger it to send out the track). The connect message is just a trigger - you still need to tell it which points to (re)plot.

Will i have to include inside the switch string? as per below

the whole function thats under the ttgo1 function??

For example what i asked is to retain the last position of that car marker after a new user open his browser

What i get instead is when refreshing in debug
08/06/2020, 20:18:43[node: ttgo1]function : (error)

"TypeError: Cannot read property 'latitude' of undefined"
What property and where should i edit for this?
Thanks in advance