import { setOpenRight, setSelectedFeature } from "../appredux/modules/map/actions"; 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]); } } } export const closePopup = () => { const { mymap, routingBarVisible } = store.getState().mapReducer; if (!routingBarVisible) { // only can close popup when routing mode is not visible removeLayerByName('popupTemp'); store.dispatch(setOpenRight(false)); store.dispatch(setSelectedFeature(null)); // if (mymap) { // mymap.invalidateSize(); // } } }