emilhe / dash-leaflet

MIT License
213 stars 37 forks source link

Issue: changing properties of a WMSTileLayer with a callback causes the layer to disappear #135

Open jnrobinson opened 2 years ago

jnrobinson commented 2 years ago

Hi,

I am trying to modify the extraProps property of a WMSTileLayer with a callback to access different historical images. I am able to see the imagery on the map initially, but once I try to change extraProps with a callback, the layer disappears. I have also tried modifying the transparent property with a callback to test the issue, and that also caused the layer to disappear.

The layer is defined in the app layout as follows:

dl.WMSTileLayer(
    url="https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi", # example NEXRAD data
    layers="nexrad-n0r-wmst", 
    format="image/png", 
    transparent=True,
    attribution='Weather data by <a href="https://mesonet.agron.iastate.edu/">Iowa Environmental Mesonet</a> of Iowa State University',
    extraProps=dict(
        time=_start_datetime.strftime("%Y-%m-%dT%H:%M:%SZ"),
    ),
    id="map-weather-n0rt",
)

I am trying to change the time by using a callback to set map-weather-n0rt.extraProps to

dict(
    time=current_time.strftime("%Y-%m-%dT%H:%M:%SZ"), # historical time
)

which causes the layer to disappear. However, I am able to view different historical images by modifying the extraProps["time"] value in the initial layer definition, so I don't think it's an issue with the WMS server.

Is there something else I need to do to refresh the map after changing the extraProps property?

Thanks

jnrobinson commented 2 years ago

After further testing I think this may be an issue that is unrelated to dash-leaflet. It might be caused by how I'm formatting the time requests to the server.

Is there a way of monitoring the WMS request sent by WMSTileLayer when it updates? It would be nice to see what message it sends and what it gets back.

emilhe commented 2 years ago

Yes, you can use the developer tool in e.g Chrome to monitor the network requests. When you pan the map, you'll see requests fired - these are the ones to look at.

jnrobinson commented 2 years ago

Hi Emil,

Thanks for the suggestion. I was able to track down the issue:

On the first map load, the WMS request does not include the "attribution" property of the WMSTileLayer. However, once I change the extraProps, subsequent WMS requests include the "attribution" property and its contents which results in an invalid WMS request which only returns blank tiles.

When I remove the attribution from the WMSTileLayer, it works as intended, but now I can't properly attribute the weather data to the correct source. I tried adding the attribution to the dl.Overlay that wraps the WMSTileLayer, but that isn't a supported property for that layer.

Do you know if there's any other way I can specify the attribution for that layer while also keeping it out of the WMS request?

Thanks