Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cesium Troubles #371

Open
Zekiye-VAP opened this issue Aug 22, 2023 · 6 comments
Open

Cesium Troubles #371

Zekiye-VAP opened this issue Aug 22, 2023 · 6 comments

Comments

@Zekiye-VAP
Copy link

Been trying to get the add_cesium function to work but have come across a few obstacles.

First, I was not able to get the example running and figured out an alternate method of calling the tile data using the tileset.json URL from this api call; https://api.cesium.com/v1/assets/{ion_asset}/endpoint (however this only seems to work for the Cesium OSM Buildings tileset).

I am trying to add the Cesium Open Street Map Buildings layer to my map and using the below chunk, I managed to get the buildings rendered HOWEVER it seems the projections do not match and many buildings are misaligned. Seems cesium only supports web mercator and WGS84, not EPSG:4326 which mapdeck renders in. (CesiumGS/cesium#3877) Wondering if you encountered this issue with the original example?

Not really sure what to do to get this layer working and would appreciate any solutions.

        tile_data <- "https://assets.ion.cesium.com/asset_depot/96188/OpenStreetMap/2023-01-02/tileset.json"
        
        mapdeck(
          location = c(144.95, -37.82)
          , zoom = 14
          , pitch = 60
        ) %>%
          add_cesium(
            data = tile_data
            , ion_token = ion_token
          )
dcooley pushed a commit that referenced this issue Aug 22, 2023
@dcooley
Copy link
Collaborator

dcooley commented Aug 22, 2023

Not directly addressing your misalignment issue, however, I've just updated all the cesium loaders, and updated the ?add_cesium() example with the (now) correct URL. The buildings and the pointcloud now work for me. Do you get the same results?

ion_asset <- 96188
tile_data <- paste0("https://assets.ion.cesium.com/",ion_asset,"/tileset.json")

mapdeck(
	style = mapdeck_style("dark")
	, location = c(144.95, -37.82)
	, zoom = 14
	, pitch = 60
) %>%
	add_cesium(
		data = tile_data
		, ion_token = ion_token
	)

Screenshot 2023-08-22 at 2 25 38 pm

ion_asset <- 43978
tile_data <- paste0("https://assets.ion.cesium.com/",ion_asset,"/tileset.json")

mapdeck(
	style = mapdeck_style("dark")
	, location = c(144.95, -37.82)
	, zoom = 14
	, pitch = 60
) %>%
	add_cesium(
		data = tile_data
		, ion_token = ion_token
	)

Screenshot 2023-08-22 at 2 25 58 pm

@Zekiye-VAP
Copy link
Author

The point cloud now works! The building layer is still not great. Here's a video showing the issues. You can see some buildings are under the base map and all the others are floating above it at varying heights across the map.
https://github.com/SymbolixAU/mapdeck/assets/102117785/1f1e8c60-f318-4559-b65d-5b581c32c9f8

The cesium layer doesn't seem to work with all the assets either, I am trying to get 3D terrain into my map (Asset ID - 1). It is in my assets list on my cesium account but doesn't show up when I try to load it. Do you have any suggestions on bringing in 3D terrain?

Thank you for your quick responses!

@dcooley
Copy link
Collaborator

dcooley commented Aug 24, 2023

full disclosure: I've never used this layer other than to build the examples as a 'proof-of-concept', so my knowledge is very limited.


Under the hood add_cesium() is using deck.Tile3DLayer, which in turn can only show PointClouds, Scenegraphs or SimpleMeshs. But it uses the CesiumLoader to load the data. Hence the add_cesium() function name.

{mapdeck} is designed to implement all the deck.gl examples. I can't see any native deck.gl examples that use scene.setTerrain(), so this is one reason why it doesn't work


Details

In the Cesium ion page, the code it gives for showing the pointcloud is scene.primitives.add():

const tileset = viewer.scene.primitives.add(
  await Cesium.Cesium3DTileset.fromIonAssetId(43978)
);

and for the terrain it's scene.setTerrain()

viewer.scene.setTerrain(
  Cesium.CesiumTerrainProvider.fromIonAssetId(1)
);

And they are both using different "loaders" (Cesium3DTileset.fromIonAssetId() and CesiumTerrainProvider.fromIonAssetId()).

Which explains why add_cesium() doesn't work; it's only using the Cesium3DTileset loader for the Tile3DLayer.


Given there are Losts of different types of loaders, updating this add_cesium() to account for them all could be tricky.


Way Forward

I'm not sure. In all the various terrain discussions I've seen there's no mention / examples of using the scene.setTerrain( CesiumTerrainProvider() ) methods. If you can find an example of someone getting this working with deckgl it should be possible to add it to mapdeck, even if it means writing custom javascript.

But for now I'm not sure I can help much (with the usual excuse of "work-gets-in-the-way-of-opensource-projects")

@dcooley
Copy link
Collaborator

dcooley commented Aug 27, 2023

@Zekiye-VAP this may be relevant for you - r-spatial/discuss#29 (comment)

@Zekiye-Y
Copy link
Contributor

Zekiye-Y commented Sep 4, 2023

Will keep looking into fixing the projections of the buildings for the cesium layer. I have switched over to using the add_terrain function for 3D terrain which is looking great however I am having issues with clear_terrain() and it seems like there is not a clear_cesium() function implemented yet. Is it possible to get these working? Thank you for all your help!!

@Zekiye-Y
Copy link
Contributor

Zekiye-Y commented Sep 4, 2023

Deck.gl has recently added a terrain extension to allow 2D layers to generate across the 3D surface. Would is this something that could be integrated into mapdeck? https://deck.gl/docs/api-reference/extensions/terrain-extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants