Select to view content in your preferred language

How to Change Vector Style by using ItemResourceCache

245
3
Jump to solution
07-18-2024 04:49 PM
ForrestKaye
New Contributor III
I am attempting to utilize the method in the maps sdk for android & ios to instantiate a vector tiled layer with a resource cache, but attempts to do so fail.  I am utilizing the method:
  • ArcGISVectorTiledLayer(vectorTileCache: VectorTileCache, itemResourceCache: ItemResourceCache?)
If I do not pass in the ItemResourceCache the VectorTiledLayer loads as expected.  
 
There are two issues I am trying to solve. 
  1. How can I generate a valid ItemResourceCache to change the styling of the VectorTiledLayer.  Is there a way to generate one through the 'vector style editor' and use this as a template style to apply to VTPK's? Or is the only way to download one through the 'ExportVectorTilesTask'?
  2. How can I apply style to a hosted Vector tile service so that I can download an ItemResourceCache? I am using my own basemap service for my testing but when I check the 'hasStyleResources' property to ensure that I can download the ItemResourceCache it says false.  I don't see a way to apply or generate a style to that service so that I can download the ItemResourceCache. 
 
As a side note I have used the sample here: 'https://developers.arcgis.com/swift/sample-code/download-vector-tiles-to-local-cache/' which has proved very useful but attempting to utilize my own vector service has not worked.
 
Ultimately my goal is to have a single style template/ItemResourceCache that I can apply to a packaged .vtpk file to change the display and look of the basemap.  At first I was under the impression that the .json file that you can download from the Vector Style Tile Editor would be all you need to pass in as the Item resource cache but that doesn't work. And any attempts to create my own resources.zip package with all the appropriate items to simulate an ItemResourceCache do not seem to work. 
 
Thanks,
0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

Hello.

I can partially answer the question for you, based off using our hosted basemap tiles (and the Vector Tile Style Editor). When it comes to your own custom basemap service, I'll have to defer to someone else.

Let's just talk about our hosted vector basemaps for the moment:

There's one set of global vector tiles which we host and for which we provide a number of different styles. And using the Vector Tile Style Editor, you can create your own custom styles to augment those, but all those styles (ours, and anything you create using the VTSE) are bound to the attributes contained in the vector tiles.

The Item Resource Cache is a folder of resources (JSON, Sprites, etc.) downloaded from the hosted style, potentially modified to remove web references, and stored on your device. It's not a public spec that we promise to adhere to and should be treated as a black box (though since it's just a folder, you can of course poke around and see what's in there).

An Item Resource Cache is, as far as I know, only created one way: by downloading it using the ExportVectorTilesTask to create an ExportVectorTilesJob, just as you suggested. You can either do it by exporting tiles and an item resource cache at the same time, or by just downloading the item resource cache (which sounds more like what you need). That way, you can download multiple different styles to different folders locally, and use them with any exported tiles (VTPKs) from that vector tile service. I've done this a number of times (multiple resource caches, one set of tiles).

Note, you can't switch styles on an instantiated ArcGISVectorTileLayer on the fly, but you can create a new layer using the same tiles (VTPK) and a different style (Item Resource Cache), and just swap that out in your Map's operationalLayers or basemap.

That should answer Q1.

Now, your own services (Q2):

If you publish your own basemap service, that's where my understanding falls apart a little. If you wanted to use an Item Resource Cache downloaded from our basemaps or your custom VTSE-created style, I expect your service would need to include attributes included in our service.

If you want to publish your own vector tile service with multiple styles, I don't know whether ArcGIS Pro supports publishing different styles for a single vector tile service of your own. I'll see if I can find someone who has some more understanding of that side of things to pipe up.

So, for your stated end goal:

If you're working with our basemaps as the source, you can absolutely do this and download any number of styles as Item Resource Caches, and any number of map areas as separate VTPKs, and mix and match them as much as you like. The schemas will match.

If you're looking for a universal style to apply to any arbitrary vector tile service or VTPK exported from that service, AFAIK that won't work. There's a tight dependency of the style definitions on the attributes published in the service.

If you have a single custom vector tile service of your own and you want to apply multiple different styles to it, we'll have to see what someone else says. It expect it would depend on how ArcGIS Pro publishes vector tile services from vector tile layers with differing styles.

Hope that helps a bit.

View solution in original post

0 Kudos
3 Replies
Nicholas-Furness
Esri Regular Contributor

Hello.

I can partially answer the question for you, based off using our hosted basemap tiles (and the Vector Tile Style Editor). When it comes to your own custom basemap service, I'll have to defer to someone else.

Let's just talk about our hosted vector basemaps for the moment:

There's one set of global vector tiles which we host and for which we provide a number of different styles. And using the Vector Tile Style Editor, you can create your own custom styles to augment those, but all those styles (ours, and anything you create using the VTSE) are bound to the attributes contained in the vector tiles.

The Item Resource Cache is a folder of resources (JSON, Sprites, etc.) downloaded from the hosted style, potentially modified to remove web references, and stored on your device. It's not a public spec that we promise to adhere to and should be treated as a black box (though since it's just a folder, you can of course poke around and see what's in there).

An Item Resource Cache is, as far as I know, only created one way: by downloading it using the ExportVectorTilesTask to create an ExportVectorTilesJob, just as you suggested. You can either do it by exporting tiles and an item resource cache at the same time, or by just downloading the item resource cache (which sounds more like what you need). That way, you can download multiple different styles to different folders locally, and use them with any exported tiles (VTPKs) from that vector tile service. I've done this a number of times (multiple resource caches, one set of tiles).

Note, you can't switch styles on an instantiated ArcGISVectorTileLayer on the fly, but you can create a new layer using the same tiles (VTPK) and a different style (Item Resource Cache), and just swap that out in your Map's operationalLayers or basemap.

That should answer Q1.

Now, your own services (Q2):

If you publish your own basemap service, that's where my understanding falls apart a little. If you wanted to use an Item Resource Cache downloaded from our basemaps or your custom VTSE-created style, I expect your service would need to include attributes included in our service.

If you want to publish your own vector tile service with multiple styles, I don't know whether ArcGIS Pro supports publishing different styles for a single vector tile service of your own. I'll see if I can find someone who has some more understanding of that side of things to pipe up.

So, for your stated end goal:

If you're working with our basemaps as the source, you can absolutely do this and download any number of styles as Item Resource Caches, and any number of map areas as separate VTPKs, and mix and match them as much as you like. The schemas will match.

If you're looking for a universal style to apply to any arbitrary vector tile service or VTPK exported from that service, AFAIK that won't work. There's a tight dependency of the style definitions on the attributes published in the service.

If you have a single custom vector tile service of your own and you want to apply multiple different styles to it, we'll have to see what someone else says. It expect it would depend on how ArcGIS Pro publishes vector tile services from vector tile layers with differing styles.

Hope that helps a bit.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

FYI, there is also this post from a while back which might be of interest. It doesn't quite tackle your specific use case and focuses on Mobile Map Packages from Pro, but it does talk a bit about what's going on within them which could be helpful.

0 Kudos
ForrestKaye
New Contributor III

Thank you for the quick and detailed response.  This helps a ton and confirms what I needed to understand to make sure I was addressing this the right way. 

I will first work on publishing a vector tile service with the styles applied that I need and go from there. It sounds like at that point my plan to have one style and apply it to other maps generated from that same service will work very well.

Thanks,

0 Kudos