bcgov / CCISS_ShinyApp

CCISS RMD knitr report graphics and Shiny App
Apache License 2.0
16 stars 3 forks source link

Dynamically changing vector tile styles #44

Closed kdaust closed 3 years ago

kdaust commented 3 years ago

@meztez again, apologies for all the questions, and if this seems to far outside the scope of the cciss tool no worries. I've been working on a species feasibility app which essentially colours a map of subzones to show suitability of a selected species. Previously I was using the Mapbox library in R, but am currently adapting it to use your leaflet rendering of the vector tiles because it's much nicer. My query is: for the app, I need to be able to quickly change the colours of polygons depending on what species is selected (so i.e. without re-rendering the line work), and was wondering if you had suggestions for the best way to do this. I've been looking a bit into the the setStyle method for leaflet, and I think that might work, but wasn't sure how it would act with the tiles. If you have any suggestions on what the best avenue would be that would be much appreciated! Thanks!

meztez commented 3 years ago

Check the code that does the opacity? You will need to redraw the map to apply a new style. I would have picked mapbox if it was still open source.

Your step should be to have a variable that holds your color scheme per zone in R and JavaScript. Use shiny observer event to sync your values. Redraw the map once you have new values.

I'm skipping a lot of intermediate steps.

There might be some alternative solution but I would have to actually work on the problem.

Best of luck

meztez commented 3 years ago

Maybe add remove layers for each new style?

kdaust commented 3 years ago

Thanks for you suggestions @meztez! I think I've got it figured out. I've actually been able to create a javascript method that takes the new style as parameters and then uses the setFeatureStyle in a loop to update the styles.

meztez commented 3 years ago

you rock @kdaust