forked from Esri/arcgis-maps-sdk-dotnet-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManageBookmarksVB.xaml.vb
149 lines (108 loc) · 5.64 KB
/
ManageBookmarksVB.xaml.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
' Copyright 2016 Esri.
'
' Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
' You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
'
' Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
' language governing permissions and limitations under the License.
Imports Esri.ArcGISRuntime.Mapping
Namespace ManageBookmarks
Partial Public Class ManageBookmarksVB
Public Sub New()
InitializeComponent()
' Create the UI, setup the control references and execute initialization
Initialize()
End Sub
Private Sub Initialize()
' Create new map with a base map
Dim myMap As New Map(Basemap.CreateImageryWithLabels())
' Set the map view, map property to the base map
MyMapView.Map = myMap
' Create a set of predefined bookmarks; each one follows the pattern of:
' ~ Initialize a viewpoint pointing to a latitude longitude
' ~ Create a new bookmark
' ~ Give the bookmark a name
' ~ Assign the viewpoint
' ~ Add the bookmark to bookmark collection of the map
' ~ Add the bookmark to the UI combobox for the user to choose from
' Bookmark-1
Dim myViewpoint1 As New Viewpoint(27.3805833, 33.6321389, 6000)
Dim myBookmark1 As New Bookmark()
myBookmark1.Name = "Mysterious Desert Pattern"
myBookmark1.Viewpoint = myViewpoint1
MyMapView.Map.Bookmarks.Add(myBookmark1)
bookmarkChooser.Items.Add(myBookmark1)
' Bookmark-2
Dim myViewpoint2 As New Viewpoint(37.401573, -116.867808, 6000)
Dim myBookmark2 As New Bookmark()
myBookmark2.Name = "Strange Symbol"
myBookmark2.Viewpoint = myViewpoint2
MyMapView.Map.Bookmarks.Add(myBookmark2)
bookmarkChooser.Items.Add(myBookmark2)
' Bookmark-3
Dim myViewpoint3 As New Viewpoint(-33.867886, -63.985, 40000)
Dim myBookmark3 As New Bookmark()
myBookmark3.Name = "Guitar-Shaped Forest"
myBookmark3.Viewpoint = myViewpoint3
MyMapView.Map.Bookmarks.Add(myBookmark3)
bookmarkChooser.Items.Add(myBookmark3)
' Bookmark-4
Dim myViewpoint4 As New Viewpoint(44.525049, -110.83819, 6000)
Dim myBookmark4 As New Bookmark()
myBookmark4.Name = "Grand Prismatic Spring"
myBookmark4.Viewpoint = myViewpoint4
MyMapView.Map.Bookmarks.Add(myBookmark4)
bookmarkChooser.Items.Add(myBookmark4)
' Set the initial combo box selection to the last bookmark added
bookmarkChooser.SelectedItem = MyMapView.Map.Bookmarks.Last()
' Zoom to the last bookmark.
myMap.InitialViewpoint = myMap.Bookmarks.Last().Viewpoint
' Hide the controls for adding an additional bookmark
BorderAddBookmark.Visibility = Visibility.Collapsed
End Sub
Private Sub OnBookmarkChooserSelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
' Get the selected bookmark And apply the view point to the map
Dim selectedBookmark = TryCast(e.AddedItems(0), Bookmark)
MyMapView.SetViewpoint(selectedBookmark.Viewpoint)
End Sub
Private Sub ButtonAddBookmark_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Show the controls to add a bookmark
BorderAddBookmark.Visibility = Visibility.Visible
ButtonAddBookmark.Visibility = Visibility.Collapsed
TextBoxBookmarkName.Text = ""
End Sub
Private Sub ButtonCanel_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Hide the controls to add a bookmark
BorderAddBookmark.Visibility = Visibility.Collapsed
ButtonAddBookmark.Visibility = Visibility.Visible
End Sub
Private Sub ButtonAddDone_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Get the name from the text field
Dim name = TextBoxBookmarkName.Text
' Exit if the name is empty
If String.IsNullOrEmpty(name) Then
Return
End If
' Check to see if there is a bookmark with same name
Dim doesNameExist As Boolean = MyMapView.Map.Bookmarks.Any(Function(b) b.Name = name)
If doesNameExist Then
Return
End If
' Create a new bookmark
Dim myBookmark As New Bookmark()
myBookmark.Name = name
' Get the current viewpoint from map and assign it to bookmark
myBookmark.Viewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry)
' Add the bookmark to bookmark collection of the map
MyMapView.Map.Bookmarks.Add(myBookmark)
' Add the bookmark name to the list of choices in the combo box
bookmarkChooser.Items.Add(myBookmark)
' Set the newly added bookmark to be the one selected in the combo box
bookmarkChooser.SelectedItem = myBookmark
' Hide the controls to add a bookmark
BorderAddBookmark.Visibility = Visibility.Collapsed
ButtonAddBookmark.Visibility = Visibility.Visible
End Sub
End Class
End Namespace