Select to view content in your preferred language

Is the identify function not possible in the version 100

1753
4
Jump to solution
03-30-2017 09:31 AM
Pierre-JeanMuller
Occasional Contributor

I tried to do an identify 

var task = MainMapView.IdentifyLayerAsync(srtmValueLayer, e.GetPosition(MainMapView), 0,false ,1);


I get this error in the task result of the task :

Error = {"Invalid argument: Identify parameters do not specify a region in the view extent."}

According to the list that shows the implemented functionalities in the version 100:

Choosing the right version | ArcGIS for Developers 

The ImageServiceLayer is not implemented. So do I have to change to the version 10.2.7 in order to have an identify function?

0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor

This should work in v100. What event are you using and what's e.GetPosition(MainMapView)'s value when you get this error? 

var position = e.GetPosition(MainMapView);
System.Diagnostics.Debug.WriteLine(position.ToString());

You can also try the following code. Using GeoViewTapped, you can pass either specific layer or identify all layers. In the identified result, notice that ArcGISMapImageLayer have results in SublayerResults and FeatureLayer have results in GeoElements.

        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" GeoViewTapped="MyMapView_GeoViewTapped">
            <esri:Map>
                <esri:ArcGISMapImageLayer Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />
                <esri:FeatureLayer>
                    <esri:ServiceFeatureTable Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Notes/FeatureServer/0" />
                </esri:FeatureLayer> 
            </esri:Map>
        </esri:MapView>
    </Grid>‍‍‍‍‍‍‍‍‍‍‍

        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                Layer layer = null;
                layer = MyMapView.Map.AllLayers.OfType<ArcGISMapImageLayer>().FirstOrDefault();
                var identifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, 1, false, 1);
                DisplayResult(identifyResult); // results in SublayerResults

                layer = MyMapView.Map.AllLayers.OfType<FeatureLayer>().FirstOrDefault();
                identifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, 1, false, 1);
                DisplayResult(identifyResult); // results in GeoElements

                var identifyResults = await MyMapView.IdentifyLayersAsync(e.Position, 1, false, 1);
                foreach (var result in identifyResults)                    
                    DisplayResult(result); 
                   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private string GetGeoElements(IEnumerable<GeoElement> geoElements)
        {
            var sb = new StringBuilder();
            foreach (var g in geoElements)
                foreach (var a in g.Attributes)
                    sb.AppendLine($"{a.Key}={a.Value}");
            return sb.ToString();
        }

        private string GetSublayerResult(IEnumerable<IdentifyLayerResult> sublayerResults)
        {
            var sb = new StringBuilder();
            foreach (var r in sublayerResults)
            {
                sb.AppendLine($"{r.LayerContent.Name} has {r.GeoElements.Count} results");
                var summary = GetGeoElements(r.GeoElements);
                if (!string.IsNullOrEmpty(summary))
                    sb.AppendLine(summary);
            }
            return sb.ToString();
        }

        private void DisplayResult(IdentifyLayerResult result)
        {
            var sb = new StringBuilder();
            var summary = GetGeoElements(result.GeoElements);
            if (!string.IsNullOrEmpty(summary))
                sb.AppendLine(summary);
            summary = GetSublayerResult(result.SublayerResults);
            if (!string.IsNullOrEmpty(summary))
                sb.AppendLine(summary);
            summary = sb.ToString();
            if(!string.IsNullOrEmpty(summary))
                MessageBox.Show(summary);
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

View solution in original post

4 Replies
JenniferNery
Esri Regular Contributor

This should work in v100. What event are you using and what's e.GetPosition(MainMapView)'s value when you get this error? 

var position = e.GetPosition(MainMapView);
System.Diagnostics.Debug.WriteLine(position.ToString());

You can also try the following code. Using GeoViewTapped, you can pass either specific layer or identify all layers. In the identified result, notice that ArcGISMapImageLayer have results in SublayerResults and FeatureLayer have results in GeoElements.

        xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">
    <Grid>
        <esri:MapView x:Name="MyMapView" GeoViewTapped="MyMapView_GeoViewTapped">
            <esri:Map>
                <esri:ArcGISMapImageLayer Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer" />
                <esri:FeatureLayer>
                    <esri:ServiceFeatureTable Source="http://sampleserver6.arcgisonline.com/arcgis/rest/services/Notes/FeatureServer/0" />
                </esri:FeatureLayer> 
            </esri:Map>
        </esri:MapView>
    </Grid>‍‍‍‍‍‍‍‍‍‍‍

        private async void MyMapView_GeoViewTapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                Layer layer = null;
                layer = MyMapView.Map.AllLayers.OfType<ArcGISMapImageLayer>().FirstOrDefault();
                var identifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, 1, false, 1);
                DisplayResult(identifyResult); // results in SublayerResults

                layer = MyMapView.Map.AllLayers.OfType<FeatureLayer>().FirstOrDefault();
                identifyResult = await MyMapView.IdentifyLayerAsync(layer, e.Position, 1, false, 1);
                DisplayResult(identifyResult); // results in GeoElements

                var identifyResults = await MyMapView.IdentifyLayersAsync(e.Position, 1, false, 1);
                foreach (var result in identifyResults)                    
                    DisplayResult(result); 
                   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private string GetGeoElements(IEnumerable<GeoElement> geoElements)
        {
            var sb = new StringBuilder();
            foreach (var g in geoElements)
                foreach (var a in g.Attributes)
                    sb.AppendLine($"{a.Key}={a.Value}");
            return sb.ToString();
        }

        private string GetSublayerResult(IEnumerable<IdentifyLayerResult> sublayerResults)
        {
            var sb = new StringBuilder();
            foreach (var r in sublayerResults)
            {
                sb.AppendLine($"{r.LayerContent.Name} has {r.GeoElements.Count} results");
                var summary = GetGeoElements(r.GeoElements);
                if (!string.IsNullOrEmpty(summary))
                    sb.AppendLine(summary);
            }
            return sb.ToString();
        }

        private void DisplayResult(IdentifyLayerResult result)
        {
            var sb = new StringBuilder();
            var summary = GetGeoElements(result.GeoElements);
            if (!string.IsNullOrEmpty(summary))
                sb.AppendLine(summary);
            summary = GetSublayerResult(result.SublayerResults);
            if (!string.IsNullOrEmpty(summary))
                sb.AppendLine(summary);
            summary = sb.ToString();
            if(!string.IsNullOrEmpty(summary))
                MessageBox.Show(summary);
        }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Pierre-JeanMuller
Occasional Contributor

Thanks for the answer, my problem was the way I used to show the results

0 Kudos
Pierre-JeanMuller
Occasional Contributor

But what I found a little bit strange, that I can't identify a layer without being added to the mapView and if I put the visibility or the opacity to zero, I get no results.

0 Kudos
brysageek
Emerging Contributor

I am not entirely sure about the design decision around not continuing the IdentifyTask, there are many use cases where we would want to query services that aren't added to our map, I do see that there are benefits to having us go through GeoView--will the identifyTasks be brought back down to the individual service level?

0 Kudos