ThinkGeo.com    |     Documentation    |     Premium Support

Map does not zoom into current extent

The steps are as follows:

I have added a feature layer to the map and retrieved the bounding box using: featureLayer.GetBoundingBox();
Next, I combine this bounding box retrieved with the current extent of the map to get a new bounding box.
Then I use this new bounding box as the map’s current extent. After refreshing the map, it does not zoom or pan to the new features. I do see the features on the map but it is not centered around these features. The code looks somewhat like this:

 if (featureLayer.IsOpen)
                {
                    bbox = featureLayer.GetBoundingBox();
                    featureLayer.Close();

                    // i just chose a random width of 5.  This should depend on projection.
                    if (bbox.Width > 5)
                    {
                        var nextExtent = MapView.CurrentExtent.Union(bbox).GetBoundingBox();
                        MapView.CurrentExtent = nextExtent;
                    }
                }

Somewhere later in the code, I do refresh the map.

What am I missing guys?

Hi Klaus,

If you want to center at the features, you shouldn’t union current extent to it.

Because if the current extent is far away from your feature’s bounding box, the map need to shows current extent area and your feature’s area at the same time, so your features will be rendered at the corner.

So you just need to make featureLayer.GetBoundingBox() as the map’s current extent.

But in fact I think that’s should because your feature’s hadn’t assign correct projection, because your target should be your feature’s match your background layer(default current extent), so please check your projection logic.

Regards,

Ethan

That did it Ethan. Thank you.

However, if I wanted to still ensure that all the features on all feature layers on the map are still displayed when I add a new feature layer, how would I go about doing this?

Grabbing all feature layers, their bounding boxes and performing a union?

Hi Klaus,

Yes, just like you mentioned, if you want to show the features from different layers into the same extent, you need union their bounding box and assign it to Map.CurrentExtent.

Regards,

Ethan