Differentiate between TiledMapServiceLayer and DynamicMapServiceLayer in code

3759
4
Jump to solution
02-10-2016 02:27 PM
AaronHigh
New Contributor III

Hi,

In my application it's currently possible to add both ArcGISTiledMapServiceLayer and ArcGISDynamicMapServiceLayer types. The issue I have is that I can't find a good way to query the service to determine which type the user is adding.

It seems I can always add a Tiled layer as a dynamic service, but the opposite (expectedly) throws an exception. What I would like to do is be able to determine and/or query in code whether a given service Uri/Url is hosting tiles or is a "standard" dynamic map service. Is this possible? The exception raised when I add a dynamic as a tiled is "no valid tile info", is there a way to check the service for tile info and then determine which type of map layer object to create based on that? It would be possible to catch the exception and then regenerate the other type, but I'm trying to save that as a last resort option.

Thanks!

Aaron

0 Kudos
1 Solution

Accepted Solutions
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Aaron,

First thing I think it is good to take a look about this diagram. Based on this online documentation: (Layer types )

Layers Mini OMD

An ArcGISDynamicMapServiceLayer is a dynamic ArcGIS REST image service layer that allows you to work a with map service resource exposed by the ArcGIS Server REST API (available in ArcGIS Server 9.3 and above). A dynamic map service generates images on the fly. The background color for an ArcGISDynamicMapServiceLayer will always be transparent.

An ArcGISTiledMapServiceLayer is a cached ArcGIS REST map service layer that allows you to work with a cached map service resource exposed by the ArcGIS Server REST API (available in ArcGIS Server 9.3 and above). A cached service accesses pre-created tiles from a cache instead of dynamically rendering images.

Then, the question about how to determine whether is an ArcGISDynamicMapServiceLayer or ArcGISTiledMapServiceLayer, I think you can first compare the REST JSON for both type of layers. Here I shared with you two different json url for each type:

ArcGISDynamicMapServiceLayer: https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0?f=pjson

ArcGISTiledMapServiceLayer: https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0?f=pjson

You can see in ArcGISDynamicMapServiceLayer the parameter "capabilities": "Data,Map,Query" versus ArcGISTiledMapServiceLayer is "capabilities": "Map"

Based on this documentation, you may try to use "GetType" method to distinguish both type of layers

Layer Class or parse the JSON to compare the capabilities. Basically, you need to compare two layer types of json and eventually find a parameter can identify the type.

Hope this can help.

Best Regards,

View solution in original post

0 Kudos
4 Replies
YueWu1
by Esri Regular Contributor
Esri Regular Contributor

Hi Aaron,

First thing I think it is good to take a look about this diagram. Based on this online documentation: (Layer types )

Layers Mini OMD

An ArcGISDynamicMapServiceLayer is a dynamic ArcGIS REST image service layer that allows you to work a with map service resource exposed by the ArcGIS Server REST API (available in ArcGIS Server 9.3 and above). A dynamic map service generates images on the fly. The background color for an ArcGISDynamicMapServiceLayer will always be transparent.

An ArcGISTiledMapServiceLayer is a cached ArcGIS REST map service layer that allows you to work with a cached map service resource exposed by the ArcGIS Server REST API (available in ArcGIS Server 9.3 and above). A cached service accesses pre-created tiles from a cache instead of dynamically rendering images.

Then, the question about how to determine whether is an ArcGISDynamicMapServiceLayer or ArcGISTiledMapServiceLayer, I think you can first compare the REST JSON for both type of layers. Here I shared with you two different json url for each type:

ArcGISDynamicMapServiceLayer: https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0?f=pjson

ArcGISTiledMapServiceLayer: https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0?f=pjson

You can see in ArcGISDynamicMapServiceLayer the parameter "capabilities": "Data,Map,Query" versus ArcGISTiledMapServiceLayer is "capabilities": "Map"

Based on this documentation, you may try to use "GetType" method to distinguish both type of layers

Layer Class or parse the JSON to compare the capabilities. Basically, you need to compare two layer types of json and eventually find a parameter can identify the type.

Hope this can help.

Best Regards,

0 Kudos
AaronHigh
New Contributor III

Thanks!

I was aware of the inheritance hierarchy, I was just trying to make a determination as to which type of Layer object to construct based on the service capabilities. A simple WebRequest to poll the capabilities member does the trick quite nicely. The difference between "TileMap" and "Map" in the capabilities was key here as if the service has tiles, I'd rather load it as a tiled layer than a dynamic layer for performance reasons.

Thanks again,

Aaron

0 Kudos
dotMorten_esri
Esri Notable Contributor

Getting the tile info is key here as you've found. However I'd like to add that if you map is in a different spatial reference than the spatial reference of the service getting added, you want to ignore the tile info and create a dynamic layer. The dynamic layer supports projection on the fly, while tile caches doesn't and requires the spatial reference to match.

0 Kudos
HuyHo
by
Occasional Contributor

We had to deal with a similar issue at one point and we used the same ?f=pjson parameters to obtain the map service description.  But rather than using the "capabilities" value, we used "tileInfo" instead.  So if the service has tileInfo, it is a map service that supports tile cache.

0 Kudos