I have this block of code
MapView{
id:mapView
anchors.fill: parent
Component.onCompleted: {mapView.map = ArcGISRuntimeEnvironment.createObject("Map", {"initUrl": 'https://www.arcgis.com/home/item.html?id=c74acddfcb1844eb90f8f9d40be2c823'});
}
}
I want to create a map within mapView but the result is just a gray screen. Is there a correct method of doing this? Because I will need to be able to create x amount of maps. And can't declare each one specifically.
Hi Kyle,
Is your web map secured or public?
Tina
its secure
Hi Kyle,
You will need to write a sign in logic to access the secured content. You can reference to Map Viewer template source code.
Thanks,
Tina
Where specifically? It's a pretty large file to dig through code to find an example of how to properly login.
I am already authenticating before invoking the command.
Hi Kyle,
If you are looking to add a secured web map to your application. You need to create a Portal QML type object with credentials and then load the PortalItem which is a webmap within the MapView.
Here is the code snippet. Please replace the item id and correct credentials to make it work. I hope this helps.
Nakul
import QtQuick 2.7
import QtQuick.Controls 2.2
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import Esri.ArcGISRuntime 100.3
App {
id: app
width: 400
height: 640
Portal{
id:portal
url:"http://www.arcgis.com"
credential: Credential{
username: "username"
password: "password"
}
onErrorChanged: {
if (loadStatus === Enums.LoadStatusFailedToLoad)
console.log(error.message);
}
}
MapView{
id:mapView
anchors.fill: parent
Map{
item: PortalItem{
portal: portal
itemId: "45641addba21436aa90fc3e79ffe158f"
}
onErrorChanged: {
if (loadStatus === Enums.LoadStatusFailedToLoad)
console.log(error.message);
}
}
}
}
Alternatively, you can do the same with JavaScript too
function loadSecuredWebMapwithCredentials() {
var credential = ArcGISRuntimeEnvironment.createObject("Credential", { username: "username", password: "password" });
securityPortal = ArcGISRuntimeEnvironment.createObject("Portal", { url: "http://www.arcgis.com", credential: credential });
var item = ArcGISRuntimeEnvironment.createObject("PortalItem", { portal: securityPortal, itemId: "45641addba21436aa90fc3e79ffe158f" });
return ArcGISRuntimeEnvironment.createObject("Map", { item: item });
}
I tried this, I get an error back
qml: 7003
qml: Invalid response
qml: Portal item type incorrect
It works as
Map{
initUrl: "http://someurl"
}
Hence why I tried to create a map object with the initUrl
Couple of problems here
1) This webmap is very old (1.7) and not supported by Runtime. Runtime only supports webmaps v2.0 or higher. https://www.arcgis.com/home/item.html?id=c74acddfcb1844eb90f8f9d40be2c823
If you run the above code with this item id "c74acddfcb1844eb90f8f9d40be2c823" it should throw you an error stating that the webmap is not supported.
2) initUrl works if webmap is unsecured or you append a token within the url.
3) Using itemId is same as initUrl. When using item id you need to give the portal url. With initUrl you have the complete URL with itemId . It just another way, plus you can use with the portal properties when using itemId
4) In your case you have a unsecured webmap with a secured layer inside. The above code would work for this scenario and also for scenario if you load the secured webmap. As long as secured webmap or secured layer belong to the same portal.