Animate a point alongside a line from known coordinates

Alexandre Dubé

In a JavaScript application that uses OpenLayers 4.5.0, where I have a linestring and a point in a map. The point is located "on" the linestring.

Now, I want to move the point to an other location on the linestring, while animating alongside the line for a given period of time.

This is the information that I have, i.e. that I'm working with:

  • I have the coordinate of the point
  • I have the coordinate where to move the point to
  • I have the geometry of the linestring
  • I know that both coordinates (start and end) are on the line

I also have a good idea how to implement the animation. What I do not know is how to obtain the location alonside the line while animating.

I'm aware of the method ol.geom.LineString.prototype.getCoordinateAt, which allows you to get a coordinate of a linestring given a fraction. What I think I would need is the opposite: I have the coordinates. I need the fractions of the start and end. If I had those, I would be able to calculate the fraction between the two while animating.

Is there a way to accomplish this with OpenLayers?

Update

Here's a picture that represents what I want to do. More explanation below it.

Preview of what I want to do

  1. I have a line string and point only. The point is on the line (not at a vertex)
  2. I get a new location where I want to move the point
  3. I want to move the point alongside the line in an animation. The arrow I drew is the path I want the point to move. In other words, it's a sub-section of the line string from the original location of the point and its destination.

If I know the 2 fractions of the linestring in question (the ones at the start and end), then I could retreive the fraction while animating. If, for example, I know that the start is 0.2 and the end 0.8, then I'd know that if I'm 10% there in the animation, then I'd need to show my point to 0.26.

I hope this helps understand what I'm trying to do.

Alexandre Dubé

I've been able to accomplish what I needed to do using the ol-ext library, more specifically using the splitAt method. Here's the recipe I used:

First, for each coordinated I had, I had to make sure that they "snap" to the line. I did so using the getClosestPoint method in OpenLayers, like so:

// Get "closest" start and end coordinates for segment computing
var closestStartCoordinate = lineString.getClosestPoint(startCoordinate);
var closestEndCoordinate = lineString.getClosestPoint(endCoordinate);

Then, if I use the splitAt method, I get multiple segments. The one I need is the one with start coordinate equal to closestStartCoordinate and end coordinate equal to closestEndCoordinate.

And that's it! I have my segment. While the animation is in progress, I'm able to use the getCoordinateAt method from the segment depending on the elapsed time of the animation to get the location to move my point to while it is in progress.

Thanks to @pavlos for pointing this out. Thanks to the authors of the ol-ext library!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTML5 Canvas animate line from point A to point B

From Dev

Finding coordinates of a point on a line

From Dev

GPS coordinates of a point between two known points

From Dev

get coordinates of arrow of a line point

From Dev

Transform point from DWG model coordinates to autodesk forge viewer coordinates

From Dev

How to animate change of background from one point

From Dev

triangulate center point with accuracy from set of coordinates

From Dev

Where do the point coordinates come from in touchesEnded?

From Dev

Get coordinates from a lambda function point

From Dev

Determine screen coordinates from point in DirectX world

From Dev

Calculate GPS coordinates from a starting point

From Dev

Determine the position of a point in 3D space given the distance to N points with known coordinates

From Dev

Finding the coordinates on the image knowing the center point and slope of a line

From Dev

Point picker event_handler drawing line and displaying coordinates in matplotlib

From Dev

Can I animate the X- and Y- coordinates of a WPF Bezier curve control point separately?

From Dev

Can I animate the X- and Y- coordinates of a WPF Bezier curve control point separately?

From Dev

How to draw a line from point to point in Processing

From Dev

ffmpeg draw a line from point to point

From Dev

How to animate alongside a UISearchController presentation/dismissal animation?

From Dev

Add subview later to animate alongside superview

From Dev

Distance of point from a line not working

From Dev

Find a line intersecting a known line at right angle, given a point in spherical system

From Dev

Generate random geo coordinates within specific radius from seed point

From Dev

Getting a lattitude & longitude point on earth from ECI coordinates of a satellite

From Dev

Getting point coordinates from `matplotlib.pyplot.plot`

From Dev

Extract <Point> coordinates from KML using shell tools

From Dev

Animate Svg Path D coordinates

From Dev

Animate canvas point

From Dev

Get Coordinates around a point

Related Related

  1. 1

    HTML5 Canvas animate line from point A to point B

  2. 2

    Finding coordinates of a point on a line

  3. 3

    GPS coordinates of a point between two known points

  4. 4

    get coordinates of arrow of a line point

  5. 5

    Transform point from DWG model coordinates to autodesk forge viewer coordinates

  6. 6

    How to animate change of background from one point

  7. 7

    triangulate center point with accuracy from set of coordinates

  8. 8

    Where do the point coordinates come from in touchesEnded?

  9. 9

    Get coordinates from a lambda function point

  10. 10

    Determine screen coordinates from point in DirectX world

  11. 11

    Calculate GPS coordinates from a starting point

  12. 12

    Determine the position of a point in 3D space given the distance to N points with known coordinates

  13. 13

    Finding the coordinates on the image knowing the center point and slope of a line

  14. 14

    Point picker event_handler drawing line and displaying coordinates in matplotlib

  15. 15

    Can I animate the X- and Y- coordinates of a WPF Bezier curve control point separately?

  16. 16

    Can I animate the X- and Y- coordinates of a WPF Bezier curve control point separately?

  17. 17

    How to draw a line from point to point in Processing

  18. 18

    ffmpeg draw a line from point to point

  19. 19

    How to animate alongside a UISearchController presentation/dismissal animation?

  20. 20

    Add subview later to animate alongside superview

  21. 21

    Distance of point from a line not working

  22. 22

    Find a line intersecting a known line at right angle, given a point in spherical system

  23. 23

    Generate random geo coordinates within specific radius from seed point

  24. 24

    Getting a lattitude & longitude point on earth from ECI coordinates of a satellite

  25. 25

    Getting point coordinates from `matplotlib.pyplot.plot`

  26. 26

    Extract <Point> coordinates from KML using shell tools

  27. 27

    Animate Svg Path D coordinates

  28. 28

    Animate canvas point

  29. 29

    Get Coordinates around a point

HotTag

Archive