Visual Basic (Declaration) | |
---|---|
Public ReadOnly Property Bookmarks As ObservableCollection(Of Bookmark.MapBookmark) |
C# | |
---|---|
public ObservableCollection<Bookmark.MapBookmark> Bookmarks {get;} |
How to use:
Click the different RadioButtons to change the items in the Bookmark Control. Then click the various Bookmark.MapBookmark items in the Bookmark Control to zoom to the different Extents.
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"> <!-- Provide the instructions on how to use the sample code. --> <TextBlock Height="52" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="626" TextWrapping="Wrap" Margin="2,9,0,0" Text="Click the different RadioButtons to change the items in the Bookmark Control. Then click the various Bookmark.MapBookmark items in the Bookmark Control to zoom to the different Extents." /> <!-- Add a Map Control. --> <esri:Map Background="White" HorizontalAlignment="Left" Margin="12,85,0,0" Name="Map1" VerticalAlignment="Top" Height="360" Width="401" > <!-- Add an ArcGISTiledMapServiceLayer for a data source. --> <esri:ArcGISTiledMapServiceLayer ID="PhysicalTiledLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"/> </esri:Map> <!-- Add a Bookmark Control. Bind the Bookmark.Map Property to the Map Control. --> <esri:Bookmark HorizontalAlignment="Left" Margin="426,85,0,0" Name="Bookmark1" VerticalAlignment="Top" Width="179" Map="{Binding ElementName=Map1}"/> <!-- Add a RadioButton that will correspond to State level predefined Map.Extents. The Click Event is Wired-up for use with the code-behind. Note how it uses the same Event handler as the other Radio Buttons. It is the use of the RadioButton.Tag Property that will help the code-behind functions know which RadioButton was chosen. --> <RadioButton Content="State (FL and GA)" Height="16" HorizontalAlignment="Left" Margin="12,67,0,0" Name="RadioButton_State" VerticalAlignment="Top" Click="RadioButtons" Tag="State"/> <!-- Add a RadioButton that will correspond to local level predefined Map.Extents. The Click Event is Wired-up for use with the code-behind. Note how it uses the same Event handler as the other Radio Buttons. It is the use of the RadioButton.Tag Property that will help the code-behind functions know which RadioButton was chosen. --> <RadioButton Content="Florida (local)" Height="16" HorizontalAlignment="Left" Margin="154,67,0,0" Name="RadioButton_Local_FL" VerticalAlignment="Top" Click="RadioButtons" Tag="FL"/> <!-- Add a RadioButton that will correspond to local level predefined Map.Extents. The Click Event is Wired-up for use with the code-behind. Note how it uses the same Event handler as the other Radio Buttons. It is the use of the RadioButton.Tag Property that will help the code-behind functions know which RadioButton was chosen. --> <RadioButton Content="Georgia (local)" Height="16" HorizontalAlignment="Left" Margin="288,67,0,0" Name="RadioButton_Local_GA" VerticalAlignment="Top" Click="RadioButtons" Tag="GA"/> </Grid> |
C# | Copy Code |
---|---|
private void RadioButtons(object sender, System.Windows.RoutedEventArgs e) { // This function serves as the Click Event handler for the three RadioButtons. Get the .Tag // Property from the RadioButton to construct an ObservableCollecton of MapBookmark objects. // Then add the MapBookmark items to the Bookmark Control. // Get the RadioButton from the sender. RadioButton theRadioButton = (RadioButton)sender; // Get the String identifying which RadioButton we have from the RadioButton.Tag Property. string theTag = (string)theRadioButton.Tag; // Get the ObservableCollection<Of MapBookmark> object based upon which RadioButton the user chose. Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark> myObservableCollectionOfMapBookmark = null; myObservableCollectionOfMapBookmark = GenerateObservableCollectionOfMapBookmark(theTag); // Clear out any existing MapBookmark objects from the Bookmark Control. Bookmark1.ClearBookmarks(); // Loop through the ObservableCollection<MapBookmark> object and add each MapBookmark to // the Bookmark Control using the .Bookmarks Property. foreach (ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark oneMapBookmark in myObservableCollectionOfMapBookmark) { // The Bookmark.Bookmarks Property returns a ReadOnly ObservableCollection<MapBookmark> // object. So to get items in the ObservableCollection, use the Add Property. Bookmark1.Bookmarks.Add(oneMapBookmark); // This could be an alternative way to add a MapBookmark to the ObservableCollection! // Bookmark1.AddBookmark(oneMapBookmark.Name, oneMapBookmark.Extent); } // NOTE: Because the Bookmark.Bookmarks Property returns a Read Only // ObservableCollection<MapBookmark>, you CANNOT do this: // Bookmark1.Bookmarks = myObservableCollectionOfMapBookmark; } public Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark> GenerateObservableCollectionOfMapBookmark(string theTag) { // This the main function that generates the correct set of MapBookmark items to be added to the // Bookmark Control. Depending on which RadioButton the user chose will determine what gets added to // the ObservableCollection<MapBookmark>. // Create a new instance of the ObservableCollection<MapBookmark>. Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark> theBookmarks = new Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark>(); if (theTag == "State") { // Generate MapBookmark's for a State level of viewing. theBookmarks.Add(MakeMapBookmark("Florida and Georgia", new ESRI.ArcGIS.Client.Geometry.Envelope(-10126037, 2750924, -8487426, 4221996))); theBookmarks.Add(MakeMapBookmark("Florida", new ESRI.ArcGIS.Client.Geometry.Envelope(-9808676, 2779124, -8812475, 3673469))); theBookmarks.Add(MakeMapBookmark("Georgia", new ESRI.ArcGIS.Client.Geometry.Envelope(-9633752, 3534963, -8898290, 4195229))); } else if (theTag == "FL") { // Generate MapBookmark's for a local level of viewing. theBookmarks.Add(MakeMapBookmark("Jacksonville", new ESRI.ArcGIS.Client.Geometry.Envelope(-9105796, 3532477, -9075555, 3559626))); theBookmarks.Add(MakeMapBookmark("Miami", new ESRI.ArcGIS.Client.Geometry.Envelope(-8936736, 2965084, -8918792, 2981193))); theBookmarks.Add(MakeMapBookmark("Tampa", new ESRI.ArcGIS.Client.Geometry.Envelope(-9194994, 3225279, -9165864, 3251430))); } else if (theTag == "GA") { // Generate MapBookmark's for a local level of viewing. theBookmarks.Add(MakeMapBookmark("Atlanta", new ESRI.ArcGIS.Client.Geometry.Envelope(-9421000, 3975108, -9367812, 4022858))); theBookmarks.Add(MakeMapBookmark("Columbus", new ESRI.ArcGIS.Client.Geometry.Envelope(-9464616, 3820843, -9455555, 3828978))); theBookmarks.Add(MakeMapBookmark("Savannah", new ESRI.ArcGIS.Client.Geometry.Envelope(-9043472, 3757220, -9013688, 3783958))); } // Return the ObservableCollection<MapBookmark> to the caller. return theBookmarks; } public ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark MakeMapBookmark(string aName, ESRI.ArcGIS.Client.Geometry.Envelope anExtent) { // A helper function to create a single MapBookmark based upon an input Name and Extent. ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark aMapBookmark = new ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark(); aMapBookmark.Name = aName; aMapBookmark.Extent = anExtent; // Return the MapBookmark to the caller. return aMapBookmark; } |
VB.NET | Copy Code |
---|---|
Private Sub RadioButtons(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) ' This function serves as the Click Event handler for the three RadioButtons. Get the .Tag ' Property from the RadioButton to construct an ObservableCollecton of MapBookmark objects. ' Then add the MapBookmark items to the Bookmark Control. ' Get the RadioButton from the sender. Dim theRadioButton As RadioButton = sender ' Get the String identifying which RadioButton we have from the RadioButton.Tag Property. Dim theTag As String = theRadioButton.Tag ' Get the ObservableCollection(Of MapBookmark) object based upon which RadioButton the user chose. Dim myObservableCollectionOfMapBookmark As Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark) myObservableCollectionOfMapBookmark = GenerateObservableCollectionOfMapBookmark(theTag) ' Clear out any existing MapBookmark objects from the Bookmark Control. Bookmark1.ClearBookmarks() ' Loop through the ObservableCollection(Of MapBookmark) object and add each MapBookmark to ' the Bookmark Control using the .Bookmarks Property. For Each oneMapBookmark As ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark In myObservableCollectionOfMapBookmark ' The Bookmark.Bookmarks Property returns a ReadOnly ObservableCollection(Of MapBookmark) ' object. So to get items in the ObservableCollection, use the Add Property. Bookmark1.Bookmarks.Add(oneMapBookmark) ' This could be an alternative way to add a MapBookmark to the ObservableCollection! 'Bookmark1.AddBookmark(oneMapBookmark.Name, oneMapBookmark.Extent) Next ' NOTE: Because the Bookmark.Bookmarks Property returns a Read Only ' ObservableCollection(Of MapBookmark), you CANNOT do this: 'Bookmark1.Bookmarks = myObservableCollectionOfMapBookmark End Sub Public Function GenerateObservableCollectionOfMapBookmark(ByVal theTag As String) As Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark) ' This the main function that generates the correct set of MapBookmark items to be added to the ' Bookmark Control. Depending on which RadioButton the user chose will determine what gets added to ' the ObservableCollection(Of MapBookmark). ' Create a new instance of the ObservableCollection(Of MapBookmark). Dim theBookmarks As New Collections.ObjectModel.ObservableCollection(Of ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark) If theTag = "State" Then ' Generate MapBookmark's for a State level of viewing. theBookmarks.Add(MakeMapBookmark("Florida and Georgia", New ESRI.ArcGIS.Client.Geometry.Envelope(-10126037, 2750924, -8487426, 4221996))) theBookmarks.Add(MakeMapBookmark("Florida", New ESRI.ArcGIS.Client.Geometry.Envelope(-9808676, 2779124, -8812475, 3673469))) theBookmarks.Add(MakeMapBookmark("Georgia", New ESRI.ArcGIS.Client.Geometry.Envelope(-9633752, 3534963, -8898290, 4195229))) ElseIf theTag = "FL" Then ' Generate MapBookmark's for a local level of viewing. theBookmarks.Add(MakeMapBookmark("Jacksonville", New ESRI.ArcGIS.Client.Geometry.Envelope(-9105796, 3532477, -9075555, 3559626))) theBookmarks.Add(MakeMapBookmark("Miami", New ESRI.ArcGIS.Client.Geometry.Envelope(-8936736, 2965084, -8918792, 2981193))) theBookmarks.Add(MakeMapBookmark("Tampa", New ESRI.ArcGIS.Client.Geometry.Envelope(-9194994, 3225279, -9165864, 3251430))) ElseIf theTag = "GA" Then ' Generate MapBookmark's for a local level of viewing. theBookmarks.Add(MakeMapBookmark("Atlanta", New ESRI.ArcGIS.Client.Geometry.Envelope(-9421000, 3975108, -9367812, 4022858))) theBookmarks.Add(MakeMapBookmark("Columbus", New ESRI.ArcGIS.Client.Geometry.Envelope(-9464616, 3820843, -9455555, 3828978))) theBookmarks.Add(MakeMapBookmark("Savannah", New ESRI.ArcGIS.Client.Geometry.Envelope(-9043472, 3757220, -9013688, 3783958))) End If ' Return the ObservableCollection(Of MapBookmark) to the caller. Return theBookmarks End Function Public Function MakeMapBookmark(ByVal aName As String, ByVal anExtent As ESRI.ArcGIS.Client.Geometry.Envelope) As ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark ' A helper function to create a single MapBookmark based upon an input Name and Extent. Dim aMapBookmark As New ESRI.ArcGIS.Client.Toolkit.Bookmark.MapBookmark aMapBookmark.Name = aName aMapBookmark.Extent = anExtent ' Return the MapBookmark to the caller. Return aMapBookmark End Function |
The Bookmark.Bookmarks Property gets a ReadOnly ObservableCollection(Of Bookmark.MapBookmark) object. This object is used to store the named Map.Extent pairs (aka. bookmarks) that are displayed in the DataGrid sub-component of the Bookmark Control. When a Bookmark Control is created, the ObservableCollection (Of MapBookmark) object is also created. Although the MapBookmark.Bookmarks Property is ReadOnly, meaning you can only get the ObservableCollection (Of MapBookmark) object, you can use the regular ObservableCollection Members to like: Add, Clear, Remove, etc. to define how the Bookmark Control behaves. NOTE: You cannot create an new instance of the ObservableCollection (Of MapBookmark) object and set it to the Bookmark.Bookmarks Property, use the ObservableCollection.Add Property instead.
You can also control the behavior of the ObservableCollection (Of MapBookmark) object by using the AddBookmark, ClearBookmarks, and DeleteBookmarkAt Methods.
By default the ESRI.ArcGIS.Client.Toolkit.Bookmark.UseIsolatedStorage value equals True. This means that the application will remember from one session to another the named Map.Extent (aka. a bookmark) values previously entered. If the Bookmark.UseIsolatedStorage is set to False, the next time a user begins another client session of the application the named Map.Extent (aka. a bookmark) settings will be lost. Note: There is only one IsolatedStorage container per application. This may have implications if you have multiple Maps, each with their own set of bookmarks. This means you may need to make use of the Bookmark.Bookmarks Property to persist across the various Maps.
Target Platforms: Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family