iTowns / itowns

A Three.js-based framework written in Javascript/WebGL for visualizing 3D geospatial data
http://www.itowns-project.org
Other
1.08k stars 293 forks source link

Data update issue with FeatureGeometryLayer? #2218

Open Criska9527 opened 9 months ago

Criska9527 commented 9 months ago

Hello author , I want to update the data in the FeatureGeometryLayer, but I don't seem to find a way to update the data directly, so I deleted the layer before updating the data, and added it again after updating the data, but I got the following error

Cannot read properties of null (reading 'object3d') at FeatureProcessing.js:23:

Here's my code

` let geojsonfeatures = { type: 'FeatureCollection', crs: { type: 'name'}, features: [

        ]
    };
    geojsonfeatures.features.push(feature)
    let source = new itowns.FileSource({
        // url: './layers/JSONLayers/water.json',
        crs: 'EPSG:4326',
        format: 'application/json',
        fetchedData: geojsonfeatures
    });

    let water2 = new itowns.FeatureGeometryLayer('water2', {
        // Use a FileSource to load a single file once
        source: source,
        transparent: true,
        opacity: 0.1,
        // zoom: { min: 10 },
        style: {
            fill: {
                color: new itowns.THREE.Color('#40FFEC'),
                extrusion_height: 3000,
                opacity: 0.1
            }
        }
    });
    this.view.addLayer(water2)
    setTimeout(()=>{
        const atmosphere = this.view.getLayerById('water2');
        let Sourcegeojsons =  atmosphere.source.fetchedData;
        // Sourcegeojsons.features.push(feature);
        this.view.removeLayer('water2');
        this.view.notifyChange();
        let source1 = new itowns.FileSource({
           // url: './layers/JSONLayers/water.json',
            crs: 'EPSG:4326',
            format: 'application/json',
            fetchedData: Sourcegeojsons
        });
        let _water3 = new itowns.FeatureGeometryLayer('water2', {
                // Use a FileSource to load a single file once
                source: source1,
                transparent: true,
                opacity: 0.1,
                // zoom: { min: 10 },
                style: {
                    fill: {
                        color: new itowns.THREE.Color('#40FFEC'),
                        extrusion_height: 3000,
                        opacity: 0.1
                    }
                }
            });
            this.view.addLayer(_water3);
            this.view.notifyChange();

    },5000)`

How do I go about updating the data in the layer?

itowns version : "2.40.0",