2

My application allows users to add GeoJSON objects to a cesium map. If the GeoJSON has a bbox, it will set the view to the bounding box:

const destination = Cesium.Rectangle.fromDegrees(
    bbox[0], bbox[1], bbox[3], bbox[4]);
this.viewer.camera.setView({destination});

My naïve expectation is that the entirety of the GeoJSON object would be shown in the view, but that is not what I am experiencing. It appears that if the bbox has the same (or quite similar) aspect ratio to the div containing the cesium map then it behaves as I want, but if not then the view only shows a portion of the GeoJSON object. For example, this is what I am seeing:

enter image description here

And this is what I would expect to see:

enter image description here

Note that the first image is exactly as rendered after setView, the second image is shown after manually zooming out, and the blue/white stripped box is the bbox drawn to demonstrate the issue.


Further investigation seems to indicate that if the bbox is width constrained, then Cesium will zoom out to include the entire bbox, but not if height constrained. To say it another way, if the bbox is tall and skinny, I have a problem, but if short and fat, I don't...

0

You may be able to find a solution using Turf, for example http://turfjs.org/docs/#square might do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.