# Perspective polling resetting views with popups

**URL:** <https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [January 4, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231 "2023-01-04T19:40:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Bunch](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Brandon\_Bunch](https://forum.inductiveautomation.com/u/Brandon_Bunch)\
**Post date:** [January 4, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231/1 "2023-01-04T19:40:50Z")

</div>

Hey all, currently I have a map that is keeping track of some data and displaying a polygon. On click it shows a tooltip but the tool tip resets every time it polls for new data (15 seconds currently). Data is polled from the database and then scripted to create the new objects to populate the polygons. Is there a setting or something I'm missing to prevent this? If not, any advice or tricks to help me prevent this from happening?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 4, 2023, 8:02pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231/2 "2023-01-04T20:02:45Z")

</div>

I'm just making a guess here, but it sounds like you have a tooltip configured for a marker, and are constructing the markers based on some sort of query.

If that is indeed the case, then the tooltip exists as part of `props.layers.ui.marker[x].tooltip` If your binding exists on any of the objects in that chain and resolves, then it _replaces_ the old data with new data. In this event, the old tooltip would essentially be garbage-collected and removed from the UI - even if the data is the same as it was before the last polling event because the binding doesn't care about equality.

If you need data to be polled, but you don't expect it to change very often, I would instead set up a custom property to reflect what it is you want your markers to be, and place your binding on that custom property. Then, place a change script on that custom property along these lines:

```auto
if currentValue and currentValue.value != previousValue.value:
    self.props.layers.ui.marker = currentValue.value

```

The goal here is to have a custom property which updates with polling, but which only updates the `marker` object when the underlying value is different then it was at the last poll event.

---

<div class="post-metadata">

**Author:** ![Brandon\_Bunch](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Brandon\_Bunch](https://forum.inductiveautomation.com/u/Brandon_Bunch)\
**Post date:** [January 4, 2023, 8:15pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231/3 "2023-01-04T20:15:15Z")

</div>

Close, but I have the script bound to the props.vector.polygon so it is re-rendering the entire polygon property (because the array is dynamic and ranges from 0-sometimes hundreds depending on whats been happening on the sites). Those polygons then have a unique tooltip based on the data received from the DB. These polygons can be added at anytime and usually get removed in 4-24 hours depending on said data. That being said, I could probably use the self prop to get this working by checking against the values i receive and values currently set.

---

<div class="post-metadata">

**Author:** ![hventer23](https://avatars.discourse-cdn.com/v4/letter/h/bbce88/32.png) [@hventer23](https://forum.inductiveautomation.com/u/hventer23)\
**Post date:** [February 16, 2023, 3:00pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231/4 "2023-02-16T15:00:55Z")

</div>

Hi Brandon

How did you get/script the polygon to create a tooltip on click? As this is not a a property available for polygons (like markers)

---

<div class="post-metadata">

**Author:** ![Brandon\_Bunch](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Brandon\_Bunch](https://forum.inductiveautomation.com/u/Brandon_Bunch)\
**Post date:** [April 6, 2023, 7:14pm UTC](https://forum.inductiveautomation.com/t/perspective-polling-resetting-views-with-popups/68231/5 "2023-04-06T19:14:11Z")

</div>

Sorry, I might have created confusion. the polygons are drawn on the map and i use the tooltip with this script to add the popups when you click on the polygon. It takes the WKT for the polygon and just finds the centroid of it. I also use the "onVectorClick" with another script to trigger the appropriate popup 🙂 Also, super sorry this response took so long to get back. I've attached the two scripts in this reply.

```auto
	def centroid(vertexes):
		 _x_list = [vertex [0] for vertex in vertexes]
		 _y_list = [vertex [1] for vertex in vertexes]
		 _len = len(vertexes)
		 _x = sum(_x_list) / _len
		 _y = sum(_y_list) / _len
		 return(_x, _y)

	#	value = [[wkt][wkt]]
	parsedWkts=[]
	
	for row in value:  
		tooltipObject = {
			"enabled": False,
			"lat": None,
			"lng": None,
			"size": {
			  "width": 36,
			  "height": 36
			},
			"style": {
			  "classes": ""
			},
			"content": {
			  "text": "",
			  "view": {
				"path": "",
				"params": {}
			  }
			},
			"width": {
			  "max": 300,
			  "min": 50
			},
			"height": {
			  "max": None
			},
			"pan": {
			  "auto": True
			},
			"closeButton": True,
			"autoClose": False,
			"closeOnEscapeKey": True,
			"closeOnClick": True
	  	}

		polygon = row["field_wkt"].strip("MULTIPOLYGON()").split(",")
		t = ()
		for poly in polygon:
			split = poly.split(" ")
			tup = (float(split[0]),float(split[1])),
			t = t + tup
		
		cent = centroid(t)
		tooltipObject["lng"] = cent[0]
		tooltipObject["lat"] = cent[1]
		tooltipObject["content"]["text"] = "Field: " + row["field"]+" REI: " +str(row["HoursTillREIEnds"])+" hours remaining"
		parsedWkts.append(tooltipObject)
	
	return parsedWkts

```

```auto
def runAction(self, event):
	indToToggle = event["name"]
	self.props.layers.ui.popup[indToToggle].enabled^=True

```
