Base map spatial reference

781
2
Jump to solution
09-28-2017 09:08 PM
RainerFarsch1
New Contributor II

I'm running v100.1 and I'm trying to get the spatial reference for a base map from a tile package I've loaded. This worked in 10.2.6 where I loaded this same tile package in QML and could print out latestWkid (3857) and wkid (102100). Now I am reading the same tile package in my v100.1-based C++/Qt Quick application and always get -1 as wkid. So I went to the basic MyFirstMap - you know the starter code from the wizard - and tried to get wkid from it. I added the last four lines of code in the snippet below. I'm getting -1 for both m_map's and m_mapView's spatial reference. Shouldn't I be getting something valid? There must be something fundamental that I'm missing. 

Thanks!

void MyFirstMapV100::componentComplete()
{
   QQuickItem::componentComplete();
   // find QML MapView component
   m_mapView = findChild<MapQuickView*>("mapView");
   m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);
   // Create a map using the imageryWithLabels BaseMap
   m_map = new Map(Basemap::imageryWithLabels(this), this);
   // Set map to map view
   m_mapView->setMap(m_map);
   SpatialReference sr = m_map->spatialReference();
   qDebug() << sr.wkid();   // returns -1
   sr = m_mapView->spatialReference();
   qDebug() << sr.wkid();   // returns -1
}

Also, here's an excerpt showing how I'm loading my tile package base map from my application. Again, I'm getting -1 for the spatial references.

   TileCache* tileCache = new TileCache(m_dataPath + "XXXXXXXXXX.tpk");
   ArcGISTiledLayer* tiledLayer = new ArcGISTiledLayer(tileCache, this);
   // What is the spatial reference?
   SpatialReference sr = tiledLayer->spatialReference();
   qDebug() << sr.wkid();   // returns -1
   Basemap* basemap = new Basemap(tiledLayer, this);
   m_map = new Map(basemap, this);
   
   // What is the spatial reference?
   sr = m_map->spatialReference();
   qDebug() << sr.wkid();   // returns -1
0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Rainer-

Try connecting to the doneLoading signal for the layer and map, and printing out the spatial reference at that point. One of the biggest new paradigms in version 100 is the use of the Loadable interface, so often times you will need to wait until something is "loaded" to get access to metadata about it.

Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

For example:

TileCache* tileCache = new TileCache(m_dataPath + "XXXXXXXXXX.tpk");
ArcGISTiledLayer* tiledLayer = new ArcGISTiledLayer(tileCache, this);
Basemap* basemap = new Basemap(tiledLayer, this);
m_map = new Map(basemap, this);
   
// connect to doneLoading signal
connect(m_map, &Map::doneLoading, this, [=](Error e)
{
  if (!e.isEmpty)
  {
    qDebug() << "error" << e.message();
    return;
  }

  // What is the spatial reference?
  SpatialReference sr = m_map->spatialReference();
  qDebug() << sr.wkid();
});

// either call m_map->load(), or set it to the MapView, which will implicitly load it
m_mapView->setMap(m_map);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

2 Replies
LucasDanzinger
Esri Frequent Contributor

Rainer-

Try connecting to the doneLoading signal for the layer and map, and printing out the spatial reference at that point. One of the biggest new paradigms in version 100 is the use of the Loadable interface, so often times you will need to wait until something is "loaded" to get access to metadata about it.

Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

For example:

TileCache* tileCache = new TileCache(m_dataPath + "XXXXXXXXXX.tpk");
ArcGISTiledLayer* tiledLayer = new ArcGISTiledLayer(tileCache, this);
Basemap* basemap = new Basemap(tiledLayer, this);
m_map = new Map(basemap, this);
   
// connect to doneLoading signal
connect(m_map, &Map::doneLoading, this, [=](Error e)
{
  if (!e.isEmpty)
  {
    qDebug() << "error" << e.message();
    return;
  }

  // What is the spatial reference?
  SpatialReference sr = m_map->spatialReference();
  qDebug() << sr.wkid();
});

// either call m_map->load(), or set it to the MapView, which will implicitly load it
m_mapView->setMap(m_map);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
RainerFarsch1
New Contributor II

Thanks Lucas,

I looked at this yesterday and noticed the same. I'm now loading the tile cache and map and waiting for them to finish loading before interrogating their spatial references - although I didn't do it as elegantly as you did with lambdas - I'll have to do the same (I was spinning on the load status ). I was already doing this loading for the geodatabase - I should have caught this for the tile cache and map. Oh well.

Thanks!

-Rainer

0 Kudos