AnsweredAssumed Answered

change basemap through token and item id

Question asked by rajni_sharma on Jul 27, 2020
Latest reply on Jul 30, 2020 by ESoekianto-esristaff

I have been trying to access my private topological basemap in my app through btn click  and calling chooseBasemap(); fnc.

But it does not load my basemap. screen goes blank

this is my code below:

import QtQuick 2.13
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13
import QtPositioning 5.8
import QtLocation 5.9
import ArcGIS.AppFramework 1.0
import Esri.ArcGISRuntime 100.6
import "../assets/js/backend.js" as Backend
import "../controls" as Controls
Page {
    id: app
    property string itemID: "my map id"
    property string tItemId:"topo map id"
     property real scaleFactor: AppFramework.displayScaleFactor
    width: parent.width
    height: parent.height
    MapView {
        id:mapView
        property real initialMapRotation: 0
        anchors {
            left: parent.left
            right: parent.right
            top: parent.top
            bottom: parent.bottom
        }
        rotationByPinchingEnabled: true
        zoomByPinchingEnabled: true
    // add a basemap
    Map {
        id:map
        item: PortalItem {
            portal: portal
            itemId: itemID
        }
        }
    }//End Mapview
    //! [PortalUserInfo create portal]
    Portal {
        id: portal
        credential: Credential {
             token: Backend.getMapToken()
        }
        Component.onCompleted: {
            load();
            //fetchLicenseInfo();
        }
        onLoadStatusChanged: {
            if (loadStatus === Enums.LoadStatusFailedToLoad)
                retryLoad();
        }
    }
    Row{
        anchors.horizontalCenter: parent.horizontalCenter
        //anchors.margins: 70 * scaleFactor
        spacing:3
        leftPadding: 120
        topPadding: 15
        Controls.Kbutton {
            id: satellitebtn
            width: 100
            text: qsTr("SATELLITE")
            font.weight: Font.Bold
            Layout.alignment: Qt.AlignHCenter
            Layout.preferredWidth: 100
            borderColor: "#ff7919"
            font.pixelSize: 14
            Layout.preferredHeight: 40
            baseColor: "#FF7919"
            textColor: "#FFFFFF"
            onClicked: {
                    map.basemap = ArcGISRuntimeEnvironment.createObject("BasemapImagery");
            }
        }
        Controls.Kbutton {
            id: topobtn
            width: 88
            text: qsTr("TOPO")
            font.weight: Font.Bold
            Layout.alignment: Qt.AlignHCenter
            Layout.preferredWidth: 100
            borderColor: "#ffffff"
            font.pixelSize: 14
            Layout.preferredHeight: 40
            baseColor: "#ffffff"
            textColor: "#333333"
            onClicked: {
                chooseBasemap();
            }
        }
        Image {
            id: group1
            source: "../assets/images/Group1.png"
            height: 60
            width: 60
        }
    }
    Row{
   topPadding: 70
   leftPadding: 315
   anchors.horizontalCenter: parent.horizontalCenter
    Image {
        id: group2
        source: "../assets/images/Group22.png"
        height: 60
        width: 60
    }
    }
    function chooseBasemap() {
        var newMap = ArcGISRuntimeEnvironment.createObject("Map", {basemap: tItemId});
        mapView.map = newMap;
        mapView.visible = true;
    }
    footer: Controls.Kfooter {
         id:footer
     }
}

Outcomes