ConstrainExtentBehavior bug?

638
3
12-03-2010 06:58 AM
EricO_Neal
New Contributor II
My "Draw" tool for drawing a box to zoom in on the map will not work in combination with the ConstrainExtentBehavior.  If ConstrainExtentBehavior is set, the tool will "jerk" the map, but never zooms, even though the zoomed geometry is well within the constraint.  It will finally zoom after the 2nd or 3rd attempt. 
As I workaround, I am setting the ConstrainExtentBehavior in code on UserControl_Loaded, removing it before I zoom, then replacing at the Map_ExtentChanged.   Am I missing something here?


System.Windows.Interactivity.Behavior behavior;

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {

            behavior = new ESRI.ArcGIS.Client.Behaviors.ConstrainExtentBehavior()
            {
                ConstrainedExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(1116757.49248094, 183859.75, 1331330.81621366, 325602.25)
            };
            System.Windows.Interactivity.Interaction.GetBehaviors(MyMap).Add(behavior);

        }
private void myDrawObject_DrawComplete(object sender, DrawEventArgs args)
{

            switch (_toolMode)
            {
                case "zoomin":
                    System.Windows.Interactivity.Interaction.GetBehaviors(MyMap).Remove(behavior);
                    MyMap.ZoomTo(args.Geometry as ESRI.ArcGIS.Client.Geometry.Envelope);
                    break;
            }
}

private void MyMap_ExtentChanged(object sender, ExtentEventArgs e)
{
    if (System.Windows.Interactivity.Interaction.GetBehaviors(MyMap).Count == 0)
            {
                System.Windows.Interactivity.Interaction.GetBehaviors(MyMap).Add(behavior);
            }

}
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
I'm not able to replicate the issue when combining these two samples:

Zoom using Draw tool
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolBarWidget

ConstrainExtentBehavior defined on XAML
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ConstrainExtentBehavior
0 Kudos
MatthewLangley
New Contributor
I am seeing this same behaviour on the sample sites (and in my custom code). If I open the sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ConstrainExtentBehavior and then zoom in (starting at full extent) the first 11 zoom attempts only zoom the map a very small amount. I then reach a point when the map zooms in correctly.

In my own code if I drag a zoom box on the map (with ConstrainExtentBehavior turned on in my XAML) the map does not zoom to the extent box - it only zooms in by a few percent. If I turn off the ConstrainExtentBehavior all zoom functions work as expected. I have tested in both Chrome and IE9, and this is happening on both browsers.

I am assuming others are seeing this issue as it can be reproduced on the ESRI samples.

Does anyone know of a suitable workaround, or if this has been logged as an official bug?
0 Kudos
NathanielWingfield
New Contributor II
We experienced this too. It's clearly a bug.

Our needs were modest: we only wanted to constrain the extent of the "zoom to world" tool, so we just wrote our own implementation of the tool and removed the ConstrainExtentBehavior.
0 Kudos