How to fix the locations in worldmap

#1

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.

0 Likes

#2

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

#3

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.

0 Likes

#4

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"]]}]
2 Likes

#5

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

0 Likes

#6

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.

0 Likes

#7

And the injection only once. not repeatedly

0 Likes

#8

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.

0 Likes

#9

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

0 Likes

#10

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"?

0 Likes

#11

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.

0 Likes

#12

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.

0 Likes

#13

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

0 Likes

#14

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?

0 Likes

#15

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

0 Likes