Visual Basic (Declaration) | |
---|---|
Public Event ExtentChanged As EventHandler(Of ExtentEventArgs) |
C# | |
---|---|
public event EventHandler<ExtentEventArgs> ExtentChanged |
Each time the ExtentChanged Event fires the e parameter (ExtentEventArgs) provides information for the NewExtent and OldExtent Propeties. The first time the ExtentChanged Event fires the OldExtent will be Nothing/null since no Extent was previously set. For each subsequent firing of the ExtentChanged Event what was the previous NewExtent will become the current OldExtent (and the pattern continues). The sender parameter of the ExtentChanged Event is the Map Control.
The information obtained from the Map.ExtentChanged can be useful for creating tools that perform actions such as:
- Adding/removing specific layers if the fall within a specified extent
- Prompting the user for enhanced credentials to see more detailed information at a specified extent
- Notifying a user that data is not available for a specific extent
The event handler receives an argument of type ExtentEventArgs containing data related to this event. The following ExtentEventArgs properties provide information specific to this event.
Property | Description |
---|---|
NewExtent | The new extent envelope. |
OldExtent | The old extent envelope. |
How to use:
Use the standard zoom in/out, pan, keyboard, mouse, and touch actions in the Map Control to interrogate the ExtentEventArgs information of the ExtentChanged Event.
The XAML code in this example is used in conjunction with the code-behind (C# or VB.NET) to demonstrate the functionality.
The following screen shot corresponds to the code example in this page.
XAML | Copy Code |
---|---|
<Grid x:Name="LayoutRoot"> <!-- Add a Map control with an ArcGISDymanicMapServiceLayer. Specify the use of the ExtentChanged Event. --> <esri:Map Background="White" HorizontalAlignment="Left" Name="Map1" VerticalAlignment="Top" Height="426" Width="434" ExtentChanged="Map1_ExtentChanged" Margin="2,54,0,0"> <esri:ArcGISDynamicMapServiceLayer Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer" /> </esri:Map> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="40" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="436" TextWrapping="Wrap" Margin="2,9,0,0" Text="Use the standard Zoom In/Out and Pan, keyboard and mouse actions to see how the ExtentChanged Events provide information for the ExtentEventArgs." /> <!-- Show the Envelope information for the OldExtent. --> <StackPanel Height="120" HorizontalAlignment="Left" Margin="440,54,0,0" Name="StackPanel1" VerticalAlignment="Top" Width="200" > <sdk:Label Height="24" Name="Label1" Width="120" Content="OldExtent"/> <Grid Name="Grid1"> <Grid.RowDefinitions> <RowDefinition Height="24"/> <RowDefinition Height="24"/> <RowDefinition Height="24"/> <RowDefinition Height="24"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"/> <ColumnDefinition Width="160"/> </Grid.ColumnDefinitions> <sdk:Label Grid.Row="0" Grid.Column="0" Content="XMin:"/> <sdk:Label Grid.Row="0" Grid.Column="1" Name="OldExtent_XMin"/> <sdk:Label Grid.Row="1" Grid.Column="0" Content="XMax:"/> <sdk:Label Grid.Row="1" Grid.Column="1" Name="OldExtent_XMax" /> <sdk:Label Grid.Row="2" Grid.Column="0" Content="YMin:"/> <sdk:Label Grid.Row="2" Grid.Column="1" Name="OldExtent_YMin"/> <sdk:Label Grid.Row="3" Grid.Column="0" Content="YMin:"/> <sdk:Label Grid.Row="3" Grid.Column="1" Name="OldExtent_YMax" /> </Grid> </StackPanel> <!-- Show the Envelope information for the NewExtent. --> <StackPanel Height="120" HorizontalAlignment="Left" Margin="440,200,0,0" Name="StackPanel2" VerticalAlignment="Top" Width="200" > <sdk:Label Height="24" Name="Label1A" Width="120" Content="NewExtent"/> <Grid Name="Grid2"> <Grid.RowDefinitions> <RowDefinition Height="24"/> <RowDefinition Height="24"/> <RowDefinition Height="24"/> <RowDefinition Height="24"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="40"/> <ColumnDefinition Width="160"/> </Grid.ColumnDefinitions> <sdk:Label Grid.Row="0" Grid.Column="0" Content="XMin:"/> <sdk:Label Grid.Row="0" Grid.Column="1" Name="NewExtent_XMin"/> <sdk:Label Grid.Row="1" Grid.Column="0" Content="XMax:"/> <sdk:Label Grid.Row="1" Grid.Column="1" Name="NewExtent_XMax" /> <sdk:Label Grid.Row="2" Grid.Column="0" Content="YMin:"/> <sdk:Label Grid.Row="2" Grid.Column="1" Name="NewExtent_YMin"/> <sdk:Label Grid.Row="3" Grid.Column="0" Content="YMin:"/> <sdk:Label Grid.Row="3" Grid.Column="1" Name="NewExtent_YMax" /> </Grid> </StackPanel> </Grid> |
C# | Copy Code |
---|---|
private void Map1_ExtentChanged(object sender, ESRI.ArcGIS.Client.ExtentEventArgs e) { // Use local variables to obtain the e arguments. ESRI.ArcGIS.Client.Geometry.Envelope myOldExtent = e.OldExtent; ESRI.ArcGIS.Client.Geometry.Envelope myNewExtent = e.NewExtent; // Display the results from the Map.ExtentChanged Event. if (myOldExtent != null) { OldExtent_XMax.Content = myOldExtent.XMax; OldExtent_XMin.Content = myOldExtent.XMin; OldExtent_YMax.Content = myOldExtent.YMax; OldExtent_YMin.Content = myOldExtent.YMin; } if (myNewExtent != null) { NewExtent_XMax.Content = myNewExtent.XMax; NewExtent_XMin.Content = myNewExtent.XMin; NewExtent_YMax.Content = myNewExtent.YMax; NewExtent_YMin.Content = myNewExtent.YMin; } } |
VB.NET | Copy Code |
---|---|
Private Sub Map1_ExtentChanged(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Client.ExtentEventArgs) ' Use local variables to obtain the e arguments. Dim myOldExtent As ESRI.ArcGIS.Client.Geometry.Envelope = e.OldExtent Dim myNewExtent As ESRI.ArcGIS.Client.Geometry.Envelope = e.NewExtent ' Display the results from the Map.ExtentChanged Event. If myOldExtent IsNot Nothing Then OldExtent_XMax.Content = myOldExtent.XMax OldExtent_XMin.Content = myOldExtent.XMin OldExtent_YMax.Content = myOldExtent.YMax OldExtent_YMin.Content = myOldExtent.YMin End If If myNewExtent IsNot Nothing Then NewExtent_XMax.Content = myNewExtent.XMax NewExtent_XMin.Content = myNewExtent.XMin NewExtent_YMax.Content = myNewExtent.YMax NewExtent_YMin.Content = myNewExtent.YMin End If End Sub |
Target Platforms:Windows Phone 7