Select to view content in your preferred language

How to use an ItemResourceCache object with the ArcGISVectorTiledLayer constructor for an offline VTPK

167
2
3 weeks ago
LeeCarter
New Contributor II

We have a ArcGIS Maps SDK for Qt (C++ not QML) based application that has an offline vector tile package basemap layer constructed as shown below before then being appended to the basemap layers:

ArcGISVectorTiledLayer* basemapLayer_p = new ArcGISVectorTiledLayer(new VectorTileCache(vectorBasemapFilename, this), this);

Where  "vectorBasemapFilename" is the location/filename on disk of the vtpk file.

This works fine, but we would like to style the map differently in certain situations, for example to be able to support application having light and dark display modes.

I know the vtpk file is just an archive and within it is a file (2MB of JSON format data?) that contains the styling information used by default with the vtpk.  Our vtpk file is large (over 50GB) so I don't want to duplicate that in order to have a different styling applied.

I believe that I should be able to create the ArcGISVectorTiledLayer using a different constructor that would allow a different styling to be applied to that layer:

ArcGISVectorTiledLayer::ArcGISVectorTiledLayer(Esri::ArcGISRuntime::VectorTileCache *vectorTileCache, Esri::ArcGISRuntime::ItemResourceCache *itemResourceCache, QObject *parent = nullptr)

Where the "ItemResourceCache*" argument would be constructed using the path to a disk file, similar how we make the VectorTileCache already:

ItemResourceCache::ItemResourceCache(const QString &path, QObject *parent = nullptr)

I cannot find any examples of ItemResourceCache being used or details of what the file referenced by the "path" argument to the constructor should contain and how to create the file.

I would be grateful if anyone can direct me to or provide information on what the local file needed to populate an ItemResourceCache object should be/contain and how to make one. 

Is using the online style editor an option and if so how and does that result in a style that will want/try to access the Internet resources when used (which would be unacceptable as our application has no Internet access when in use).

2 Replies
LucasDanzinger
Esri Frequent Contributor

Good question. I had to do a little digging on this one... Currently, the only way to create custom item resource caches is through portal items, so a workflow such as the following should get you on the right track. I tested it and was successful:

  • Publish your vtpk as a service. I used ArcGIS Online and uploaded as a hosted service, but you could publish to enterprise. Make sure to enable offline export capabilities
  • Use the vector tile style editor to make edits to the style. They've got some good tutorials to showcase how you can edit the style. Save your edits as a new item
  • Using the newly created item, call the ExportVectorTileTask:: exportStyleResourceCache to export the resource cache - https://developers.arcgis.com/qt/cpp/api-reference/esri-arcgisruntime-exportvectortilestask.html#exp... 
  • Export how every many resource caches you want and place them next to your VTPK. The resource cache will be a folder with a json file and a zip.

Screenshot 2024-07-09 at 1.30.31 PM.png

  • Construct your local vector tile layer using the vector tile cache and the new item resource cache

 

VectorTileCache* vtc = new VectorTileCache("/Users/<username>/Desktop/nz_bndl.vtpk", this);

ItemResourceCache* irc = new ItemResourceCache("/Users/<username>/Desktop/nz_bndl_resourcecache1", this);

ArcGISVectorTiledLayer* lyr = new ArcGISVectorTiledLayer(vtc, irc, this);

Basemap* bmap = new Basemap(lyr, this);
m_map = new Map(bmap, this);

 

 

 

 

0 Kudos
LeeCarter
New Contributor II

Hi Lucas,

Thank you for the response.  I'm just seeing if I can upload the vtpk file (+50GB!) now.  I do have a concern that due to the recent changes to subscriptions, user types, etc. I will not be able to do this sort of operation for long without revising the subscription but I will reach out to my ESRI UK Customer Success Manager about that.

I did find a post on the .NET SDK forum that talked about putting a resources.zip file somewhere and referencing the folder to create the item resource cache and I had managed to hack together such a file and see it having an effect, but your information gives us a way to create styles with the online editor which should be easier than editing a big JSON file in notepad.

Once I've finished giving this a go, if successful I'll accept your information as the solution.

0 Kudos