Extent from polygon / polyline?

Hi all,

Is there an easy way to calculate the extent from a polygon / polyline?

Assuming I have something like

polylines.add({

positions: Cesium.Ellipsoid.WGS84.cartographicArrayToCartesianArray([

new Cesium.Cartographic(Cesium.Math.toRadians(ybl), Cesium.Math.toRadians(xbl)),

new Cesium.Cartographic(Cesium.Math.toRadians(ybr), Cesium.Math.toRadians(xbr)),

new Cesium.Cartographic(Cesium.Math.toRadians(ytr), Cesium.Math.toRadians(xtr)),

new Cesium.Cartographic(Cesium.Math.toRadians(ytl), Cesium.Math.toRadians(xtl)),

new Cesium.Cartographic(Cesium.Math.toRadians(ybl), Cesium.Math.toRadians(xbl))

])

});

I know I can’t do polylines.extent or polylines.getExtent() or something?

Thanks

Toby

Toby - check out Extent.fromCartographicArray.

Patrick

Perfect. Thanks.

For anyone looking at this thread wanting to make the camera fly to an extent, make sure the flight is : Cesium.CameraFlightPath.createAnimationExtent and not Cesium.CameraFlightPath.createAnimationCartographic

Had me stumped for a while.

Sorry to reopen - should this work for polylines too?

Given

var test = new Array([

Cesium.Cartographic.fromDegrees(-120.0, 40.0),

Cesium.Cartographic.fromDegrees(-110.0, 30.0)

]);

var newExtent = Cesium.Extent.fromCartographicArray(test);

Should that work? my newExtent.north / south etc are coming back as NaN…

Toby

Toby,

I’m not sure that the JavaScript is right. Try just:

var test = [

Cesium.Cartographic.fromDegrees(-120.0, 40.0),

Cesium.Cartographic.fromDegrees(-110.0, 30.0)

];

var newExtent = Cesium.Extent.fromCartographicArray(test);

Patrick