import { store } from "../appredux/store"; export const removeLayerByName = (layerName) => { const {mymap} = store.getState().mapReducer; var layerToRemove = []; mymap.eachLayer(function(layer) { if (layer.wmsParams) { if (layer.wmsParams.layers) { let layerWmsName = layer.wmsParams.layers.split(':')[1]; if (layerName === layerWmsName) { layerToRemove.push(layer) } } } else { if (layer.options && layer.options.name && layer.options.name === layerName) { layerToRemove.push(layer); } } }); if (layerToRemove.length > 0) { for (let i = 0; i < layerToRemove.length; i++) { mymap.removeLayer(layerToRemove[i]); } } }