Is it possible to add points to an existing linestring in openlayers? I have a stream of points coming from the server that I wish to draw when they arrive on the client. Currently, the only way I can see to do this is to draw a single line from the last point that I received to the new point each time a new point comes in, like so:
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;
}
This seems inefficient. Obviously I could keep an array of all of the points and redraw the whole line each time a new point comes in, but that seems inefficient too.
OpenLayers.Geometry.LineStringhas a methodaddPoint(point, index)through theOpenLayers.Geometry.MultiPointclass that it derives from, take a look at the source code.So your solution should be as simple as:
You will probably need to call
redraw()method on the layer as well.