# Dynamic Map Markers

**URL:** <https://forum.inductiveautomation.com/t/dynamic-map-markers/97028>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 9, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028 "2024-10-09T15:29:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 3:29pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/1 "2024-10-09T15:29:19Z")

</div>

I don't want to add a new marker for every new site that comes online. So I reference each site in this loop and try to generate the JSON for the marker. The map throws a "t.map is not a function" error and all the JSON is out of order. I tried lots of methods and searching online but couldn't find any guides for a property like "marker" that has variable length (or I would have just used the expression binding).

Here's my code...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/d/fdaf02d21d3fe3a3af1a4572b1f447c928dc93de.png)  
[forum.txt](https://forum.inductiveautomation.com/uploads/short-url/tesSsxlZDF971mbxpNR5olhzi2F.txt) (1.0 KB)

Here's what the code returns in the property browser for a marker (there are 60+ markers)...

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

Here's the reference of what a regular marker looks like I'm aware some of my properties might not be done properly like the colors or "null" not sure if that causes the issue...

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d815b14aa80a2fceb2304278ced133eb7a374008.png)

Here's the error on the map...  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/c/acd0b2672a25139bb985484776412e3a02f8c43d.png)

I'm very new to the map component apologies if I'm missing something obvious.

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 9, 2024, 4:16pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/2 "2024-10-09T16:16:28Z")

</div>

I would start troubleshooting by just limiting your loop to a single marker for now to see if it's just a marker later in the loop causing issues, or if it will work with just 1. If it works with just 1, then increase your loop in increments until it gets the error as there may be one location that's breaking the entire component.

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 4:32pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/3 "2024-10-09T16:32:46Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/a/daecf0b3dba9deda3a568f8bfaf248e0cfa9a834.png)  
This is the error I'm not getting after reducing it to one marker. I have no idea how to change it from a object to an array using just ignitions scripting?

UPDATE:  
Used this post

> [@Converting remote asset UDTs into dynamic map markers](https://forum.inductiveautomation.com/t/converting-remote-asset-udts-into-dynamic-map-markers/62891/5):
>
> Hey Sam, Instead of using a dummy query, I would recommend switching to an expression structure binding. You can have many inputs to the binding and use a single script transform. To make it poll, make one of the inputs a now(x) where x is the time, in milliseconds you want the poll rate to be

to make a list and append to it the dictionary and now I'm closer I think but I get a "Cannot read properties of undefined (reading 'content')"

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/2/026507417ee8433b61ed717903f7989cfd8fc3e3.jpeg)

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 9, 2024, 4:42pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/4 "2024-10-09T16:42:17Z")

</div>

~~On your return change it to this and see if that fixes it:~~

```python
return [newDict]

```

Edit: I see what you're doing now. You need to define newDict before your loop as an empty array

```python
newDict = []

```

Then you can create a tempDict without the array designation you're trying to do with  
`newDict[str(count)] = {`  
to just be

```python
tempDict = {

```

then replace your counter increment with

```python
newDict.append(tempDict)

```

Then return it just as you currently are.

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 4:44pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/5 "2024-10-09T16:44:17Z")

</div>

Yea I tried that and still getting the "cannot read contents error in the post above", I think I need to write the actual dicitonary different somehow.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [October 9, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/6 "2024-10-09T16:46:45Z")

</div>

You don't want to return a dictionary, you want to return a list of markers (which are dictionaries)

not sure what line you're declaring `newDict` but I think you're declaring it as `newDict = {}`

I would change it to `newList = []`  
Then on line 34, change that `newDict[str(count)] = <your marker dictionary>` to `newList.append(<your marker dictionary>)`

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [October 9, 2024, 4:46pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/7 "2024-10-09T16:46:54Z")

</div>

Just edited my response. Re-check that and see if that helps.

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 4:47pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/8 "2024-10-09T16:47:21Z")

</div>

Trying these rn I'll edit this when I'm done. Thanks!  
@michael.flagler @Matthew.gaitan  
Thanks so much the map isn't showing an error but the marker isn't showing up still sadly.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ce6ea069db512535eadfc87e5e515570fe42ae6d.jpeg)

Heres the new code

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

```
tempDict = {
'name': str("GS111111"),
'properties':{},
'enabled': True,
'lat': siteNameLatt,
'lng': siteNameLong,
'opacity': 1,
"icon":{"path": "material/location_on", "color": "#4190F7", 'rotate': 0, 'size':{'width':36,'height':36}, 'style':{}},
'event':{'stopPropagation':False},
'tooltip':{'content':{'text':'','view':{'path':'','params':{}}},'direction':'auto','permanent':False,'sticky':False,'opacity':1},
'popup':{'enabled':False,'content':{'text':'','view':{'path':'','params':{}}},'width':{'max':300,'min':50},'height':{'max':None},
'pan':{'auto':True},'closeButton':True,'autoClose':True,'closeOnEscapeKey':True,'closeOnClick':None}
}

newList.append(tempDict)
return newList

```

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 5:16pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/9 "2024-10-09T17:16:57Z")

</div>

Got the marker to show up by changing the 'null' fields to actual values as I'm not sure how to put an actual null value in. The marker shows up way at the wrong place however, its suppose dto be in texas, I know its the right coordinates bc i use the same values for the map default center and thats right. It does move when i change the lat and long in the code however its way off from where that actually is.

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

---

<div class="post-metadata">

**Author:** ![Randolph\_Sewell](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@Randolph\_Sewell](https://forum.inductiveautomation.com/u/Randolph_Sewell)\
**Post date:** [October 9, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/10 "2024-10-09T17:19:19Z")

</div>

Wait if I reverse latt and long variable in the code it's accurate?

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [October 9, 2024, 5:19pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/11 "2024-10-09T17:19:26Z")

</div>

Your Lat & Lng values are backwards

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 9, 2024, 5:20pm UTC](https://forum.inductiveautomation.com/t/dynamic-map-markers/97028/12 "2024-10-09T17:20:40Z")

</div>

![That ain't Texas](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/3/9390bc0f801d474ef257e95c5890e30bd8c155a4.png)
