Problem Showing/Hiding DynamicObjects on globe startup

Hi there,

I am working on a program that uses a DynamicObjectCollection to represent country border lines and state border lines. These are represented by vectors which I populate the DynamicObjectCollection with. One of the things that users can do is specify whether they want these borders to appear when the globe starts up. The problem I am having is that sometimes the boarders will load even though the user has requested them not to show.

The way this system works is I keep track of which Objects in the collection belong to a certain set of borders. When the user selects to load the globe (it is not turned on by default), it initially loads in all of the Objects into the collection, then the program goes through and looks for any borders that the user switched off, clears the DynamicObjectCollection and then redraws it, omitting the borders that the user unchecked (not the most efficient method, but it's the best we could come up with given the way the entire project is set up). The problem I am having is that the DynamicObjectCollection is that the behavior is neither expected, nor predictable. If I uncheck one of the border options then it is random if that border appears or not. If I uncheck both, then I might see any combination of borders. Any ideas why this might be happening, and what could fix it?

Thanks in advance!
-Donald

Fixed the issue. For anybody that is curious/also has this problem, the issue was that I would check to see if a collection was visible before calling Cesium.loadJson().then() instead of putting this if statement inside of the then() function