Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move OpenLayers Vector programmatically?

The API documentation for OpenLayers.Feature.Vector says that Vector itself has no methods at all.

I know how to let user move the Vector by adding OpenLayers.Control.DragFeature control to map. So if the user can move the Vector then there has to ba a way to move it programmatically too. But I can't figure out how to do it.

like image 726
Rene Saarsoo Avatar asked Dec 02 '09 11:12

Rene Saarsoo


2 Answers

You move an OpenLayers.Feature.Vector object by calling methods on its geometry object, not the vector itself. These methods include move, rotate, resize, and transform.

Note that you will not find any of the methods defined on the OpenLayers.Geometry base object but only on the appropriate child object (note that there are multiple level of inheritance within OpenLayers geometries). OpenLayers.Geometry.Collection is a good example.

You can find a great example of programmatically moving OpenLayers vectors here.

like image 195
atogle Avatar answered Oct 15 '22 15:10

atogle


This worked for me:

geometry.move(Y_NextPosition - Y_CurrentPosition, X_NextPosition - X_CurrentPosition)
like image 39
danielB Avatar answered Oct 15 '22 15:10

danielB