I do not get to move the Vector Layer in my OpenLayers script. The layer should be renewed every second. I have already tried a lot, like refresh() and redraw() or OpenLayers.Strategy.Refresh, but nothing has worked for me.

The GeoJSON-"polygon" should be re-layered every second.

Here is a JSFiddle: https://jsfiddle.net/ejts8foc/4/

1 Answer 1


In your case you call the _compute() function just once when page is loaded that's why Geojson coordinates are not updated every second.
Add this function at the end:

            geojsonObject = {
            'type': 'FeatureCollection',
            'crs': {
              'type': 'name',
              'properties': {
                'name': 'EPSG:4326'
            'features': [{
              'type': 'Feature',
              'geometry': {
                'type': 'Polygon',
                'coordinates': [_compute()]
      source.addFeatures((new ol.format.GeoJSON()).readFeatures(geojsonObject,{featureProjection: 'EPSG:3857'}));

The function creates Geojson Object every second with new coordinates and updates the layer. Here is the working Fiddle: https://jsfiddle.net/ygh249ur/

  • wooohooo! yeah! it's moving! I've tried a lot. There are many different approaches to solution and then for OL2, OL3 and OL4. This one is in OL4. My solutions were similar to yours, but just similar. They did not work. Yours works perfectly. Many thanks!
    – Suka
    Oct 4, 2017 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.