How to get the Extent of a Dynamic Layer

2965
5
10-04-2012 06:57 AM
Labels (1)
EricPaitz
Esri Contributor
We have an ArcGISDynamicMapServiceLayer that has several layers defined in the Map Service and several Dynamic Layers added on the fly at run time because this map service is connected to an SDE Workspace. I need to get the extent of each layer within the ArcGISDynamicMapServiceLayer so our uses can have a Zoom to Layer capability. I have it working for only the layers that are statically defined in the map service but not for the layers added at run time.

This is what I have so far. In my XAML I have a context menu item defined in the LayerTempate DataTemplate for the ESRI Legend. This is the basic idea I have for my XAML.

<DataTemplate x:Key="LayerTemplate">
  .....
  <ContextMenu>
    <MenuItem Header="Zoom To" CommandParameter="{Binding}" Command ="{ ... DoZoomToLayer ... }" />
  </ContextMenu>
  ....
</DataTemplate>


Then in my ViewModel I have the following C# code.

public void DoZoomToLayer(ESRI.ArcGIS.Client.Toolkit.Primitives.LayerITemViewModel layerItemViewModel) {
  Action<ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo, Exception> action = (featureLayerIfno, exception) => {
    if (exception == null) {
      if (featureLayerInfo != null) {
        App.Map.Extent = featureLayerInfo.Extent;
      }
    }
  };
  ((ArcGISDynamicMapServiceLayer)layerItemViewModel.Layer).GetDetails(layerItemViewModel.SubLayerID, action);
}


If the layer is a dynamic layer added on the fly at run time then the featureLayerInfo object is null. This make some sense because the GetDetails() call asks the server side map service for details on a layerID that does not exist.

So how can I get the extent of a dynamic layer added on the fly at run time?
0 Kudos
5 Replies
ChristinaKochan
New Contributor
Did you figure this out? I've been trying to use WebClient.DownloadString(<dynamic layer url>), but while this works for feature layers, all of my raster layers just return the following json:

{"error":{"code":400,"message":"Invalid or missing input parameters.","details":[]}}
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

Can you provide any details on why you're calling WebClient.DownloadString ?

At the 10.2 release many more operations in the API, such as GetDetails/GetAllDetails now supports datasources configured via DynamicLayers. Therefore, where it was previously necessary to make handcrafted calls to the endpoint, you can now use the standard API methods.

For example, once you've configured a new raster datasource you can call GetDetails then process the FeatureLayerInfo for the required details. The extent property will give the extent of the new datasource. This code is taken from the "Add Shapefiles and Rasters" sample in the Sample App (under Mapping > Dynamic Map Layers).

arcGisLocalDynamicMapServiceLayer.GetDetails(dynamicLayerInfo.ID, (featureLayerInfo, exception) =>
{
    ...
    // Check featureLayerInfo.Extent property
    ...
}


Cheers

Mike
0 Kudos
ChristinaKochan
New Contributor
That was the only way I could figure out to get the info I needed from the dynamic layers, but it only worked for me on feature layers, not on rasters.

Unfortunately I can't move to 10.2 yet because we won't have enough time to test a new version and it's too high-risk for us at this time, so I am stuck with 10.1 for our current release. I am glad to hear that this functionality will be available when we are able to upgrade.

Is there any way I can get the extent from a dynamically-added raster layer using 10.1?
0 Kudos
MichaelBranscomb
Esri Frequent Contributor
Hi,

The 10.2 SDK can be installed alongside the 10.1.1 SDK - you obviously just need to make sure that your main app/project does not automatically pick up the 10.2 assemblies. 10.2 was a significant update to 10.1.1 with a lot of new functionality and various enhancements. If you don't have time to run full certification testing then you will likely want to stick on 10.1.1 to deploy initially but obviously we would recommend you consider upgrading to 10.2 as soon as possible.

I just ran the dynamiclayer sample/test against 10.2 - the request URL and JSON response is below - so you can check the URL you're constructing against this example. Note there's a GUID because that's what I use for the unique workspace name, but it can be any string you like. You might like to try something like http://json2csharp.com/ to generate C# classes for the JSON to make handling the response easier.

## REQUEST ##

http://localhost.:50000/Znk7Sv/arcgis/rest/services/emptympk_wgs84/MapServer/dynamicLayer?f=json&lay...{"id":0,"source":{"type":"dataLayer","dataSource":{"type": "raster","workspaceId": "78dfa62b-3a3c-4740-b1c4-f122b563795a","dataSourceName": "Photo.sid"}}}

## RESPONSE ##

{
  "currentVersion": 10.21,
  "name": "Raster Layer",
  "type": "Raster Layer",
  "description": "",
  "geometryType": null,
  "copyrightText": "",
  "subLayers": [
   
  ],
  "minScale": 0,
  "maxScale": 0,
  "defaultVisibility": true,
  "extent": {
    "xmin": -72.89445320022088,
    "ymin": 42.252009540096672,
    "xmax": -72.845193804302411,
    "ymax": 42.288595011042979,
    "spatialReference": {
      "wkid": 4326,
      "latestWkid": 4326
    }
  },
  "hasAttachments": false,
  "htmlPopupType": "esriServerHTMLPopupTypeNone",
  "displayField": "",
  "typeIdField": null,
  "fields": null,
  "relationships": [
   
  ],
  "canModifyLayer": true,
  "canScaleSymbols": false,
  "hasLabels": false,
  "capabilities": "Map,Query",
  "supportsStatistics": false,
  "supportsAdvancedQueries": false,
  "supportedQueryFormats": "JSON, AMF",
  "ownershipBasedAccessControlForFeatures": {
    "allowOthersToQuery": true
  },
  "useStandardizedQueries": true,
  "id": 0
}

Cheers

Mike
0 Kudos
ChristinaKochan
New Contributor
My problem was annoyingly simple: I was using "table" instead of "raster" for the data source type in my request URL, which was returning the 400 error code. All is well now.

Thanks for your help, Mike!
0 Kudos