Can someone help me understand the what the GeometryEngine.nearestCoordinate returns? I'm wondering if there is a bug in Runtime v100.1, as I'm seeing different results between a Polyline and a Polygon.
It returns a ProximityResult, which has a pointIndex. What exactly is that pointIndex supposed to be?
I made a basic polyline. I then click along the edges. The pointIndex seems to be the index of the lower vertex of that segment. e.g. if I click between vertices 0 and 1 I get a pointIndex of 0. If I click between vertices 2 and 3 I get 2. And so on.
I tried making a basic square polygon, and then started clicking along the edge. Obviously the polygon has 4 vertices, numbering 0-3. Clicking between 0-1 returns a pointIndex of 0. But as I move along from 1-2, it randomly alternates between returning 1 and 0. Again, as I move between 2-3, it randomly returns sometimes 2 and sometimes 0. And so on.
I have pasted below a very basic sample app. Is there someone that can test this, and confirm is this is either a bug, or whether I'm misunderstanding how the method works?
import QtQuick 2.7
import QtQuick.Controls 2.1
import ArcGIS.AppFramework 1.0
import ArcGIS.AppFramework.Controls 1.0
import Esri.ArcGISRuntime 100.0
Item {
id: mainPage
Graphic{
id: samplePolygon
symbol: SimpleLineSymbol{
color: "blue"
width: Qt.platform.os === "ios" || Qt.platform.os === "android" ? 3 * scaleFactor : 2 * scaleFactor;
style: Enums.SimpleLineSymbolStyleSolid
}
Component.onCompleted: {
geometry = ArcGISRuntimeEnvironment.createObject("Polygon", {json: {"rings":[[[-11136550.000343282,5201675.000715708],[-10361849.999553088,5220725.0007351395],[-10374549.999566041,4573025.000074485],[-11117500.00032385,4598425.000100394],[-11136550.000343282,5201675.000715708]]],"spatialReference":{"latestWkid":3857,"wkid":102100}}
})
}
}
Graphic{
id: samplePolyline
symbol: SimpleLineSymbol{
color: "blue"
width: Qt.platform.os === "ios" || Qt.platform.os === "android" ? 3 * scaleFactor : 2 * scaleFactor;
style: Enums.SimpleLineSymbolStyleSolid
}
Component.onCompleted: {
geometry = ArcGISRuntimeEnvironment.createObject("Polyline", {json: {"paths"
:[[[-11422300.000634747,4122174.9996146187],[-10526949.99972149,4109474.999601665],[-10558699.999753874,3487174.9989669183],[-11390550.00060236,3525274.9990057806]]],"spatialReference":{"latestWkid":3857,"wkid":102100}}
} )}
}
MapView {
id: mapView
anchors.fill: parent
wrapAroundMode: Enums.WrapAroundModeDisabled
magnifierEnabled: true
GraphicsOverlay{
id: drawingLayer
}
onMouseClicked: {
console.log('--------------------------------------------')
var nearestCoordinate = GeometryEngine.nearestCoordinate(samplePolygon.geometry, mouse.mapPoint)
console.log('polygon pointIndex: ', nearestCoordinate.pointIndex)
var nearestCoordinate2 = GeometryEngine.nearestCoordinate(samplePolyline.geometry, mouse.mapPoint)
console.log('polyline pointIndex: ', nearestCoordinate2.pointIndex)
}
Map {
// Set the initial basemap to Streets
BasemapStreets { }
// set initial viewpoint to The United States
ViewpointCenter {
Point {
x: -10800000
y: 4500000
spatialReference: SpatialReference {
wkid: 102100
}
}
targetScale: 3e7
}
onLoadStatusChanged: {
if (loadStatus === Enums.LoadStatusLoaded){
drawingLayer.graphics.append(samplePolygon)
drawingLayer.graphics.append(samplePolyline)
}
}
}
}
}
As a further comment as I try to understand the nearestCoordinate method, I notice that if you pass in a geometry and a point that happens to be exactly one of the vertex points, then it always seems to return a pointIndex of 0.
for example, in the following code, the first console log always returns zero, even though the index is clearly 2, which the second console log correctly returns.
var idx = 2
var nearestCoordinate = GeometryEngine.nearestCoordinate(samplePolygon.geometry, samplePolygon.geometry.parts.part(0).point(idx) )
console.log('polygon pointIndex: ', nearestCoordinate.pointIndex)
var nearestVertex = GeometryEngine.nearestVertex(samplePolygon.geometry, samplePolygon.geometry.parts.part(0).point(idx) )console.log('polygon pointIndex: ', nearestVertex.pointIndex)