HitTestAsync with Polyline

5712
11
02-17-2015 07:44 AM
DarleneBanta1
New Contributor

I have a map service and when I call

     await MyLayer.HitTestAsync(MyMapView, screenPoint)

with a point feature layer everything works.  When I switch to a polyline feature layer I get a popup message box that vshost32.exe has stopped working and I cannot debug from my visual studio window and the app crashes.

Does HitTestAsync support polylines?

0 Kudos
11 Replies
dotMorten_esri
Esri Notable Contributor

Polylines are supported. Do you have a simple reproducer I can use to test what's going on? Also note that we released 10.2.5 last week which contains many bug fixes.

0 Kudos
DarleneBanta1
New Contributor

I'm using 10.2.5 assemblies.  I just downloaded the nuget package this morning.

Here is the code that reproduces the issue against our FeatureLayer.  Our layer is M-Aware (HasM = true) and its spatial reference is 4269.  I can reproduce with our point layers that also has HasM = true.  Using the same code sample I cannot reproduce the issue using this layer hosted by ESRI - Layer: Highways (ID: 1)

Should I contact ESRI support or wait for followup here?

Layer: Centerline History (ID: 6)

Name: Centerline History

Display Field: CENTERLINE_HISTORY_ID

Type: Feature Layer

Geometry Type: esriGeometryPolyline

Description:

Definition Expression:

Copyright Text:

Default Visibility: false

MaxRecordCount: 1000

Supported Query Formats: JSON, AMF

Min Scale: 0

Max Scale: 0

Supports Advanced Queries: true

Supports Statistics: true

Has Labels: false

Can Modify Layer: false

Can Scale Symbols: false

Extent:

      XMin: -180

      YMin: -90

      XMax: 180

      YMax: 90

      Spatial Reference: 4269  (4269)

Drawing Info:

Renderer:Simple Renderer:

Symbol:

Style:

          esriSLSSolid

Color:

          [133, 0, 11, 255]

Width:

          1

Label:

Description:Transparency:

      0

Labeling Info:

HasZ: true

HasM: true

Has Attachments: false

HTML Popup Type: esriServerHTMLPopupTypeAsHTMLText

Type ID Field: null

Fields:

  • CENTERLINE_HISTORY_ID ( type: esriFieldTypeDouble , alias: CENTERLINE_HISTORY_ID )
  • ROUTE_ID ( type: esriFieldTypeDouble , alias: ROUTE_ID )
  • SHAPE ( type: esriFieldTypeGeometry , alias: SHAPE )
  • SHAPE.LEN ( type: esriFieldTypeDouble , alias: SHAPE.LEN )
  • SHAPE.FID ( type: esriFieldTypeOID , alias: SHAPE.FID )
  • LINE_ID ( type: esriFieldTypeDouble , alias: LINE_ID )
  • DESIGNATOR ( type: esriFieldTypeString , alias: DESIGNATOR , length: 50 )
  • LINE_DESCRIPTION ( type: esriFieldTypeString , alias: LINE_DESCRIPTION , length: 254 )
  • PRODUCT_TYPE_SCL ( type: esriFieldTypeString , alias: PRODUCT_TYPE_SCL , length: 16 )
  • PRODUCT_SUBTYPE_SCL ( type: esriFieldTypeString , alias: PRODUCT_SUBTYPE_SCL , length: 16 )
  • PRODUCT_DESCRIPTION ( type: esriFieldTypeString , alias: PRODUCT_DESCRIPTION , length: 254 )
  • BEGIN_MEASURE ( type: esriFieldTypeDouble , alias: BEGIN_MEASURE )
  • END_MEASURE ( type: esriFieldTypeDouble , alias: END_MEASURE )
  • ROUTE_DESCRIPTION ( type: esriFieldTypeString , alias: ROUTE_DESCRIPTION , length: 254 )
  • SEQUENCE ( type: esriFieldTypeSmallInteger , alias: SEQUENCE )
  • ROUTE_TYPE_CL ( type: esriFieldTypeString , alias: ROUTE_TYPE_CL , length: 16 )
  • EFFECTIVE_FROM_DATE ( type: esriFieldTypeDate , alias: EFFECTIVE_FROM_DATE , length: 36 )
  • EFFECTIVE_TO_DATE ( type: esriFieldTypeDate , alias: EFFECTIVE_TO_DATE , length: 36 )
  • OBJECTID ( type: esriFieldTypeInteger , alias: OBJECTID )
  • CHANGE_TYPE_CL ( type: esriFieldTypeString , alias: CHANGE_TYPE_CL , length: 16 )
  • LINE_TYPE_CL ( type: esriFieldTypeString , alias: LINE_TYPE_CL , length: 16 )
  • LINE_TYPE_DESCRIPTION ( type: esriFieldTypeString , alias: LINE_TYPE_DESCRIPTION , length: 254 )
  • ROUTE_TYPE_DESCRIPTION ( type: esriFieldTypeString , alias: ROUTE_TYPE_DESCRIPTION , length: 254 )
0 Kudos
DarleneBanta1
New Contributor

Morten Nielsen‌ I think this might be because our layer is M-Aware.  Should I submit this as an official support request to ESRI?

0 Kudos
JenniferNery
Esri Regular Contributor

Hi Darlene,

I tried to reproduce with the following code against ArcGIS Runtime SDK for .NET 10.2.5.857 (nuget package) but I am finding these issues instead (no crash)

M-aware point returns empty result on hittest.

M-aware line do not render.

Could you maybe try the following code with your services?

            xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>

        <esri:MapView x:Name="MyMapView">

            <esri:Map>

                <esri:ArcGISTiledMapServiceLayer ServiceUri="http://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer"/>

                <esri:FeatureLayer ID="Line">

                    <esri:ServiceFeatureTable ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/1" />

                </esri:FeatureLayer>

                <esri:FeatureLayer ID="Point" >

                    <esri:ServiceFeatureTable ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0"/>

                </esri:FeatureLayer>

                <esri:FeatureLayer ID="LineHasM">

                    <esri:ServiceFeatureTable ServiceUri="..." />

                </esri:FeatureLayer>

                <esri:FeatureLayer ID="PointHasM">

                    <esri:ServiceFeatureTable ServiceUri="..." />

                </esri:FeatureLayer>

            </esri:Map>

        </esri:MapView>

        <Button VerticalAlignment="Top" HorizontalAlignment="Center" Content="Select" Click="Select_Click"/>

    </Grid>

private async void Select_Click(object sender, RoutedEventArgs e)

{

string message = null;

try

{

foreach (var layer in MyMapView.Map.Layers.OfType<FeatureLayer>())

{

if (layer.SelectedFeatureIDs.Any())

layer.UnselectFeatures(layer.SelectedFeatureIDs.ToArray());

var geometry = await MyMapView.Editor.RequestPointAsync();

var ids = await layer.HitTestAsync(MyMapView, MyMapView.LocationToScreen(geometry));

if (ids != null && ids.Any())

layer.SelectFeatures(ids);

}

}

catch (TaskCanceledException ex)

{

}

catch (Exception ex)

{

message = ex.Message;

}

if (!string.IsNullOrWhiteSpace(message))

MessageBox.Show(message);

}

Thanks.

0 Kudos
DarleneBanta1
New Contributor

My M-Aware line and point are rendering. 

The first time I click select Editor.RequestPointAsync never returns a geometry after waiting for a minute or two.  Subsequent calls to Editor.RequestPointAsync results in an exception.  This exception is thrown with and without my M-Aware line and point layers.  I cannot reach the call to HitTestAsync.

System.Threading.Tasks.TaskCanceledException was caught

  HResult=-2146233029

  Message=A task was canceled.

  Source=mscorlib

  StackTrace:

       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

       at Esri.ArcGISRuntime.Controls.Editor.<RequestPointAsync>d__0.MoveNext()

    --- End of stack trace from previous location where exception was thrown ---

       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

       at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

       at RuntimeMap.MainWindow.<Select_Click>d__14.MoveNext() in c:\TFS\Sandbox\RuntimeMap\RuntimeMap\MainWindow.xaml.cs:line 219

  InnerException:

0 Kudos
JenniferNery
Esri Regular Contributor

Did you await RequestPointAsync? It should return a geometry as soon as you tap or click on the map. The TaskCanceledException may have been triggered by the next call to RequestPointAsync, this will cancel previous async call that has not returned.  You can also use MapView.MapViewTapped event to get the screen point for hit test.

Could you also share code to reproduce the crash on hit test? Are we using the same version of the API? Are you using WPF, Store or Phone application?

0 Kudos
DarleneBanta1
New Contributor

I used await MyMapView.Editor.RequestPointAsync().  I copied the code you provided.  I will test using MapViewTapped and let you know how that works.

I have a WPF application.  I attached my code to the post where I include the Centerline Layer properties.  I attached it here again as well.  I am using 10.2.5.0 assemblies.

0 Kudos
JenniferNery
Esri Regular Contributor

Oh sorry, I didn't realize there was a sample attachment in the thread. It was not visible from the main discussion thread.

I see now why you would get TaskCanceledException if you copied the code I provided from click event handler. Your sample is using MouseMove, which will fire numerous times. Thus starting another RequestPointAsync call which cancels previous async call. I was only using RequestPointAsync to get a screen point but you're free to use e.GetPosition() from MouseEventArgs.

Going back to the original issue. I tried using your sample as is with my own m-aware service. Your sample uses hit test result to query the table for features.

The only thing, I changed was the binding statement since DataContext of the overlay is set to graphics and you want access its Attributes.

<TextBlock Text="{Binding Attributes[OBJECTID]}" />

I did not get a crash though.

debug.png

maptip.png

0 Kudos
DarleneBanta1
New Contributor

Ok so I suspect it might be something with my map layer then if that code works for you.  I initially suspected that it was because my layer is m-aware, but I guess you have eliminated that.  Do you have any suggestions for how to identify what could be causing this crash on my layers?  The geodatabase is at version 10.1sp0 for Oracle 11g.

I did some testing with additional layers and I found a difference between the layers that work and the layers that don't work.  The layers that cause the crash are part of a group layer.  Could you test this on your side and see if sub-layers that are part of a group layer crash?

I tried using the following code and it crashed as soon as it iterated over my layer and called HitTestAsync -

        private async void MyMapView_OnMapViewTapped(object sender, MapViewInputEventArgs e)

        {

            string message = null;

            try

            {

                foreach (var layer in MyMapView.Map.Layers.OfType<FeatureLayer>())

                {

                    if (layer.SelectedFeatureIDs.Any())

                        layer.UnselectFeatures(layer.SelectedFeatureIDs.ToArray());

                    //var geometry = await MyMapView.Editor.RequestPointAsync();

                    var ids = await layer.HitTestAsync(MyMapView, MyMapView.LocationToScreen(e.Location));

                    if (ids != null && ids.Any())

                        layer.SelectFeatures(ids);

                }

            }

            catch (TaskCanceledException ex)

            {

            }

            catch (Exception ex)

            {

                message = ex.Message;

            }

            if (!string.IsNullOrWhiteSpace(message))

                MessageBox.Show(message);

        }

0 Kudos