Apply basemap style parameters customization for a basemap, such as displaying all labels in a specific language or displaying every label in their corresponding local language.

Use case
When creating an application that’s used in multiple countries, basemaps can reflect the languages and cultures of the users’ location. For example, if an application user is in Greece, displaying the labels on a basemap in Greek reflects the local language. Customizing the language setting on the basemap can be controlled by an application user (such as by setting preferences), or implicitly managed within the application logic (by querying the locale of the platform running the application).
How to use the sample
This sample showcases the workflow of configuring basemap style parameters by displaying a basemap with labels in different languages and launches with a Viewpoint near Bulgaria, Greece, and Turkey, as they use three different alphabets: Cyrillic, Greek, and Latin, respectively. By default, the BasemapStyleLanguageStrategy is set to LOCAL, which displays all labels in their corresponding local language. This can be changed to GLOBAL, which displays all labels in English. The SpecificLanguage setting sets all labels to a selected language and overrides the BasemapStyleLanguageStrategy settings.
Pan and zoom to navigate the map and see how different labels are displayed in these countries depending on the selected BasemapStyleLanguageStrategy and SpecificLanguage: all English, all Greek, all Bulgarian, all Turkish, or each their own.
How it works
- Create a
BasemapStyleParametersobject. - Configure customisation preferences on the
BasemapStyleParametersobject, for instance:- setting the
LanguageStrategytoBasemapStyleLanguageStrategy.LOCALor setSpecificLanguage("el")changes the label language to Greek.
- setting the
- The
SpecificLanguagealways overrides theLanguageStrategy, which means the specific language needs to be set to an empty string in order to use the language strategy. - Create a basemap using a
BasemapStyleand theBasemapStyleParameters. - Assign the configured basemap to the
Map’sbasemapproperty. - To modify the basemap style, for example if you want to change your preferences, repeat the above steps.
Relevant API
- Basemap
- BasemapStyleLanguageStrategy
- BasemapStyleParameters
- Map
- MapView
About the data
The main data for this sample is the BasemapStyle, which includes basemaps that support both language localization and global language setting. The supported languages, along with their language code, can be found in the API’s documentation.
Additional information
For ArcGIS Basemap styles, language localization becomes visible when you zoom in closer.
Tags
basemap style, language, language strategy, map, point, viewpoint
Sample code
// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]// [Legal]// Copyright 2024 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 "ConfigureBasemapStyleLanguage.h"
// ArcGIS Maps SDK headers#include "Basemap.h"#include "BasemapStyleParameters.h"#include "Map.h"#include "MapQuickView.h"#include "MapTypes.h"#include "Point.h"#include "SpatialReference.h"#include "Viewpoint.h"
// Qt headers#include <QFuture>
using namespace Esri::ArcGISRuntime;
ConfigureBasemapStyleLanguage::ConfigureBasemapStyleLanguage(QObject* parent /* = nullptr */) : QObject(parent), m_map(new Map(SpatialReference::webMercator(), this)), m_basemapStyleParameters(new BasemapStyleParameters(this)){}
ConfigureBasemapStyleLanguage::~ConfigureBasemapStyleLanguage() = default;
void ConfigureBasemapStyleLanguage::init(){ // Register the map view for QML qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView"); qmlRegisterType<ConfigureBasemapStyleLanguage>("Esri.Samples", 1, 0, "ConfigureBasemapStyleLanguageSample");}
MapQuickView* ConfigureBasemapStyleLanguage::mapView() const{ return m_mapView;}
// Set the view (created in QML)void ConfigureBasemapStyleLanguage::setMapView(MapQuickView* mapView){ if (!mapView || mapView == m_mapView) return;
m_mapView = mapView; m_mapView->setMap(m_map);
const Point point(3144804, 4904598);
// Create a Viewpoint object with the created Point and a scale of 10000000 const Viewpoint viewpoint(point, 10000000);
// Set the viewpoint for the mapView mapView->setViewpointAsync(viewpoint);
emit mapViewChanged();}
// Set new basemap language based on the parameters selectedvoid ConfigureBasemapStyleLanguage::setNewBasemapLanguage(bool global, const QString& language){ m_basemapStyleParameters->setLanguageStrategy(global ? BasemapStyleLanguageStrategy::Global : BasemapStyleLanguageStrategy::Local);
// A SpecificLanguage setting overrides the LanguageStrategy settings if (language == "none") { m_basemapStyleParameters->setSpecificLanguage(""); } else if (language == "Bulgarian") { m_basemapStyleParameters->setSpecificLanguage("bg"); } else if (language == "Greek") { m_basemapStyleParameters->setSpecificLanguage("el"); } else if (language == "Turkish") { m_basemapStyleParameters->setSpecificLanguage("tr"); }
if (m_basemap) { m_basemap->deleteLater(); }
m_basemap = new Basemap(BasemapStyle::ArcGISLightGray, m_basemapStyleParameters, this); m_map->setBasemap(m_basemap);}// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]// [Legal]// Copyright 2024 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 CONFIGUREBASEMAPSTYLELANGUAGE_H#define CONFIGUREBASEMAPSTYLELANGUAGE_H
// Qt headers#include <QObject>
namespace Esri::ArcGISRuntime { class Basemap; class BasemapStyleParameters; class Map; class MapQuickView;}
Q_MOC_INCLUDE("MapQuickView.h");
class ConfigureBasemapStyleLanguage : public QObject{ Q_OBJECT
Q_PROPERTY(Esri::ArcGISRuntime::MapQuickView* mapView READ mapView WRITE setMapView NOTIFY mapViewChanged)
public: explicit ConfigureBasemapStyleLanguage(QObject* parent = nullptr); ~ConfigureBasemapStyleLanguage() override;
static void init(); Q_INVOKABLE void setNewBasemapLanguage(bool global, const QString& language);
signals: void mapViewChanged();
private: Esri::ArcGISRuntime::MapQuickView* mapView() const; void setMapView(Esri::ArcGISRuntime::MapQuickView* mapView);
Esri::ArcGISRuntime::Map* m_map = nullptr; Esri::ArcGISRuntime::MapQuickView* m_mapView = nullptr; Esri::ArcGISRuntime::BasemapStyleParameters* m_basemapStyleParameters = nullptr; Esri::ArcGISRuntime::Basemap* m_basemap = nullptr;};
#endif // CONFIGUREBASEMAPSTYLELANGUAGE_H// [WriteFile Name=ConfigureBasemapStyleLanguage, Category=Maps]// [Legal]// Copyright 2024 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.Samples
Item {
// add a mapView component MapView { id: view anchors.fill: parent
Component.onCompleted: { // Set the focus on MapView to initially enable keyboard navigation forceActiveFocus(); } }
// Declare the C++ instance which creates the map etc. and supply the view ConfigureBasemapStyleLanguageSample { id: model mapView: view }
Rectangle { id: rectangle anchors { right: parent.right top: parent.top margins: 15 } width: column.width height: column.height color: Qt.rgba(0, 0, 0, 0.5) border { color: "black" width: 1 } opacity: 0.9
Column { id: column padding: 10 spacing: 5 width: 300
Column { id:languageStrategy spacing: 5
Text { text: "Set Language Strategy:" font.bold: true color: "white" }
Row { RadioButton { id: globalButton onCheckedChanged: { model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText); localButton.checked = !globalButton.checked } enabled: comboBox.currentText == "none" }
Text { id: globalText text: "Global" height: globalButton.height verticalAlignment: Text.AlignVCenter color: "white" } }
Row { RadioButton { id: localButton checked: true onCheckedChanged: { model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText); globalButton.checked = !localButton.checked } enabled: comboBox.currentText == "none" } Text { id: localText text: "Local" height: localButton.height verticalAlignment: Text.AlignVCenter color: "white" } }
}
Column { id:specificLanguage
Text { text: "Set Specific Language:" font.bold: true color: "white" }
ComboBox { id: comboBox model: ["none" , "Bulgarian", "Greek", "Turkish"] // onCurrentTextChanged executes when the text is changed and also initially on loading the sample onCurrentTextChanged: model.setNewBasemapLanguage(globalButton.checked, comboBox.currentText); } } } }}