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 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
- The user is prompted to load a portal anonymously or with a log-in.
- A
Portalis then loaded - if the user chose to log-in in step 1, this uses aCredentialof type OAuth. - When the app starts, the portal is loaded and if required, the
AuthenticationManagerissues a challenge for the supplied credential type. - The user is presented with an
Authenticatorwhich allows them to log-in. - After a successful load, get the list of basemaps:
portal::fetchBasemapsAsync()
Relevant API
- Portal
- Portal::fetchBasemapsAsync
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
// [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
// sample headers#include "ShowOrgBasemaps.h"
// ArcGIS Maps SDK headers#include "Authentication/OAuthUserConfiguration.h"#include "Basemap.h"#include "BasemapListModel.h"#include "Error.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "Portal.h"#include "PortalInfo.h"
// Qt headers#include <QFuture>
// Other headers#include "OAuthUserConfigurationManager.h"
using namespace Esri::ArcGISRuntime;using namespace Esri::ArcGISRuntime::Authentication;using namespace Esri::ArcGISRuntime::Toolkit;
ShowOrgBasemaps::ShowOrgBasemaps(QQuickItem* parent /* = nullptr */): QQuickItem(parent){}
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::connectLoadStatusSignal(){ if (m_portal) { connect(m_portal, &Portal::loadStatusChanged, this, [this]() { m_portalLoaded = m_portal->loadStatus() == LoadStatus::Loaded; m_portalLoading = m_portal->loadStatus() == LoadStatus::Loading;
emit portalLoadedChanged(); emit portalLoadingChanged(); emit orgNameChanged();
if (m_portalLoaded) { m_portal->fetchBasemapsAsync().then(this, [this]() { emit basemapsChanged(); }); } }); }
// find QML MapView component m_mapView = findChild<MapQuickView*>("mapView");}
bool ShowOrgBasemaps::portalLoaded() const{ return m_portalLoaded;}
bool ShowOrgBasemaps::portalLoading() const{ return m_portalLoading;}
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) { delete m_portal; m_portal = nullptr; }
const bool loginRequired = !anonymous; m_portal = new Portal(loginRequired, this); connectLoadStatusSignal();
if (loginRequired) { const QString redirectUrl{"urn:ietf:wg:oauth:2.0:oob"}; OAuthUserConfiguration* config = new OAuthUserConfiguration(m_portal->url(), "iLkGIj0nX8A4EJda", redirectUrl, this); OAuthUserConfigurationManager::addConfiguration(config); } else { OAuthUserConfigurationManager::clearConfigurations(); }
load();}
void ShowOrgBasemaps::load(){ if (!m_portal) return;
if (m_portal->loadStatus() == LoadStatus::FailedToLoad) m_portal->retryLoad(); else 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();}// [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]
#ifndef SHOWORGBASEMAPS_H#define SHOWORGBASEMAPS_H
// Qt headers#include <QAbstractListModel>#include <QQuickItem>
namespace Esri::ArcGISRuntime{ class BasemapListModel; class Map; class MapQuickView; class Portal;}
class ShowOrgBasemaps : public QQuickItem{ Q_OBJECT
Q_PROPERTY(bool portalLoaded READ portalLoaded NOTIFY portalLoadedChanged) Q_PROPERTY(bool portalLoading READ portalLoading NOTIFY portalLoadingChanged) Q_PROPERTY(QString orgName READ orgName NOTIFY orgNameChanged) Q_PROPERTY(QAbstractListModel* basemaps READ basemaps NOTIFY basemapsChanged) Q_PROPERTY(QString mapLoadError READ mapLoadError NOTIFY mapLoadErrorChanged)
public: explicit ShowOrgBasemaps(QQuickItem* parent = nullptr); ~ShowOrgBasemaps() override;
static void init();
bool portalLoaded() const; bool portalLoading() const; QString orgName() const; QAbstractListModel* basemaps() const; QString mapLoadError() const;
Q_INVOKABLE void load(bool anonymous); Q_INVOKABLE void loadSelectedBasemap(int index); Q_INVOKABLE void errorAccepted();
signals: void portalLoadedChanged(); void portalLoadingChanged(); void orgNameChanged(); void basemapsChanged(); void mapLoadErrorChanged();
private: void load(); void connectLoadStatusSignal();
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::Portal* m_portal = nullptr; bool m_portalLoaded = false; bool m_portalLoading = false; QString m_mapLoadError;};
#endif // SHOWORGBASEMAPS_H// [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]
import QtQuickimport QtQuick.Controlsimport Esri.Samplesimport Esri.ArcGISRuntime.Toolkit
ShowOrgBasemapsSample { width: 800 height: 600 clip: true
onPortalLoadedChanged: { gridFadeIn.running = true; }
BusyIndicator { anchors.centerIn: parent running: portalLoading }
Text { id: titleLabel 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 ? orgName + " Basemaps" : "Loading Organization Basemaps...") wrapMode: Text.Wrap elide: Text.ElideRight }
GridView { id: basemapsGrid anchors { top: titleLabel.bottom; bottom: parent.bottom; left: parent.left; right: parent.right } visible: portalLoaded cellWidth: 128; cellHeight: 128 opacity: 0 focus: true clip: true model: basemaps
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 ); source: thumbnailUrl // use the thumbnailUrl role of the model width: height fillMode: Image.PreserveAspectCrop }
Text { id: basemapLabel anchors { bottom: parent.bottom; left: parent.left; right: parent.right } height: 16 z: 100 wrapMode: Text.Wrap horizontalAlignment: Text.AlignHCenter elide: Text.ElideRight text: title // use the title role of the model font.pointSize: 8 font.bold: index === basemapsGrid.currentIndex } //! [BasemapListModel example QML delegate]
MouseArea { enabled: !mapView.visible && portalLoaded anchors.fill: parent
onClicked: { if (!enabled) return;
basemapsGrid.currentIndex = index; } onDoubleClicked: { if (!enabled) return;
selectedAnimation.running = true; titleLabel.text = title; loadSelectedBasemap(index); gridFadeOut.running = true; } }
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 } }
MapView { id: mapView objectName: "mapView" anchors { top: titleLabel.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 text: "Back" icon.source: "qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ic_menu_back_dark.png"
opacity: hovered ? 1 : 0.5
onClicked: { titleLabel.text = "Basemaps"; mapView.visible = false; basemapsGrid.enabled = true; gridFadeIn.running = true; } }
Button { id: anonymousLogIn anchors { margins: 16 horizontalCenter: parent.horizontalCenter top: titleLabel.bottom } text: "Anonymous" icon.source: "qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ic_menu_help_dark.png" visible: !portalLoaded
onClicked: { load(true); } }
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" visible: !portalLoaded
onClicked: { load(false); } }
// Declare Authenticator to handle any authentication challenges Authenticator { anchors.fill: parent }
}// [Legal]// Copyright 2015 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]
// Qt headers#include <QAbstractListModel>#include <QCommandLineParser>#include <QDir>#include <QGuiApplication>#include <QQmlEngine>#include <QQuickView>
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND#include <QtWebEngineQuick>#endif // QT_WEBVIEW_WEBENGINE_BACKEND
#ifdef Q_OS_WIN#include <Windows.h>#endif
#include "Esri/ArcGISRuntime/Toolkit/register.h"#include "ArcGISRuntimeEnvironment.h"
#include "ShowOrgBasemaps.h"
#define STRINGIZE(x) #x#define QUOTE(x) STRINGIZE(x)
int main(int argc, char *argv[]){ Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setUseLegacyAuthentication(false); QGuiApplication app(argc, argv); app.setApplicationName(QString("Show Org Basemaps"));
// Use of ArcGIS location services, such as basemap styles, geocoding, and routing services, // requires an access token. For more information see // https://links.esri.com/arcgis-runtime-security-auth.
// The following methods grant an access token:
// 1. User authentication: Grants a temporary access token associated with a user's ArcGIS account. // To generate a token, a user logs in to the app with an ArcGIS account that is part of an // organization in ArcGIS Online or ArcGIS Enterprise.
// 2. API key authentication: Get a long-lived access token that gives your application access to // ArcGIS location services. Go to the tutorial at https://links.esri.com/create-an-api-key. // Copy the API Key access token.
const QString accessToken = QString("");
if (accessToken.isEmpty()) { qWarning() << "Use of ArcGIS location services, such as the basemap styles service, requires" << "you to authenticate with an ArcGIS account or set the API Key property."; } else { Esri::ArcGISRuntime::ArcGISRuntimeEnvironment::setApiKey(accessToken); }
#ifdef QT_WEBVIEW_WEBENGINE_BACKEND QtWebEngineQuick::initialize();#endif // QT_WEBVIEW_WEBENGINE_BACKEND
// Initialize the sample ShowOrgBasemaps::init();
// Initialize application view QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView);
// Add the import Path view.engine()->addImportPath(QDir(QCoreApplication::applicationDirPath()).filePath("qml"));
QString arcGISRuntimeImportPath = QUOTE(ARCGIS_RUNTIME_IMPORT_PATH);
#if defined(LINUX_PLATFORM_REPLACEMENT) // on some linux platforms the string 'linux' is replaced with 1 // fix the replacement paths which were created QString replaceString = QUOTE(LINUX_PLATFORM_REPLACEMENT); arcGISRuntimeImportPath = arcGISRuntimeImportPath.replace(replaceString, "linux", Qt::CaseSensitive); #endif
// Add the Runtime and Extras path view.engine()->addImportPath(arcGISRuntimeImportPath);
Esri::ArcGISRuntime::Toolkit::registerComponents(*(view.engine()));
// Set the source view.setSource(QUrl("qrc:/Samples/CloudAndPortal/ShowOrgBasemaps/ShowOrgBasemaps.qml"));
view.show();
return app.exec();}