我在每个选项上添加了一个div和dropdwn,我已经在reactjs中使用addDatatoMap上传了geojson数据。 每当我选择该选项时,都会上传相应的图层, 但是我无法删除之前的图层, 因此,任何用于重置/清除地图图层的代码或示例
答案 0 :(得分:0)
经过大量研究,我找到了解决方案,因此将其发布以节省其他人的时间
import KeplerGlSchema from 'kepler.gl/schemas';
import { visStateUpdaters } from 'kepler.gl/reducers';
// // Clear Uploaded Data
RemoveUploadedData() {
// // returns uploaded Data on map
const dataToSave =
KeplerGlSchema.getDatasetToSave(this.props.demo.keplerGl.map);
console.log('dataToSave', dataToSave);
// // returns uploaded layer config on map
const configToSave =
KeplerGlSchema.getConfigToSave(this.props.demo.keplerGl.map);
console.log('configToSave', configToSave);
var layerConfigs = configToSave.config.visState.layers;
// // Removed each uploaded layers
if (configToSave && layerConfigs.length > 0) {
for (var i = 0; i < layerConfigs.length; i++) {
this.props.demo.keplerGl.map.visState =
visStateUpdaters.removeDatasetUpdater(
this.props.demo.keplerGl.map.visState,
{ key: dataToSave[i].data.id }
)
}
}
}