Skip to content Skip to sidebar Skip to footer

Dynamically Adding And Removing Segments From A Track In Openlayers 3

I want to display a track in real-time with OpenLayers 3 which disolves at the end, just like a snails trail. Only appending new coordinates to a LineString is easy. See this exam

Solution 1:

The appendCoordinate method is a shortcut for the fairly common use case of adding a coordinate to the end of a LineString. To modify geometries with more control, set your desired coordinates with setCoordinates.

var maxCoords = 100;
var coords = lineString.getCoordinates(); // get coordinate array
coords.unshift(newCoord); // add to beginning of array
if (coords.length > maxCoords) {
    coords.length = maxCoords;
}
lineString.setCoordinates(coords);

Post a Comment for "Dynamically Adding And Removing Segments From A Track In Openlayers 3"