Jacob
Jacob

Reputation: 58

How to remove features in an Image Layer, Openlayers 3

So I'm checking to see if there is a way to delete features that exist on an Image layer in Openlayers 3 (e.g. ol.layer.Image({}) ). Here's the code I use to create the layer:

var vector = new ol.layer.Image({
    tethys_legend_title: titleName,
    zIndex: 1,
    source: new ol.source.ImageVector({
        source: vectorSource,
        style: styleFunction,
    }),
});

// Make sure that the layer is not already existing, remove it if the layer does exist
map = TETHYS_MAP_VIEW.getMap();
for (i = 0; i < map.getLayers().getProperties().length ; i ++){
    if (map.getLayers().item(i).getProperties().tethys_legend_title === titleName)
        map.removeLayer(map.getLayers().item(i));
}
vector.tethys_legend_title = 'Water Table';
map.addLayer(vector);

The way I currently understand features that can be deleted in openlayers is through the .removeFeature() method. However, the removeFeature() method only applies to vector layers. Is there a way to delete features that pertain to Image layers? Thanks

Upvotes: 0

Views: 1634

Answers (1)

Alexandre Dub&#233;
Alexandre Dub&#233;

Reputation: 2829

First, you need to access the vector source, which is within the Image source: vector.getSource().getSource(). Then, you'll be able to use the removeFeature method from there, i.e. from the ol.source.Vector object returned..

Upvotes: 1

Related Questions