Closed ShaneMill1 closed 3 years ago
Hi @ShaneMill1 - sorry for the slow reply to this, which does sound like a bug. I think we might have to wait until @guygriffiths is back from leave before getting a proper answer, apologies
Apologies, I hadn't seen this. For some reason I wasn't getting notifications for this repository - probably because I never actually contributed to it? Anyway, I can certainly take a look. @ShaneMill1 - do you have some sample code you could share which demonstrates this issue?
@guygriffiths Thanks a lot for the response! I created the following codepen that replicates the issue we are having elsewhere. It attempts to alter the data but adding a new data array into the CoverageJSON when clicking the button above the map:
https://codepen.io/shanemill1/pen/VwbReXg
It may be that I am not altering the data as intended? Any feedback would be very much appreciated!
@ShaneMill1 - The issue is that the leaflet coverage plugin caches the values, so when you simply modify the existing object, it still reads from the cache (which is at covJSON.ranges.temperature._ndarr.data
) when plotting. So your choices are:
covJSON.ranges.temperature._ndarr.data
. The coverage itself will be wrong.covJSON.ranges.temperature._ndarr.data
and covJSON.ranges.temperature.values
. This will update the coverage object and the cached dataHowever, if you do the latter, your example will still not work because you are adding a new layer on top of the existing one (so both layers will be visible). You need to remove that layer first.
You can see an adjusted working version here: https://codepen.io/guygriffiths/pen/YzQoYxB This extracts the fetch of the data into a function, then uses that twice (once initially, then once again when it removes the values), and calls the necessary layer-removing code.
Hope this helps.
Thank you for the clarification!! This is very very helpful. I will give this a try and confirm the approach on me end. Thanks again!
Hello all,
At the National Weather Service, we are implementing the OGC Environmental Data Retrieval API which outputs CoverageJSON.
We are developing a client that will make a data query from the EDR-API, and is able to successfully plot the data using the leaflet-coverage library.
Now, based on a threshold, we want to replace the data within the CoverageJSON that doesn't meet the threshold with "null". We seem to be able to create an updated CoverageJSON to do this.
The problem is when we try to plot the new CoverageJSON, the old layer appears, not the new updated data. My instinct is that the original layer has the name "Grid" and the new layer also has the name "Grid", so maybe it is taking cache from the older layer.
Has anyone experienced this before, or what are the best practices for deleting an old layer completely and adding a new layer. I have tried the leaflet removeLayer function, tried deleting all layers, tried recreating the map altogether, and the layer never updates.