Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot remove the heatmap layer #351

Open
taimoorh13 opened this issue Sep 7, 2022 · 1 comment
Open

Cannot remove the heatmap layer #351

taimoorh13 opened this issue Sep 7, 2022 · 1 comment

Comments

@taimoorh13
Copy link

taimoorh13 commented Sep 7, 2022

I am trying to create a heatmap using this library and it does display perfectly using my data. However, the issue us that I want my web app to work with filters. So when a filter is applied, a request is sent to get the filtered the data. Now I want this heatmap to be created on this filtered data. I am trying to remove this existing layer and then add a new heatmap layer from the filtered data but the issue is that when I try to remove it, it shows me an error. This is the error:

Uncaught TypeError: Cannot read properties of undefined (reading '_leaflet_id')

I am trying to use this line of code to remove the layer from the layer control and the map:

var heat =
map.removeLayer(heat);
layerControl.removeLayer(heat);

If I just add the new layer, it still works but I am able to remove the existing heatmap layer. I also tried making the data in it empty before using the filtered data using this line of code:

heat.setData({});

Just a few things that I think may cause problem:
I am removing the layer when a form is submitted. For that I am using jquery to see when the form is submitted. When I try to see the layer properties within the jquery listener, it says that the layer is undefined but when I do it outside the jquery listener, it works so maybe it has to do something with the jquery (I am not an expert so I just caught this observation). Below is the example of what I am saying:

This does not work
$('form').on('submit', function(e){ e.preventDefault(); map.removeLayer(heat);

This works but it does not fulfill my purpose as I cant track when the form was submitted before removing the heat layer:

map.removeLayer(heat); $('form').on('submit', function(e){ e.preventDefault();

Can you please help me in sorting this issue.

Thank you!

@davquar
Copy link

davquar commented Oct 24, 2022

I also tried making the data in it empty before using the filtered data using this line of code:

Hi, heat.setData({data: []}) should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants