CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.02k stars 3.51k forks source link

Showing/hiding a CZML data source stops working if the data is reloaded #12298

Closed javier-lopez-1s closed 1 week ago

javier-lopez-1s commented 2 weeks ago

What happened?

The entities in a CzmlDataSource can be shown/hidden without problems after being loaded for the first time. However, they can no longer be hidden if they are reloaded (with the same entity IDs). In fact, if a new data load includes entities with both previously loaded IDs and new IDs, the outcome is that the former can no longer be hidden while the latter can. CzmlDataSource's load() function calls entityCollection.removeAll(); internally. I believe the bug is in the function EntityCollection.removeAll(), specifically where the IDs of added and existing entities are checked, or a consequence of calling that function while the EntityCollection events are suspended. This was first observed on GeoJson data sources, reported in #12283, and closed as it was a duplicate of #2891. However, I believe it is worth creating a new issue given that the CZML data sources are also impacted, and the problem seems to be related to EntityCollection.

Reproduction steps

  1. Click the button "Load data".
  2. Click the button "Toggle visibility" a few times. It works as expected.
  3. Click the button "Load data" again.
  4. Click the button "Toggle visibility" a few times. The data source can no longer be hidden.

Sandcastle example

https://sandcastle.cesium.com/#c=3VXbjtowEP2VKU9BYk24absUULvs40qVyqpSRfbBcQxYODayHehuxb93nBAIl6q0+1IVIScez5wzM8d2mFbWAXtNJQxhGimAH34AEEkfolqiWZZy5aJaozArmnK/EOvve9uaGyu08uYWCXfmbeMMzC7oirfOoO5lxqGKt9JWuBxwFw7AqHF6buhqIdgDnxvObR+mN61Wl4QN6IZ+7IT+R8LnHcx290ToClIisB6frq0YCwJuBUXSaXcHdIBsQO8E/AAPkFLHjaDyCNBqKZKxltocmZHpgg3AzGOK1MiE/3avlw8HsmPC6vv2qNpfdb191vUvPPGdgY1wC4glZUvQmZNC8b/RIbz9v3TIFSjEaLXf/4kOULaxD85k/NR6nsmR8uGJ7tep2zlT9xuXUm9ygd+iavgPqDoTEhWdUWn5G1tcHqtr2vz8IVKRYvntuBZ8ww3ej4pvYIx1ZCn5mtuCqMby+VgrR5HbRLV6JTKhjk50Zhg/jh7jffuwXwt8SEFCDhGW0CQJDvOKE0OVDSVS6+UnF/iUS9yyzx0yMzrdaRmgkr1SyXpeYjWXfUyQa3HTvb3bK3TXKV59VFHYhKqEUesk9/k9aS1jau4z57TCbjxqmuRV43aDWaaY32kQ1As1DsVg7jQJ/GfHo26vgX7S87nkKIYVsZDCvfyOwi7wBAzh3Ymp5Ks1agPrXiQflbvgo0hX2jjIjAwIaTqeriReKbYZZ2zJHWHW+kDvOmhWQweJWON5HF7YDcAktRZXZpmUE/GK53A0aKL/WajviFDzz/g1lfTFuy1ao8fCSAgZNHF6OdIVnaogFx4/AQ

Environment

Browser: Chrome 130, Edge 130, Firefox 132 CesiumJS Version: 1.123 Operating System: Windows 11

ggetz commented 1 week ago

Hi @javier-lopez-1s, thank you for confirming this is effecting other data sources!

I've updated https://github.com/CesiumGS/cesium/issues/2891 to include all data sources since that appears to be the root issue. I'm going to close your issue to keep the discussion in one place. If you have any further input on this, please post it there instead.