Script used to change colour of a label on a different view depending on marker clicked on a map

So i have multiple markers on a map and the markers have a popup. On this popup screen i would like the status of the marker to be shown using a label. This label should turn red if the tag is offline and green if the tag is online.

I made a custom property called ‘Selected_tag_path_value’. That didnt work because it was not recognizing what tag was being selected at the same time as the status of that tag. The status value is either a 1 or 0 .

Just wondering if anyone could help with this.

I’m not sure I understand what your problem is. Are you wanting pass both the status and the tag path to the popup?

1 Like

To add to @daniel.snyder, you should pass the tagpath to the popup you’re opening
https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup

E.g.

system.perspective.openPopup('path', {'tagPath': 'path/to/tag'}) 

And then use a tag > indirect binding to read your status tag and hence colour your component

1 Like

So I have a view with a table on it that returns the data of a specific tag depending on what marker is clicked.
I then have a status label on the same view that I want to change colour depending on what the status of the marker that I have clicked is.

So that popup is made my configuring events on the map and writing a script like this

marker = next(m for m in self.props.layers.ui.marker if m['name'] == event.name)
self.session.custom.selected_tag_path = marker['tagpath']

But what I want is for the label to instead of showing data, I want it to show a colour depending on whether the tag is online or offline for the same tag thats data is being displayed on the table.

I hope this makes more sense.

On the view that you are using as a popup, create 2 parameters: tagPath and markerStatus (or however you want to name them). Then in the event that fires when the marker is clicked, open the popup and pass those parameters to it (just like in @nminchin example above). In the popup, bind the table data to the parameter rather than the session prop, and bind the label color to the status parameter.

You don't need your for loop, the onMarkerClick event contains all the props associated with your markers already.

image

This is what the event variable contains:

{
  "name": "Bob",
  "properties": {
    "tagPath": "path/to/tag"
  },
  "lat": 38.67123766735303,
  "lng": -121.16958349943162
}

So you're already passing in the tag path to the tag into the popup and it looks like you've already bound the label.props.text to an indirect tag binding using the view.params.tagPath (or whatever you've called it), you just need to also bind the label.props.style.backgroundColor to the label.props.text property and use a map transform with your colours in it.
image

If I were doing this, I would use style classes for the colour so that I can define the colours globally to use everywhere instead of using magic colours that are horrible to maintain and incredibly time-consuming