Perspective polling resetting views with popups

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?

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:

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.

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.

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)

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 :slight_smile: Also, super sorry this response took so long to get back. I've attached the two scripts in this reply.

	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
def runAction(self, event):
	indToToggle = event["name"]
	self.props.layers.ui.popup[indToToggle].enabled^=True