Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for Qt

Change basemap

Sample Viewer View Sample on GitHub

Change a map's basemap. A basemap is beneath all layers on an Map and is used to provide visual reference for the operational layers.

Use case

Basemaps should selected contextually, for example, in maritime applications, it would be more appropriate to use a basemap of the world's oceans as opposed to a basemap of the world's streets.

How to use the sample

Use the drop down menu to select the active basemap from the list of available basemaps.

How it works

  1. Create a Map.
  2. Set the map to the MapView.
  3. Choose a new basemap type and set it on the map.

Relevant API

  • Map
  • Basemap
  • MapView

Tags

basemap, map

Sample Code

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.ArcGISRuntime 100.9

Rectangle {
    width: 800
    height: 600

    // Create MapView that contains a Map
    MapView {
        anchors.fill: parent
        Map {
            id: map
            // Set the initial basemap to Topographic
            BasemapTopographic {}
        }
    }

    ComboBox {
        id: comboBoxBasemap
        anchors {
            left: parent.left
            top: parent.top
            margins: 5
        }
        property int modelWidth: 0
        width: modelWidth + leftPadding + rightPadding + indicator.width
        textRole: "text"
        model: ListModel {
            ListElement { text: "Topographic"; map: "BasemapTopographic" }
            ListElement { text: "Streets"; map: "BasemapStreets" }
            ListElement { text: "Streets (Vector)"; map: "BasemapStreetsVector" }
            ListElement { text: "Streets - Night (Vector)"; map: "BasemapStreetsNightVector" }
            ListElement { text: "Imagery (Raster)"; map: "BasemapImagery" }
            ListElement { text: "Imagery with Labels (Raster)"; map: "BasemapImageryWithLabels" }
            ListElement { text: "Imagery with Labels (Vector)"; map: "BasemapImageryWithLabelsVector" }
            ListElement { text: "Dark Gray Canvas (Vector)"; map: "BasemapDarkGrayCanvasVector" }
            ListElement { text: "Light Gray Canvas (Raster)"; map: "BasemapLightGrayCanvas" }
            ListElement { text: "Light Gray Canvas (Vector)"; map: "BasemapLightGrayCanvasVector" }
            ListElement { text: "Navigation (Vector)"; map: "BasemapNavigationVector" }
            ListElement { text: "OpenStreetMap (Raster)"; map: "BasemapOpenStreetMap" }
            ListElement { text: "Oceans"; map: "BasemapOceans" }
        }

        Component.onCompleted : {
            for (let i = 0; i < model.count; ++i) {
                metrics.text = model.get(i).text;
                modelWidth = Math.max(modelWidth, metrics.width);
            }
        }

        TextMetrics {
            id: metrics
            font: comboBoxBasemap.font
        }

        onCurrentIndexChanged: {
            // Call this JavaScript function when the current selection changes
            if (map.loadStatus === Enums.LoadStatusLoaded)
                changeBasemap(model.get(currentIndex).map);
        }

        function changeBasemap(type) {
            map.basemap = ArcGISRuntimeEnvironment.createObject(type);
        }
    }
}