Perspective (leaflet)map scripting

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 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).

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:

	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
1 Like

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.

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

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.

1 Like