View Extent that spans the poles issue?

Hello All,

Is there a known issue that Cesium has in zooming to an extent that crosses the poles? I get in a WKT [1] which I translate into a Cartographic array [2]. That extent of that array [3] is then used to send the camera on a flight and finish there [4].

The issue is that when the camera flies it ends up at the wrong place (see image).

Any ideas?

Thanks

Toby

[1] POLYGON((173.432744991659 81.352294222274,177.322624535387 83.019958561176,183.74980554926 84.6283724821572,195.526528976403 86.1036634832159,219.067575925448 87.2249429886453,257.190466398135 87.4678448039113,287.747043392052 86.6363822051197,303.394411215325 85.2663339766817,311.551035037177 83.6997170373746,316.293929881442 82.0518501723837,319.304005087058 80.364270031322,321.335223859686 78.65456672004,322.764979449651 76.9312943391795,323.800422209977 75.1991053451193,324.563954520309 73.4606965030539,325.132234522747 71.7177694750058,325.55561974728 69.9713729699831,325.868474287099 68.2222165914708,326.095014008624 66.4708388210721,326.252784154321 64.7176064425749,326.354790223748 62.962789343714,326.410864006997 61.2066228093034,326.428569778813 59.4492272503271,326.413809593 57.6907033607286,326.371251199109 55.9311789072471,326.344136508253 55.1413103661434,326.312410022239 54.349082433211,344.102210841266 53.1200545386932,359.905612703499 49.5016896617048,388.011668730935 66.7671929523656,450.328564925755 69.5192676972965,472.283804747853 78.3223897366817,173.432744991659 81.352294222274))

[2] function WKT2CartographicArray(WKT) {

//mainly for image information.

var newWKT = WKT.replace(“frame:”, “”);

newWKT = newWKT.replace("((", “”);

newWKT = newWKT.replace("))", “”);

try {

newWKT = newWKT.replace(“POLYGON”, “”);

} catch (e) {

}

try {

newWKT = newWKT.replace(“POLYLINE”, “”);

} catch (e) {

}

try {

newWKT = newWKT.replace(“POINT”, “”);

} catch (e) {

}

var stringArray = (newWKT.split(","));

for (var i = 0; i < stringArray.length; i++) {

stringArray[i] = stringArray[i].replace(" ", “,”);

var subNumbers = stringArray[i].split(",");

for (var j = 0; j < subNumbers.length; j++) {

subNumbers[j] = parseFloat(subNumbers[j]);

}

stringArray[i] = Cesium.Cartographic.fromDegrees(subNumbers[0], subNumbers[1], 0);

}

return stringArray;

}

[3] var extent = new Cesium.Extent.fromCartographicArray(positionsArray);

[4] var flight = Cesium.CameraFlightPath.createAnimationExtent(scene.getFrameState(), {

destination: extent,

onComplete: function () { }

});

I'm sure one of the Cesium devs could elaborate on this more, but I think you're running into a similar issue that I ran into so thought I would share my experiences. The issue I ran into was that when you have an extent that crosses over the poles or the International Date Line you have an extent that is not unique (i.e. there is more than one place on the globe where that extent can be represented). I'm not sure how Cesium chooses, but the issue I was having is that when I had an extent that crossed the Date Line and tried to zoom to it I was zoomed to the exact opposite side of the globe (makes sense since this location had the same extent). How I overcame this issue was to also include a center point with my extent. Now in my case I wasn't using any sort of animation to zoom so I just got the camera coordinates needed to view the extent and then manually adjusted the center point:

var toRad = Cesium.Math.toRadians;
var controller = widget.scene.getCamera().controller;
var ellipsoid = widget.centralBody.getEllipsoid();
var czExtent = new Cesium.Extent(toRad(viewingExtent.west), toRad(viewingExtent.south), toRad(viewingExtent.east), toRad(viewingExtent.north));
// get the position of the camera needed to view the extent
var cameraPosition = ellipsoid.cartesianToCartographic(controller.getExtentCameraCoordinates(czExtent));
// adjust the center point
cameraPosition.longitude = toRad(viewingExtent.center.lon);
cameraPosition.latitude = toRad(viewingExtent.center.lat);
// update the camera position
controller.setPositionCartographic(cameraPosition);

Hope this helps.