0

我添加了一个 div 和 dropdwn,在每个选项上我都使用 reactjs 中的 addDatatoMap 上传了 geojson 数据。每次我选择该选项时,都会上传相应的图层,但我无法删除以前的图层,因此任何重置/清除地图图层的代码或示例

4

1 回答 1

1

经过这么多研究,我找到了解决方案,所以发布它以节省其他人的时间

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 }
         )
       }
     }
   }
于 2019-11-25T10:03:22.950 回答