Select to view content in your preferred language

Zooming into an extent more than once causes features within it to shift

682
3
10-07-2011 07:34 AM
HasheenDeBerry
Occasional Contributor
Hello All,

I am using the Silverlight API v2.2 and I noticed a rather odd issue.

I have some code that will zoom into the extent of the features on the map (usually points and/or polygons).  When the function is called again on the same extent, the features within the extent shift north and east a little. Below is the code for the function:

 private void ZoomIn(List<Graphic> lstGraphics)
        {
            if (lstGraphics.Count > 0)
            {
                Envelope zoomExtent = lstGraphics.First().Geometry.Extent;

                for (int i = 1, il = lstGraphics.Count; i < il; i++)
                {
                    try
                    {
                        zoomExtent = zoomExtent.Union(lstGraphics.Geometry.Extent);
                    }
                    catch { continue; }
                }

                Utils.ApplyWKID(zoomExtent, myCurrentMap.Layers[0].SpatialReference.WKID);

                double width = zoomExtent.XMax - zoomExtent.XMin;
                double height = zoomExtent.YMax - zoomExtent.YMin;

                if (width > 0 && height > 0)
                {
                    //expand by 10%

                    double newWidth = width + (width * 0.1);
                    double newHeight = height + (height * 0.1);

                    double dx = (newWidth - width) / 2;
                    double dy = (newHeight - height) / 2;

                    //update extent
                    zoomExtent.XMin -= dx;
                    zoomExtent.XMax += dx;
                    zoomExtent.YMin -= dy;
                    zoomExtent.YMax += dy;

                    myCurrentMap.ZoomTo(zoomExtent);
                }
                else
                {
                    //assume it is a single map point and zoom in
                    ZoomIn(new MapPoint(zoomExtent.XMin, zoomExtent.YMin, zoomExtent.SpatialReference), LinearUnit.Meter, 1610);
                }
            }
            else
            {
                ShowMessage("Unable to zoom to map featues. No map features found.");
            }
        }


I've been able to recreate the behaviour on different basemaps hosted in house and on ESRI's servers.  Any help or insight that anyone can provide is greatly appreciated.

Thanks In Advance
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I cannot repro with your code using sampleserver services although I had to skip the following lines (since there was no implementation provided):
 Utils.ApplyWKID(zoomExtent, myCurrentMap.Layers[0].SpatialReference.WKID);
  ZoomIn(new MapPoint(zoomExtent.XMin, zoomExtent.YMin, zoomExtent.SpatialReference), LinearUnit.Meter, 1610);


I called ZoomIn() method in a Button.Click event multiple times and I did not see a shift in the features using v2.2 assemblies.

Could you check if there was a mismatch between FeatureService.SpatialReference and Map.SpatialReference?
0 Kudos
HasheenDeBerry
Occasional Contributor
@jenniferdnery

Thank you for your help.  Upon further review this was an EBCAK error on my end and not an issue with the SDK.  Is there a way to mark this thread as complete?
0 Kudos
JenniferNery
Esri Regular Contributor
I'm not how forum threads can be marked resolved. But thanks for giving us a follow up. I think your last post is a good indicator that it has been resolved 🙂
0 Kudos