Hi,
I’m trying to load a GeoJson onto the map. The GeoJson is coming from GeoServer and the coordinates are in meters (EPSG:3857). The only way I could load the data correctly was by converting the coordinate points to EPSG:4326 and then load with Cesium.GeoJsonDataSource
.
const proj = new Cesium.WebMercatorProjection();
featureInfo.data.geometry.coordinates.forEach(polygon => {
polygon.forEach(ring => {
ring.forEach((point, index, coordinateArray) => {
const cartographic = proj.unproject(new Cesium.Cartesian3(point[0], point[1]));
const x = Cesium.Math.toDegrees(cartographic.longitude);
const y = Cesium.Math.toDegrees(cartographic.latitude);
coordinateArray[index] = [x, y];
});
});
});
self.viewer.dataSources.add(Cesium.GeoJsonDataSource.load(featureInfo.data, {
stroke: Cesium.Color.ORANGE,
fill: Cesium.Color.YELLOW,
strokeWidth: 3
}));
The code above only works for MultiPolygon
feature type. Now I have to make changes to support all other feature type, which is annoying. Is there an easier way to do this?
Thank you,
Hugo