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

**URL:** <https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573>\
**Category:** Ignition\
**Created:** [July 6, 2022, 4:30pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573 "2022-07-06T16:30:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Conn\_Mccurdy](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Conn\_Mccurdy](https://forum.inductiveautomation.com/u/Conn_Mccurdy)\
**Post date:** [July 6, 2022, 4:30pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/1 "2022-07-06T16:30:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [July 6, 2022, 7:49pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/2 "2022-07-06T19:49:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 6, 2022, 8:21pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/3 "2022-07-06T20:21:16Z")

</div>

To add to @djs, you should pass the tagpath to the popup you’re opening  
[https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup](https://docs.inductiveautomation.com/display/DOC81/system.perspective.openPopup)

E.g.

```auto
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

---

<div class="post-metadata">

**Author:** ![Conn\_Mccurdy](https://avatars.discourse-cdn.com/v4/letter/c/e495f1/32.png) [@Conn\_Mccurdy](https://forum.inductiveautomation.com/u/Conn_Mccurdy)\
**Post date:** [July 7, 2022, 9:13am UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/4 "2022-07-07T09:13:20Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/1/0142ea27a37c234657b9d9b839ad00848fca6147.png)

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.

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [July 7, 2022, 12:40pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/5 "2022-07-07T12:40:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 7, 2022, 10:18pm UTC](https://forum.inductiveautomation.com/t/script-used-to-change-colour-of-a-label-on-a-different-view-depending-on-marker-clicked-on-a-map/61573/6 "2022-07-07T22:18:27Z")

</div>

> [@Conn\_Mccurdy](#):
>
> ```auto
> marker = next(m for m in self.props.layers.ui.marker if m['name'] == event.name)
> self.session.custom.selected_tag_path = marker['tagpath']
> 
> ```

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/778128f94ddd08dcfcab9f3d55186f696f32acae.png)

This is what the `event` variable contains:

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

```

> [@Conn\_Mccurdy](#):
>
> 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

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](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/3/630dff1adf1eff4e6b7f94d3965b395bd18ea039.png)

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
