Closed Fedec96 closed 2 months ago
Tried to change the entity's arc type:
const dataSource = Cesium.GeoJsonDataSource.load(data);
dataSource.then((render) => {
for (let i = 0; i < render.entities.values.length; i++) {
const entity = render.entities.values[i];
if (entity.polygon) {
entity.polygon.arcType = Cesium.ArcType.GEODESIC;
}
}
viewer.dataSources.add(dataSource);
});
The error is different:
Error
at new DeveloperError (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:64:13)
at Cartesian3.normalize (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:859:17)
at blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:19224:23
at computeTriangleAttributes (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:19245:7)
at splitLongitudeTriangles (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:19512:9)
at GeometryPipeline.splitLongitude (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:20994:13)
at geometryPipeline (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:21253:36)
at PrimitivePipeline.combineGeometry (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:21542:24)
at combineGeometry (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:21924:47)
at onMessageHandler (blob:https://sandcastle.cesium.com/40f95b44-e0f4-46f1-b23d-819881da1a16:21870:30)
Hi @Fedec96, thanks for reporting this issue!
I believe this is an instance of a bug we're already tracking, https://github.com/CesiumGS/cesium/issues/4801. 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.
From that issue, a potential workaround could be to set up the Viewer
with the scene3DOnly
option.
Thanks for the feedback @ggetz! Setting scene3Donly
to true
prevents Cesium from crashing, but no geometry is drawn on the globe. I'll keep an eye on #4801.
@ggetz & others: I'm gonna leave this here for other souls that have this problem in production: while this is not ideal, this is the function I used to patch the crash. While it's not formally correct, it prevents crashes while not heavily impacting visuals:
import type { Polygon, Position } from "geojson";
const adjustPolygonCoordinates = (coordinates: Position[][]): Position[][] => {
const maxLatitude = 89.9;
const minLatitude = -89.9;
return coordinates.map((ring) =>
ring.map(([lon, lat]) => {
const adjustedLat = Math.max(Math.min(lat, maxLatitude), minLatitude);
let adjustedLon = lon;
if (lon < -180) {
adjustedLon = lon + 360;
} else if (lon > 180) {
adjustedLon = lon - 360;
}
return [adjustedLon, adjustedLat];
})
);
};
/**
* Adjusts a polygon's coordinates to avoid rendering issues caused by extreme
* latitudes (near the poles) and longitudes (crossing the International Date
* Line).
*
* The problem: GeoJSON polygons that have coordinates near the poles (at
* latitudes of -90 or 90) can cause issues in rendering engines like Cesium.
* Additionally, coordinates that cross the International Date Line
* (IDL, at longitude ±180°) might introduce invalid geometries due to improper
* longitude wrapping.
*
* Approach:
*
* - Latitude adjustment: Coordinates with latitudes beyond -89.9° and 89.9°
* are adjusted to avoid issues at the poles
* - Longitude wrapping: Longitudes outside the range of [-180, 180] are
* normalized by wrapping around the globe to ensure continuity
*
* @param geometry The polygon geometry.
*
* @returns The adjusted polygon.
*/
export const adjustPolygon = (geometry: Polygon): Polygon => ({
...geometry,
coordinates: adjustPolygonCoordinates(geometry.coordinates),
});
What happened?
I receive a valid GeoJSON geometry which cannot be rendered on Cesium. I tried to convert it to Entity and also tried to use GeoJsonDataSource. The incriminated code for reference:
This is the same geometry drawn on geojson.io (no errors):
The error from Cesium:
Reproduction steps
No response
Sandcastle example
https://sandcastle.cesium.com/index.html#c=jVbbbtw2EP0VYZ9cwKZneBmSrmMUcIICRW+Ai750+6DsKqlQrWSsZAdOkH/voSgn4tYF6gfv7pyZ4ZkruRv6car29VRXr6pP276qpqf75qrabn4duqf3Q7/dnCfpbhiO+7avp2a8qv5Ikur5A180Kx1IkzuvLoJVLhj28uf5Fzwo7YTEJNgpayx5u4IvojLWx7jg0YoRt8Z1VI6NdXZRCIHX7i+sV94LGZdxZ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v3ohedWuq8cRyLuHrrtrPzbbzc31JfT/ZZqia/v3vzw2x65+Smp/8c2PWaiUur7Ez5ctp2Ho3tbHE8//AA
Environment
Browser: Microsoft Edge 128.0.2739.79 (Official build) (64-bit) CesiumJS Version: 1.121.1 Operating System: Linux Ubuntu 22.04.5 LTS x86_64