Have you run into a strange bug where your ArcGIS map zooms out to show the entire world, even though you’re using SetViewpointAsync with the correct Extent?

We did too.

In a recent project, we were programmatically placing graphic pins on a map using Esri’s ArcGIS Runtime SDK (for .NET MAUI and WinUI). Everything worked fine — until it didn’t. Sometimes, after setting the map extent, we’d end up zoomed all the way out to the global view. And we’re talking tiny pins in Berlin, not a world tour.

đŸ§© The Real Problem
#

After some digging, we realized this only happened when:

  • All pins shared the same latitude (or longitude)
  • We had only one single pin
  • Our calculated Envelope had zero width or height

When this happens, EnvelopeBuilder.Height or .Width returns 0, and SetViewpointAsync decides:

“No size? Cool, here’s the entire planet.”

🙃 Thanks, but no thanks.

✅ The Fix: Robust SetExtentAsync
#

Here’s the full method we now use to avoid this pitfall:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private async Task SetExtentAsync(GraphicsOverlay graphicsOverlay)
{
    GraphicCollection graphicsCollection = graphicsOverlay.Graphics;
    EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(SpatialReferences.Wgs84);

    foreach (Graphic oneGraphic in graphicsCollection)
    {
        envelopeBuilder.UnionOf(oneGraphic.Geometry?.Extent ??
                                  new Envelope(new MapPoint(0, 0), new MapPoint(0, 0)));
    }

    // Avoid flat envelopes (zero width/height)
    if (envelopeBuilder.Height == 0 || envelopeBuilder.Width == 0)
    {
        double height = envelopeBuilder.Height == 0
            ? (envelopeBuilder.Width == 0 ? 0.01 : envelopeBuilder.Width * 0.1)
            : envelopeBuilder.Height;

        double width = envelopeBuilder.Width == 0
            ? (envelopeBuilder.Height == 0 ? 0.01 : envelopeBuilder.Height * 0.1)
            : envelopeBuilder.Width;

        envelopeBuilder = new EnvelopeBuilder(envelopeBuilder.Center, width, height);
    }

    envelopeBuilder.Expand(1.3); // Add 30% padding

    await MapView.SetViewpointAsync(new Viewpoint(envelopeBuilder.Extent));
}

🔍 SEO-style summary (for Google-friendliness):
#

If you’re searching for:

  • “ArcGIS map zooms out too far”
  • “SetExtent not working ArcGIS”
  • “ArcGIS map shows world even though pins are close together”
  • “SetViewpointAsync extent has 0 height or width”


then you’re exactly the person this post is for.