Best practice to caluclate GeoJson polygon of what the camera see's

Hi,

I need to calculate the map “extent” (part of the world that the player actually sees). What is the best approach for it?

Hi @asaf.masa ,

Thanks for your question! Determining the geographic “extent” of what the player’s camera sees is a common use case in geospatial projects. Let me walk you through the general approach for Cesium for Unity.

In this case, your objective is to calculate the geographic view extent based on the camera’s frustum. Cesium for Unity provides APIs that allow you to achieve this:

  • You can use the **`Camera.main`** object in Unity to access the camera properties and retrieve its frustum parameters (i.e. near and far planes, field of view, and aspect ratio).
  • Then, you can use the Cesium for Unity API to convert 3D view frustum points from the Unity world coordinate system into geospatial coordinates. The key class here is `CesiumGeoreference`. By applying `UnityToEarthCenteredEarthFixed` or similar functions, you can transform these points into global coordinates.
  • With the view’s corner points converted to geospatial data, you can construct a bounding polygon in GeoJSON format. This involves formatting the points as a GeoJSON `Polygon` object.

For further reference, I recommend reviewing the Cesium for Unity – Cesium to better understand the transformation methods. If you’d like, I can provide more detailed guidance (e.g., sample code snippets) tailored to a specific aspect of this workflow. Let me know!

Also, if you’re dealing with large extents or want optimized performance for frequent calculations, you might consider leveraging Cesium Native directly.

Looking forward to your response!

Best,
Jake