Zooming to ImageryLayer

I’ve been having some trouble figuring out how to zoom to an ImageryLayer. I am using the WebMapServiceImageryProvider, and I’ve tried both using the viewer.flyTo(layer) and the ImageryLayer.getViewableRectangle() zooming example provided in the documentation, but no matter which way I try, I always get zoomed to Africa at the whole-world level (even if my imagery contains a very small area, like a football field). I think I’m missing something in the documentation, maybe I need to provide the bounding rectangle data in the first place? Here is a simple sandcastle example to illustrate (note that my actual application is more complex and allows users to click on layers to choose which to zoom to, and we generally use internal WMS sources from a local GeoServer instance):

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var provider = new Cesium.WebMapServiceImageryProvider({
url: 'https://mesonet.agron.iastate.edu/cgi-bin/wms/goes/conus_ir.cgi?’,
layers: ‘goes_conus_ir’,
parameters : {
transparent : ‘true’,
format: ‘image/png’
}
});

var layer = viewer.imageryLayers.addImageryProvider(provider);
viewer.flyTo(layer);

Hello,

This is happening because Cesium thinks the imagery spans the whole globe, so it’s zooming to (0, 0)

If you set the bounding rectangle, the functionality works as expected. Here is your example updated: (I just estimated the rectangle values here)

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var provider = new Cesium.WebMapServiceImageryProvider({
url: 'https://mesonet.agron.iastate.edu/cgi-bin/wms/goes/conus_ir.cgi?’,
layers: ‘goes_conus_ir’,
rectangle: Cesium.Rectangle.fromDegrees(-179, -35, -70, 80),
parameters : {
transparent : ‘true’,
format: ‘image/png’
}
});

var layer = viewer.imageryLayers.addImageryProvider(provider);
viewer.flyTo(layer);

``

Best,

Hannah

Thank you Hannah - are there any circumstances where Cesium is able to determine the bounds without declaring them manually? In our app, we allow the users to input their own WMS sources. If not, I will dig into the WMS schema and see if it’s something we can parse from the XML itself.

Sorry, I don’t think there’s anything in our code to do that automatically

-Hannah