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
}
}
Solved! Go to Solution.
Finally i get the result But does this code replace my drawing polygons and ,markers also which i m going to put in future in this code?? I just want to change basemap with my secured map here.. Can anyone tell me that i am going right way function chooseBasemap() {
var credential = ArcGISRuntimeEnvironment.createObject("Credential", { token: Backend.getMapToken() });
var securityPortal = ArcGISRuntimeEnvironment.createObject("Portal", { credential: credential });
var item = ArcGISRuntimeEnvironment.createObject("PortalItem", { portal: securityPortal, itemId: tItemId });
mapView.map= ArcGISRuntimeEnvironment.createObject("Map", { item: item });
}
i am also trying this way: but nothing shows on screen
function chooseBasemap() {
console.log(ArcGISRuntimeEnvironment.createObject("Map", {portal: portal,itemId: itemID}));
mapView.map = ArcGISRuntimeEnvironment.createObject("Map", {portal: portal,itemId: itemID});
}
Finally i get the result But does this code replace my drawing polygons and ,markers also which i m going to put in future in this code?? I just want to change basemap with my secured map here.. Can anyone tell me that i am going right way function chooseBasemap() {
var credential = ArcGISRuntimeEnvironment.createObject("Credential", { token: Backend.getMapToken() });
var securityPortal = ArcGISRuntimeEnvironment.createObject("Portal", { credential: credential });
var item = ArcGISRuntimeEnvironment.createObject("PortalItem", { portal: securityPortal, itemId: tItemId });
mapView.map= ArcGISRuntimeEnvironment.createObject("Map", { item: item });
}
I think that is correct, you could probably re-use the Portal and Credential object that you already have.
Tagging ArcGIS Runtime SDK for Qt to see if there is a better way to solve this.