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 GeoJsonDataSource stops working if data is reloaded #12283

Closed javier-lopez-1s closed 2 weeks ago

javier-lopez-1s commented 3 weeks ago

What happened?

I'm working of the implementation of a GeoJsonDataSource that loads new data whenever the camera's view rectangle changes. Everything works as expected except for the logic for showing/hiding the data source. It turns out that after loading the data for the first time, the data source can be shown/hidden without problems, but if I load the same data again, then the data source can no longer be hidden. I have even tried setting show=false for every single entity after they are all loaded, but they remain visible. Sandcastle reproducing the issue below.

const viewer = new Cesium.Viewer("cesiumContainer");

const dataSource = new Cesium.GeoJsonDataSource();
viewer.dataSources.add(dataSource);
viewer.camera.lookAt(
  Cesium.Cartesian3.fromDegrees(-98.0, 40.0),
  new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0),
);

Sandcastle.addToolbarButton("Load data", function () {
  dataSource.load("../SampleData/ne_10m_us_states.topojson");
});

Sandcastle.addToolbarButton("Toggle visibility", function () {
  dataSource.show = !dataSource.show;
});

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=jVJNSwMxEP0rcU9bqNmVClrcFrWCIIKHiqeFMs1O22g2U5LZlir+d5MutfUDNKeZyXszb16iyHoWK41rdGIgLK7FCL1uavm0raVlorb5iCyDtujKpHNR2tKqLbMChjE1TuFX9i3SnSd783mdRlY7R+5JXkJVpfv8AKSgRgfSEL1ccVpasWs9AschAtuTM0f1Dc4dok+P++cy74rTXOadboQfqNlT0jyCjk/P+nk4Me71e20YWe1qY7CVAs8Go7xHIjMFd90wkw1+3BNU273LpCtmjVWsyYq0I97i1P0uQTpUAS9lNoZ6aTCakVmcnOT1pPETzxBESaYlPQerWl/f/6PgkeZzg+HVvJ5qo3nzlxK/oHV4n6Nvpd28pJsUnjcGh5EXz6Wul+RYNM6kQT9j0B/VZtNGvSBL5X0kRmiRHVKLSq+Erga/fBuhDHgfbmaNMWP9imUyLLKA/0GNxmk7f1ihM7CJsMXJ8L4tSimLLKS/M7l16lvnDw

Environment

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

ggetz commented 2 weeks ago

Thanks for the report @javier-lopez-1s!

I think this is actually a duplicate of https://github.com/CesiumGS/cesium/issues/2891. 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.