Select to view content in your preferred language

Singleton for Global Variables & Methods

175
0
a month ago
Glyphmo
New Contributor

Greetings!

I'm currently using ESRI's Experience Builder v1.11. My Widget provides a visual list of all the items retrieved from the selected map layer. Each item of said list has it's own class that handles the OnClickListener. Once you select an item from the list, the map zooms to it.

My problem is, the data from my map automatically updates itself a few times per minute, which offcenters the selected item unless selected again. To account for this, I'd like to have the map automatically zoom to it whenever the data refreshes.

As a baseline, I thought a singleton (a class only instantiable once) to manage the automatic map zooming would be the ideal solution, as I want all list items to point and talk to this same singleton class.

So, I created a singleton class, but my list's items seem to each create their own instance of my singleton instead of speaking to the same single instance of that class. That means I'm unable to share variables and method states between them. Being new to this, I had help from the base "List" Widget, so a good part of this code I mentioned is not mine. Is there any better way to do this?

 

Thank you a lot for any input in advance!

0 Replies