1

I have a WPF Map control whose extent I would like to restrict to a certain area (e.g. to the full extent of some layer). That is, a user should not be able to zoom out too far, or shift the map to an area outside that full extent.

How can I restrict Map display to a certain extent?

This is my code:

<esri:Map x:Name="Map" SizeChanged="Map_SizeChanged">
    <esri:ArcGISTiledMapServiceLayer x:ID="LB" ... />
    ...
</esri:Map>

And here is the code-behind (this code does not work):

void Map_SizeChanged(object sender, SizeChangedEventArgs e)
{
    if (currentExtent > Map.Zoom(Map.Layers["LB"].FullExtent)) // check the current extent of the map. If currentExtent is more than FullExtent
    {
        // jump back to full extent
        Map.Zoom(Map.Layers["LB"].FullExtent);
    }
}

I'd like to get something like that:

private void Map_SizeChanged(object sender, SizeChangedEventArgs e)
{
    … // get current extent of the map

    … // check the current extent of the map.
      // if currentExtent is more than FullExtent jump back to full extent
}

I'm using the ESRI API for WPF and C# in Visual Studio 2010.

2

There is a ConstrainExtentBehavior that you can add to the Map.

See here.

<esri:Map x:Name="MyMap" Extent="-120,30,-60,60">
. . . 
  <i:Interaction.Behaviors>
    <esriBehaviors:ConstrainExtentBehavior
      ConstrainedExtent="-120,30,-60,60"/> 
  </i:Interaction.Behaviors>
</esri:Map>

You can get the extent of your layer and set it as the ContrainedExtent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.