Hi Carlos,
I checked our core assembly and found it is actually a bug for the method "GetFeaturesNearestTo". In the method, if the found feature in the buffer area is less than the limited count, we return the nearest features without the limited distance. This also explains why it works if you add all features into one InMemoryFeatureLayer. I have reported this issue to the core team. Please try the latest build tomorrow.
Also, I modified one of your method like following, and it works fine too.
Private Function GetFeaturesOnScreenPos(ByVal ScreenPos As ScreenPointF) As Collection(Of Feature)
Dim ScreenBufferSize As Integer = 5
Dim selectedFeatures As New Collection(Of Feature)
Try
'Logic for converting screen coordinate values to world coordinate for the spatial query. Notice that the distance buffer for the spatial query
'will change according to the zoom level while it remains the same for the screen buffer distance.
Dim WorldPos As PointShape = ExtentHelper.ToWorldCoordinate(WpfMap1.CurrentExtent, ScreenPos.X, ScreenPos.Y, WpfMap1.ActualWidth, WpfMap1.ActualHeight)
Dim bufferPointF As ScreenPointF = New ScreenPointF(ScreenPos.X + ScreenBufferSize, ScreenPos.Y)
Dim distanceBuffer As Double = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(WpfMap1.CurrentExtent, ScreenPos, bufferPointF, WpfMap1.ActualWidth, WpfMap1.ActualHeight, WpfMap1.MapUnit, DistanceUnit.Meter)
Dim BufferedShape As MultipolygonShape = WorldPos.Buffer(distanceBuffer, WpfMap1.MapUnit, DistanceUnit.Meter)
'Gets the track overlay
Dim TracksOverlay As LayerOverlay = DirectCast(WpfMap1.Overlays("TracksOverlay"), LayerOverlay)
Dim columnNames As Collection(Of String) = New Collection(Of String)
columnNames.Add("ID")
'Search in all the layers the features within the distance range
For Each tmpFeatureLayer As FeatureLayer In TracksOverlay.Layers
tmpFeatureLayer.Open()
'Dim Features As Collection(Of Feature) = tmpFeatureLayer.FeatureSource.GetFeaturesNearestTo(WorldPos, WpfMap1.MapUnit, 5, columnNames, distanceBuffer, DistanceUnit.Meter)
Dim Features As Collection(Of Feature) = tmpFeatureLayer.QueryTools.GetFeaturesIntersecting(BufferedShape.GetBoundingBox(), columnNames)
For Each tmpFeature As Feature In Features
selectedFeatures.Add(tmpFeature)
Next
tmpFeatureLayer.Close()
Next
Catch
End Try
Return selectedFeatures
End Function
Thanks for reporting.
Howard