Visualizing WebMaps in QT aplication

955
3
06-16-2021 12:43 PM
TimerDeveloper
New Contributor

Hello Community!

I am new to QT and ArcGIS and I am having a hard time visualizing a WebMap on my main QT application.

I have tried the tutorial (https://developers.arcgis.com/qt/maps-2d/tutorials/display-a-web-map/) and it works, but only for the default webMap of the tutorial, if I change the itemID for my own test web map ID, the widget shows nothing.

Here is the code that I implemented:

//Default itemID ArcGIS WebMap
//    const QString item_id("41281c51f9de45edaf1c8ed44bb10e30");
//   My public WebMap
const QString item_id("26c05778806b435283c9787079b96b51");

const QUrl portal_url(QString("https://arcgis.com/sharing/rest/content/items/" + item_id));

m_map = new Map(portal_url, this);

 

I thought that the problem was related to the portal, so I tried this:

 

Credential* ucPortal = new Credential("MyUsername","MyPassword", parent);
Portal* myPortal = new Portal(QUrl("https://timerdeveloper.maps.arcgis.com"), ucPortal, parent);
connect(myPortal, &Portal::doneLoading, this, [](Esri::ArcGISRuntime::Error loadError)
{
if (!loadError.isEmpty())
qDebug() << loadError.message();
});
myPortal->load();

PortalItem* portalItem = new PortalItem(myPortal, item_id, parent);
connect(portalItem, &PortalItem::doneLoading, this, [portalItem](){
qDebug() << "Item title:" << portalItem->title();
});
portalItem->load();


m_map = new Map(portalItem, this);

And again it works, but only for the default itemID of the tutorial, not for my own itemID.

 

I have been stuck on this for over a week so any help is welcome c:

 

I am using QT 5.12.10 with MSVC2015 and ArcGIS Runtime 100.8

I wasn't able to set my API Key because of the old runtime versión that I am using.

I am currently trying to set an OAuth 2.0 Autentication but it has been dificult.

The WebMap that I am trying to display is set to public so the autentication shouldn't be a problem (right?)

 

I uploaded the files if you want to check them.

0 Kudos
3 Replies
Tanner_Yould
Esri Contributor

Hi @TimerDeveloper, thanks for asking and I hope I can help! There are a couple of things going on here:

I believe your web map item is actually hosted on your own portal here (timerdeveloper.maps.arcgis.com), so your application is unable to find the web map at arcgis.com/sharing/rest/content/items.

The web map you're connecting to is public, but the basemap it uses requires an ArcGIS Developer account. You're providing credentials, so this isn't an issue, but it's worth noting.

However, the main issue here is that you're not calling m_mapView->setMap(m_map) after the portal has loaded and your new map has been instantiated.

Here's a simplified code block to demonstrate:

 

// Item id of MapaTestTIMER
QString itemId = "26c05778806b435283c9787079b96b51";

// Portal defaults to "arcgis.com" when no url is provided, and because "MapaTestTIMER" is hosted there, we do not need to provide a url.
Portal* portal = new Portal(new Credential("username", "password", this), this);

// This is the "MapaTestTIMER" web map
PortalItem* portalItem = new PortalItem(portal, itemId, this);

// We create a Map from the portal item
// Portal and PortalItem will automatically be loaded
m_map = new Map(portalItem, this);

// We set the MapView to use our new map
m_mapView->setMap(m_map);

 

 

I hope this works for you please let me know if I can do anything else to help!

Tanner Yould
ArcGIS Runtime API for Qt, Samples Engineer

Tanner Yould
Samples Product Engineer
ArcGIS Maps SDK for Qt
Esri
0 Kudos
TimerDeveloper
New Contributor

Hi @Tanner_Yould , thank you so much for your help.

In both codes samples  that I posted  did call m_mapView->setMap(m_map)  after the  m_map = new Map(portalItem,this); line. I just didn't include it in the code sample (sorry my bad😅

I tried your code block but I keep having the same issue. The example WebMap of the tutorial works great, but if change the itemID for my MapaTestTimer id, it shows nothing.

Any help is appreciated 

0 Kudos
PJ9987
by
New Contributor

Hi @TimerDeveloper ,

Did you ever figure this out? I am having the same problem.

0 Kudos