I’ve checked the picker demo on the Sandcastle, but I am not understanding how to implement alike for my project.
I have multiple polylines, and when I move with the mouse around I would like to pick the closest point from the polyline which I’ve placed the mouse over.
Since the array of points coming from an array of points with additional properties - the best would be if I can get the index of the closest point.
Is there a way to do this ?
There isn’t a built-in way to compute this, but I would simple loop through the list of points you have, compute the distance from the mouse to each using Cartesian3.distance.
Alternatively, you could find the two closest ones, which form a line, and then find the closest point on that line, which is a common application (you can google “get closest point on line”).
What kind of application/use case are you working on?
The problem is that I have a few tens of thousands of points per line, and i have a few tens of such lines, and I wish to make it instantly…
I am converting Flash application which is based on google maps on Flash, and there is a way … since each point of the polyline is actually exposed as an actual point, and somehow the mechanic is doing it absolutely lighting fast…
But calculating it on mouse move for each point for a millions of points…
Is that application still running somewhere? I’d be curious to take a look.
The easiest thing I can think of is to add your points to some kind of spatial data structure like a quadtree. So even if you have millions of points, you’ll only ever be computing the distance between a small number of points each time the mouse moves.
Unfortunately - it does not run anymore. It was… once before, but not anymore, they dich it, now trying to restore it, but well -Flash is killed because the greed of “some” well known companies, and well- they assigned me to reworking it but one of the hardest part is to recreate the lighting fast flash interactions, and the miniature volume of datа it were allowing ( compressed binary types arrays … etc ).
Well… I was really hoping for something like - when the mouse is near some line to get the nearest point by some internal method.