简体   繁体   English

如何以编程方式移动OpenLayers Vector?

[英]How to move OpenLayers Vector programmatically?

The API documentation for OpenLayers.Feature.Vector says that Vector itself has no methods at all. OpenLayers.Feature.Vector的API文档说Vector本身根本就没有方法。

I know how to let user move the Vector by adding OpenLayers.Control.DragFeature control to map. 我知道如何通过添加OpenLayers.Control.DragFeature控件来映射用户来移动Vector。 So if the user can move the Vector then there has to ba a way to move it programmatically too. 因此,如果用户可以移动Vector,那么必须以编程方式移动它。 But I can't figure out how to do it. 但我无法弄清楚该怎么做。

You move an OpenLayers.Feature.Vector object by calling methods on its geometry object, not the vector itself. 通过调用其几何对象上的方法而不是向量本身来移动OpenLayers.Feature.Vector对象。 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基础对象上定义的任何方法,但仅在相应的子对象上找到(请注意,OpenLayers几何中有多个级别的继承)。 OpenLayers.Geometry.Collection is a good example. OpenLayers.Geometry.Collection就是一个很好的例子。

You can find a great example of programmatically moving OpenLayers vectors here . 您可以在此处找到以编程方式移动OpenLayers向量的绝佳示例。

这对我有用:

geometry.move(Y_NextPosition - Y_CurrentPosition, X_NextPosition - X_CurrentPosition)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM