Select to view content in your preferred language

Delete Cluster Layers

185
2
08-07-2024 11:06 PM
LIZDean
Occasional Contributor

I have some Javascript code that creates three cluster layers.

I need to be able to clear the three layers (workLayer, educationLayer, volunteerLayer) when I start a new process but can't figure out the right function.

This is what I have but it leaves the layers / graphics there.

 function clearLayers() {
                [workLayer, educationLayer, volunteerLayer].forEach(layer => {
                    if (layer.source) {                        
                        layer.source.remove()                                              
                    }
                });
            }

 

 

 

Tags (2)
0 Kudos
2 Replies
Sage_Wall
Esri Contributor

Hi @LIZDean 

  • FeatureLayer.applyEdits() - if you want to delete the features but leave the layers for later use
  • Map.removeMany() - if you want to remove the layer from the map but maybe readd it again
  • FeatureLayer.destroy() - if you want to destroy the reference to the layer and free up the memory. The layer and any associated resources no longer exist.
LIZDean
Occasional Contributor

Thanks @Sage_Wall I will give them a go 🙂

0 Kudos