# How to Add marker over script in map component in perspective

**URL:** <https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [April 12, 2022, 11:28am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350 "2022-04-12T11:28:44Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [April 12, 2022, 11:28am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/1 "2022-04-12T11:28:44Z")

</div>

Hi,  
can anyone know about how to add a marker in map component in perspective over script  
Thanks in advance,  
Sri

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 12, 2022, 11:49am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/2 "2022-04-12T11:49:03Z")

</div>

Hi,  
I add markers this way:

```auto
markers = []
#Tooltip
TooltipOrientation = 'auto' #top,bottom etc
TooltipView = {'params':{},'path':'path_to_tooltip_view'}#params which are defined on the path_to_tooltip_view. If You have some, so the code have to be: 'params':{'first_param':value_of_the_first_param,'second_param':value_of_the_second_param}
tooltip = {'enabled':True,'content':{'text':'Tooltip Tittle','view':TooltipView},'direction':TooltipOrientation,'permanent':False,'sticky':False,'opacity':1}
#Marker PopUp
MarkerView = {'params':{},'path':'path_to_marker_view'}#params which are defined on the path_to_marker_view
content = {'text':'PopUp text','view':MarkerView}
pan = {'auto':True}
width = {'max':300,'min':50}
height = {'max':300}
IconClasses = {'classes':''}
icon = {'path':'material/place','color':'(0,0,0)','size':{'width':30,'height':30},'style':IconClasses}
popup = {'enabled':False,'content':content,'pan':pan,'closeButton':False,'autoclose':False,'closeOnEscapeKey':False,'closeOnClick':True,'width':width,'height':height}
#Marker
markers.append({'popup':popup,'name':'New Marker','lat':float(59.252521),'lng':float(24.020222),'opacity':1,'icon':icon,'tooltip':tooltip})
self.getSibling("Map").props.layers.ui.marker = markers

```

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [April 13, 2022, 3:44am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/3 "2022-04-13T03:44:28Z")

</div>

Thanks Iscrac, for your response  
I tried this script as same in a button pressed state it showing like Global name error sorry for the noob question what does popup means,  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/9/29505bc67f350fae4a4da44a9b579ad0db67393e.png)

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 13, 2022, 5:17am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/4 "2022-04-13T05:17:09Z")

</div>

I edited my code above, so try one more time please. There was a little mistake)

and… as a result You will get nothing until You put these markers to Your map element

Do You know how to do it?

Here’s the screenshots:  
Graphic Display

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

Objects’ Structure in **Project Browser** :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/9/79f7f513dd332708b8c944c73b8d0e04cfe71f54.png)

Location of Map’s markers in **Perspective Property Editor** :

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

Button **Event Script** (_onClick_)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/e/ae6c5ed114974fe9e86ad26c18785b9d6295ee82.png)

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [April 13, 2022, 5:41am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/5 "2022-04-13T05:41:44Z")

</div>

Thanks Iscrac That was a great guidance  
it worked fine  
once again thanks  
Warm Regards,  
Sri

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 13, 2022, 5:45am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/6 "2022-04-13T05:45:09Z")

</div>

> [@Sri\_Haran](#):
>
> Thanks Iscrac That was a great guidance

You are welcome! 😊

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [April 13, 2022, 10:28am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/7 "2022-04-13T10:28:01Z")

</div>

Hi Israc  
i already have 7 markers which i have added manually when i used this script it is overwriting them and only one marker is showing how can i overcome it?  
the below pictures shows that how my ui markers changed from and to  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/b/3b6485fbc39c53f39fc83129794e99406f89ef32.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/30e21bffa3aaafea4234a31f9ae1d48f11d09df3.png)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [April 13, 2022, 10:33am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/8 "2022-04-13T10:33:11Z")

</div>

Probably by setting this to the markers you already have

> [@iscrac](#):
>
> `markers = []`

`markers = self.getSibling("Map").props.layers.ui.marker`

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 14, 2022, 8:35am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/9 "2022-04-14T08:35:04Z")

</div>

> [@victordcq](#):
>
> markers = self.getSibling("Map").props.layers.ui.marker

for sure) thanx)  
but when I use loops, so I use temporary variable **markers = []**, and then I send them to map

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [April 14, 2022, 8:58am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/10 "2022-04-14T08:58:19Z")

</div>

array.extend(array) probaly should work too  
`self.getSibling("Map").props.layers.ui.marker.extend(markers)`

i dont think this is a good idea tho, as it might keep appending more and more…  
idk the usecase, maybe thats what you want…  
but i would defining your custom markers in a custom prop and then add them both up into the property

view prop with the predefined static markers  
`view.custom.staticMarkers = [...]`  
and then in the script  
`self.getSibling("Map").props.layers.ui.marker = view.custom.staticMarkers + markers`

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 14, 2022, 9:54am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/11 "2022-04-14T09:54:51Z")

</div>

> [@victordcq](#):
>
> i dont think this is a good idea tho,

He asked how to add markers via script  
He did't specify what he wants to get in the end as a Result.  
There's no exact task)

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [April 14, 2022, 10:02am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/12 "2022-04-14T10:02:55Z")

</div>

> [@victordcq](#):
>
> idk the usecase, maybe thats what you want…  
> but i would...

Thats why it was a suggestion 🙂

> [@Sri\_Haran](#):
>
> i already have 7 markers which i have added manually when i used this script it is overwriting them and only one marker is showing how can i overcome it?

**i would** define the 7 markers somewhere else and then combine them like so  
`self.getSibling("Map").props.layers.ui.marker = view.custom.staticMarkers + markers`

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [April 14, 2022, 10:08am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/13 "2022-04-14T10:08:53Z")

</div>

> [@victordcq](#):
>
> **i would** define the 7 markers somewhere else and then combine them like so

I get it now. sorry for misunderstanding from my side

---

<div class="post-metadata">

**Author:** ![Sri\_Haran](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@Sri\_Haran](https://forum.inductiveautomation.com/u/Sri_Haran)\
**Post date:** [April 22, 2022, 7:58am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/14 "2022-04-22T07:58:46Z")

</div>

Hi Iscrac,  
can i know how to delete those added markers over script  
Regards,  
Sri Haran

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [April 22, 2022, 8:46am UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/15 "2022-04-22T08:46:56Z")

</div>

Yeah thats why i said its best to split them up so you know which were added xd

---

<div class="post-metadata">

**Author:** ![ignitionSL](https://avatars.discourse-cdn.com/v4/letter/i/9e8a1a/32.png) [@ignitionSL](https://forum.inductiveautomation.com/u/ignitionSL)\
**Post date:** [October 15, 2023, 11:51pm UTC](https://forum.inductiveautomation.com/t/how-to-add-marker-over-script-in-map-component-in-perspective/58350/16 "2023-10-15T23:51:40Z")

</div>

Thank you for the script.  
I updated the locations from the database. When I add more locations to DB, the same mark is being updated with the new location. how do we keep the previous marker and create a new marker with the new location?
