Show organization basemaps

View inC++QMLView on GitHubSample viewer app

Connect to Portal to give users access to their organization's basemaps.

screenshot

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 load a portal anonymously or with a log-in. After you sign in, you'll see thumbnails for these basemaps shown in a picker. Select a basemap to use it in the map.

How it works

  1. The user is prompted to load a portal anonymously or with a log-in.
  2. A Portal is then loaded - if the user chose to log-in in step 1, this uses a Credential of type OAuth.
  3. When the app starts, the portal is loaded and if required, the AuthenticationManager issues a challenge for the supplied credential type.
  4. The user is presented with an AuthenticationView which allows them to log-in.
  5. After a successful load, get the list of basemaps: portal::fetchBasemaps()

Relevant API

  • Portal
  • Portal::fetchBasemaps

Additional information

See Customize basemaps in the Portal for ArcGIS documentation to learn about customizing the organization's basemap list in a portal.

Tags

basemap, integration, organization, portal

Sample Code

ShowOrgBasemaps.cppShowOrgBasemaps.cppShowOrgBasemaps.hShowOrgBasemaps.qml
Use dark colors for code blocksCopy
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
// [WriteFile Name=ShowOrgBasemaps, 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]

#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD

#include "AuthenticationManager.h"
#include "Map.h"
#include "MapQuickView.h"
#include "Basemap.h"
#include "BasemapListModel.h"
#include "Portal.h"
#include "ShowOrgBasemaps.h"
#include "MapTypes.h"
#include "CoreTypes.h"
#include "Credential.h"
#include "OAuthClientInfo.h"
#include "Error.h"
#include "PortalInfo.h"

using namespace Esri::ArcGISRuntime;

ShowOrgBasemaps::ShowOrgBasemaps(QQuickItem* parent /* = nullptr */):
  QQuickItem(parent),
  m_portal(new Portal(this))
{
  AuthenticationManager::instance()->setCredentialCacheEnabled(false);
}

ShowOrgBasemaps::~ShowOrgBasemaps() = default;

void ShowOrgBasemaps::init()
{
  qmlRegisterUncreatableType<QAbstractListModel>("Esri.Samples", 1, 0, "AbstractListModel", "AbstractListModel is uncreateable");
  qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
  qmlRegisterType<ShowOrgBasemaps>("Esri.Samples", 1, 0, "ShowOrgBasemapsSample");
}


void ShowOrgBasemaps::componentComplete()
{
  QQuickItem::componentComplete();

  if (m_portal)
  {
    connect(m_portal, &Portal::loadStatusChanged, this, [this]()
    {
      m_portalLoaded = m_portal->loadStatus() == LoadStatus::Loaded;

      emit portalLoadedChanged();
      emit orgNameChanged();

      if (m_portalLoaded)
        m_portal->fetchBasemaps();
    });

    connect(m_portal, &Portal::basemapsChanged, this, [this]()
    {
      emit basemapsChanged();
    });
  }

  // find QML MapView component
  m_mapView = findChild<MapQuickView*>("mapView");
}

bool ShowOrgBasemaps::portalLoaded() const
{
  return m_portalLoaded;
}

QString ShowOrgBasemaps::orgName() const
{
  if (!m_portalLoaded || !m_portal || !m_portal->portalInfo())
    return QString();

  return m_portal->portalInfo()->organizationName();
}

QAbstractListModel* ShowOrgBasemaps::basemaps() const
{
  return m_portal ? m_portal->basemaps() : nullptr;
}

QString ShowOrgBasemaps::mapLoadError() const
{
  return m_mapLoadError;
}

void ShowOrgBasemaps::load(bool anonymous)
{
  if (!m_portal)
    return;

  if (anonymous)
    m_portal->load();
  else {
    Credential* cred = new Credential(OAuthClientInfo("iLkGIj0nX8A4EJda", OAuthMode::User), this);
    m_portal->setCredential(cred);
    m_portal->load();
  }
}

void ShowOrgBasemaps::loadSelectedBasemap(int index)
{
  if (!m_portal || !m_portal->basemaps())
    return;

  Basemap* selectedBasemap = m_portal->basemaps()->at(index);
  if (!selectedBasemap)
    return;

  if (m_map)
  {
    delete m_map;
    m_map = nullptr;
  }

  m_mapLoadError.clear();
  emit mapLoadErrorChanged();

  m_map = new Map(selectedBasemap->item(), this);

  connect(m_map, &Map::errorOccurred, this, [this]()
  {
    m_mapLoadError = m_map->loadError().message();
    emit mapLoadErrorChanged();
  });

  connect(m_map, &Map::loadStatusChanged, this, [this]()
  {
    if (!m_map || m_map->loadStatus() != LoadStatus::Loaded)
      return;

    m_mapView->setMap(m_map);
    m_mapView->setVisible(true);
  });

  m_map->load();
}

void ShowOrgBasemaps::errorAccepted()
{
  m_mapLoadError.clear();
  emit mapLoadErrorChanged();
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.