I'm a beginner so i might be overlooking something very obvious here: So i have this function, which i call with a button click, to get the layers from the map and if they are either dataLayer2 or dataLayer3 they should be removed and then dataLayer1 should be added to the map. I have the same function for the other dataLayers, which are called from the clicking on other buttons. The layers get added to the map if they are the first one to be added after loading the page. If you click on another button which should remove the active layer and add the new one, the old one gets removed from the map but the new one won't be added. I get no error or anything from the console. The data is all from the same file for all the layers. The styling is just different for the layers depending on different attributes. The geometries stay the same. I tried just loading in the layer and then restyling it with a button click but that also didn't work. Like I said I'm a beginner and might be overlooking something here.
addDataLayer1(){
this.map.getLayers().forEach(layer => {
if (layer === this.dataLayer2 || layer === this.dataLayer3){
this.map.removeLayer(layer);
}
})
this.dataLayer1 = new VectorImage({
source: new VectorSource({
overlaps:false,
features: new TopoJSON().readFeatures(file)
})
});
this.map.addLayer(this.dataLayer1);