是否可以在openlayers中为现有的线串添加点?当我们到达客户端时,我有一个来自服务器的点流.目前,我能看到这样做的唯一方法是每次新点进入时从我收到的最后一点到新点画一条线,如下所示:
Drawer.prototype.drawPoint = function(point)
{
var line = new OpenLayers.Geometry.LineString([this.lastPoint, point]);
var lineFeature = new OpenLayers.Feature.Vector(line, null, this.style);
this.lineLayer.addFeatures([lineFeature]);
this.lastPoint = point;
}
Run Code Online (Sandbox Code Playgroud)
这似乎效率低下.显然,我可以保留所有点的数组,并在每次出现新点时重新绘制整行,但这似乎效率低下.
OpenLayers.Geometry.LineString有一个addPoint(point, index)通过OpenLayers.Geometry.MultiPoint它派生的类的方法,看一下源代码.
所以你的解决方案应该简单如下:
line.addPoint(point); //second parameter(index) is optional
Run Code Online (Sandbox Code Playgroud)
您可能还需要redraw()在图层上调用方法.
| 归档时间: |
|
| 查看次数: |
3779 次 |
| 最近记录: |