View in QML C++ View on GitHub Sample viewer app
Connect to Portal to give users access to their organization's basemaps.
Use case
Organizational basemaps are a Portal feature allowing organizations to specify basemaps for use throughout the organization. Customers expect that they will have access to their organization's standard basemap set when they connect to a Portal. Organizational basemaps are useful when certain basemaps are particularly relevant to the organization, or if the organization wants to make premium basemap content available to their workers.
How to use the sample
You'll be prompted to provide a URL to your Portal, then sign in. After you sign in, you'll see a map and a list of basemaps to choose from. Select a basemap to use it in the map.
How it works
The user is prompted to load a portal anonymously or with a log-in.
A Portal
is then loaded - if the user chose to log-in in step 1, this uses a Credential
of type OAuth.
When the app starts, the portal is loaded and if required, the AuthenticationManager
issues a challenge for the supplied credential type.
The user is presented with an AuthenticationView
which allows them to log-in.
After a successful load, a request is made to fetchBasemaps
from the portal instance.
When the basemaps are successfully retrieved, the portal's BasemapListModel
is passed to a QML GridView
.
A delegate shows each basemap's title
and thumbnail image.
When the user double-clicks on a Basemap
in the list, a Map
is created using this (unloaded) item.
The map is then loaded and once the operation is complete it is set on a MapView
to show the user's selected basemap.
A back button allows the user to return to the list of basemaps.
Relevant API
AuthenticationManager
BasemapListModel
Credential
Portal
See Customize basemaps in the Portal for ArcGIS documentation to learn about customizing the organization's basemap list in a portal.
basemap, integration, organization, portal
Sample CodeShowOrgBasemaps.qml
Use dark colors for code blocks Copy
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// [WriteFile Name=ShowOrgBasemapPicker, Category=CloudAndPortal]
// [Legal]
// 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.
// [Legal]
import QtQuick
import QtQuick.Controls
import Esri.ArcGISRuntime
import Esri.ArcGISRuntime.Toolkit
Rectangle {
id: rootRectangle
clip : true
width : 800
height : 600
property var porInfo : portal.portalInfo
function chooseBasemap ( selectedBasemap ) {
title.text = selectedBasemap.item.title;
basemapsGrid.enabled = false ;
const newMap = ArcGISRuntimeEnvironment.createObject( "Map" , { item : selectedBasemap.item});
mapView.map = newMap;
gridFadeOut.running = true ;
mapView.visible = true ;
}
BusyIndicator {
anchors.centerIn : parent
running : !anonymousLogIn.visible && !mapView.visible && portal.loadStatus !== Enums.LoadStatusLoaded;
}
Credential {
id: oAuthCredential
oAuthClientInfo : OAuthClientInfo {
oAuthMode : Enums.OAuthModeUser
clientId : "iLkGIj0nX8A4EJda"
}
}
Portal {
id: portal
//! [Portal fetchBasemaps after loaded]
onLoadStatusChanged : {
if (loadStatus === Enums.LoadStatusFailedToLoad) {
retryLoad();
return ;
}
if (loadStatus !== Enums.LoadStatusLoaded)
return ;
fetchBasemaps();
}
onFetchBasemapsStatusChanged : {
if (fetchBasemapsStatus !== Enums.TaskStatusCompleted)
return ;
basemapsGrid.model = basemaps;
gridFadeIn.running = true ;
}
//! [Portal fetchBasemaps after loaded]
}
Text {
id: title
anchors {
top : parent .top;
left : parent .left;
right : parent .right;
margins : 10
}
font.pointSize : 14
font.bold : true
horizontalAlignment : Text.AlignHCenter
verticalAlignment : Text.AlignTop
text : anonymousLogIn.visible ? "Load Portal" :
(basemapsGrid.count > 0 ? porInfo.organizationName + " Basemaps" : "Loading Organization Basemaps..." )
wrapMode : Text.Wrap
elide : Text.ElideRight
}
MapView {
id: mapView
anchors {
top : title.bottom;
bottom : parent .bottom;
left : parent .left;
right : parent .right
}
visible : false
Component.onCompleted : {
// Set the focus on MapView to initially enable keyboard navigation
forceActiveFocus();
}
}
Button {
id: backButton
anchors {
top : mapView.top
right : mapView.right
margins : 16
}
visible : mapView.visible
icon.source : "qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ic_menu_back_dark.png"
text : "Back"
opacity : hovered ? 1 : 0.5
onClicked : {
title.text = "Basemaps" ;
mapView.visible = false ;
basemapsGrid.enabled = true ;
gridFadeIn.running = true ;
}
}
GridView {
id: basemapsGrid
anchors {
top : title.bottom;
bottom : parent .bottom;
left : parent .left;
right : parent .right
}
cellWidth : 128 ;
cellHeight : 128
opacity : 0
focus : true
clip : true
delegate : Rectangle {
anchors.margins : 5
width : basemapsGrid.cellWidth
height : width
border {
width : 2 ;
color : index === basemapsGrid.currentIndex ? "blue" : "lightgrey"
}
color : index === basemapsGrid.currentIndex ? "yellow" : "white"
radius : 2
clip : true
//! [BasemapListModel example QML delegate]
Image {
id: basemapImg
anchors {
bottom : basemapLabel.top;
horizontalCenter : parent .horizontalCenter
}
height : parent .height - ( basemapLabel.height * 2 );
width : height
source : thumbnailUrl
fillMode : Image.PreserveAspectCrop
}
Text {
id: basemapLabel
anchors {
bottom : parent .bottom;
left : parent .left;
right : parent .right
}
height : 16
z : 100
horizontalAlignment : Text.AlignHCenter
text : title
wrapMode : Text.Wrap
elide : Text.ElideRight
font.pointSize : 8
font.bold : index === basemapsGrid.currentIndex
}
//! [BasemapListModel example QML delegate]
MouseArea {
enabled : !mapView.visible && portal.loadStatus === Enums.LoadStatusLoaded
anchors.fill : parent
onClicked : {
if (!enabled)
return ;
basemapsGrid.currentIndex = index;
}
onDoubleClicked : {
if (!enabled)
return ;
selectedAnimation.running = true ;
chooseBasemap(basemapsGrid.model.get(index));
}
}
SequentialAnimation on opacity {
id: selectedAnimation
running : false
loops : 4
PropertyAnimation { to : 0 ; duration : 60 }
PropertyAnimation { to : 1 ; duration : 60 }
}
}
OpacityAnimator on opacity {
id: gridFadeIn
from : 0 ;
to : 1 ;
duration : 2000
running : false
}
OpacityAnimator on opacity {
id: gridFadeOut
from : 1 ;
to : 0 ;
duration : 2000
running : false
}
}
Button {
id: anonymousLogIn
anchors {
margins : 16
horizontalCenter : parent .horizontalCenter
top : title.bottom
}
text : "Anonymous"
icon.source : "qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ic_menu_help_dark.png"
onClicked : {
portal.load();
anonymousLogIn.visible = false ;
userLogIn.visible = false ;
}
}
Button {
id: userLogIn
anchors {
margins : 16
horizontalCenter : anonymousLogIn.horizontalCenter
top : anonymousLogIn.bottom
}
width : anonymousLogIn.width
text : "Sign-in"
icon.source : "qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ic_menu_account_dark.png"
onClicked : {
portal.credential = oAuthCredential;
portal.load();
anonymousLogIn.visible = false ;
userLogIn.visible = false ;
}
}
// Declare AuthenticationView to handle any authentication challenges
AuthenticationView {
anchors.fill : parent
}
}