# Perspective (leaflet)map scripting

**URL:** <https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434>\
**Category:** Ignition Early Access\
**Tags:** scripting\
**Created:** [July 10, 2019, 12:53pm UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434 "2019-07-10T12:53:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedde](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@fedde](https://forum.inductiveautomation.com/u/fedde)\
**Post date:** [July 10, 2019, 12:53pm UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434/1 "2019-07-10T12:53:38Z")

</div>

I have a lot of trouble finding information about scripting in the perspective map, for instance I want to create markers onMapClick. If I manually create empty markers I can change the properties like name, lat and lng but I have no clue how to create new markers or get the lat/lng from the clicked location. I found some functions on [leafletjs.com](http://leafletjs.com) but I don’t know how to use them in Ignition.

I hope you can provide me with some more information and possibly update the user manual.([https://docs.inductiveautomation.com/display/DOC80/Perspective+-+Map](https://docs.inductiveautomation.com/display/DOC80/Perspective+-+Map)).

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [July 11, 2019, 5:32pm UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434/2 "2019-07-11T17:32:57Z")

</div>

If you are already able to make empty markers and change name/properties of it, then it sounds like it’s just a simple addition of adding these new markers with the right properties to the list of existing markers. What you can do is get a list of the current markers, and add your new marker to the list and set that list back to the property in the map that holds the markers.  
As a _very_ simple example:

```auto
	markers = self.props.layers.ui.marker.tolist()
	newMarker = {}
	newMarker['name'] = 'some unique name'
# Include the lat and lng variables provided in the onMapClick event
	newMarker['lat'] = event.lat
	newMarker['lng'] = event.lng
# ..add the rest of the markers properties here
	markers.append(newMarker)
	self.props.layers.ui.marker = markers

```

---

<div class="post-metadata">

**Author:** ![fedde](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@fedde](https://forum.inductiveautomation.com/u/fedde)\
**Post date:** [July 22, 2019, 9:11am UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434/3 "2019-07-22T09:11:46Z")

</div>

Thanks for the info and sorry for the late response. I was only able to manually create empty markers (not with scripting) and then edit them with scripting because I can’t find information about functions like tolist(). With this function I can now create the markers with scripting but I need to add the rest of the default marker properties to get them to work, for example:  
newMarker[‘icon’] = {‘color’:“red”}  
newMarker[‘popup’] = {‘enabled’:“false”}.  
I was wondering if there is a way to make an marker with all the default marker properties with scripting so all the default properties are assigned and I don’t have to assign them all individually every time I add a marker.

---

<div class="post-metadata">

**Author:** ![nader.chinichian](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nader.chinichian/32/9261_2.png) [@nader.chinichian](https://forum.inductiveautomation.com/u/nader.chinichian)\
**Post date:** [January 8, 2020, 8:12am UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434/4 "2020-01-08T08:12:56Z")

</div>

Hi  
I have the same issue but I get error when using tolist() method on return object.

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [January 8, 2020, 5:20pm UTC](https://forum.inductiveautomation.com/t/perspective-leaflet-map-scripting/26434/5 "2020-01-08T17:20:14Z")

</div>

If you are on version 8.0.5 or greater the .tolist() method is no longer needed and the script should work without that line. As a consequence of that however, there’s a bug with the resulting last line `self.props.layers.ui.marker = markers` that will replace the whole list with an empty list.

In order for the above script to work, remove `.tolist()` and remove the last line. It should then update appropriately.
