Limit the view of a map to a particular area.
Use case
When showing map information relevant to only a certain area, you may wish to constrain the user's ability to pan or zoom away.
How to use the sample
The application loads with a map whose maximum extent has been set to the borders of Colorado. Note that you won't be able to pan far from the Colorado border or zoom out beyond the minimum scale set by the max extent. Use the control to disable the max extent to freely pan/zoom around the map.
How it works
- Create a
Map
object. - Create an envelope of the extent.
- Set the map to a
MapView
object. - Set the maximum extent of the map with
map.MaxExtent = extentEnvelope
. - Set
MaxExtent
tonull
to disable the maximum extent of the map.
Relevant API
- Envelope
- Map
Tags
extent, limit panning, map, mapview, max extent, zoom
Sample Code
<ContentPage x:Class="ArcGISRuntimeXamarin.Samples.SetMaxExtent.SetMaxExtent"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:esriUI="clr-namespace:Esri.ArcGISRuntime.Xamarin.Forms;assembly=Esri.ArcGISRuntime.Xamarin.Forms">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<esriUI:MapView x:Name="MyMapView" Grid.Row="0" />
<Grid Grid.Row="1" HorizontalOptions="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="Max Extent Enabled"
VerticalOptions="Center" />
<Switch x:Name="MaxExtentSwitch"
Grid.Column="1"
Toggled="MaxExtentSwitchToggled"
VerticalOptions="Center" />
</Grid>
</Grid>
</ContentPage>