1

What is the difference between adding an ImageLayer like this:

new ImageLayer({
    map: map,
});

And this:

map.addLayer(imageLayer);

I'm asking because I can't remove the layer if I pass the map to the ImageLayer in the properties.

map.removeLayer(imageLayer);

1 Answer 1

3

Unmanaged layers are not added to the layer collection, so to remove them you would need to use

imageLayer.setMap(null);

See https://openlayers.org/en/latest/apidoc/module-ol_layer_VectorImage-VectorImageLayer.html#setMap

1
  • Thanks, Mike, I just tried to call the dispose function, and it works also. imageLayer.dispose(). Does it make any difference to your suggestion?
    – BR75
    Aug 19, 2021 at 14:35

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.