You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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!
The text was updated successfully, but these errors were encountered: