openlayersopenlayers-5

Is there a way to force a map reload/refresh in openlayers 5?


Using openlayers 5, I'm getting an issue where geometry persists on the map after deleting it - seems like the map isn't updating properly. Is there a way to force an update / refresh of the map and its features? Can't find anything related to that in the documentation.

Tried using map.render() but that doesn't seem to work either.

Calling .getFeatures() on my VectorSource object shows that the geometry/object is not in the features list, but it still appears on the map on my page.


Solution

  • [EDIT] As noted in the OpenLayers changelog v6.0.0 you have now to call:

    layer.changed()
    

    Try to refresh your source:

    layer.getSource().refresh();
    

    Or do this for all layers:

    map.getLayers().forEach(layer => layer.getSource().refresh());
    

    If this still does not work:

    Assuming your layer is the first layer, try console.log(map.getLayers()[0].getFeatures());. Are the deleted features logged? If so, it might be a reference problem.