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

Add changeColors() for changing the color of a map layer on the fly #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dfriend21
Copy link
Contributor

This PR adds a function to re-map the colors of a leaflet layer on the fly. I had two closely related reasons for creating it:

  1. I had generated some map tiles and wanted the ability to easily change the color scheme without having to regenerate them all (as they took a long time to generate)
  2. I wanted the ability to be able to change the colors of tiles added via WMS

It uses the gradientmaps JavaScript library to change the colors. For an example, here's a WMS layer as-is:

Screen Shot 2023-05-20 at 7 39 57 PM

And here I've changed the colors using the changeColors() function:

Screen Shot 2023-05-20 at 7 40 27 PM

Here's the code to recreate the previous example:

l <- leaflet() %>%
  setView(-112.56, 40.66, 5) %>%
  addTiles() %>%
  addWMSTiles("https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2016_Bare_Ground_Shrubland_Fractional_Component/ows?SERVICE=WMS&",
              layers = "NLCD_2016_Bare_Ground_Shrubland_Fractional_Component",
              options = WMSTileOptions(className = "bare_ground", transparent = TRUE, format = "image/png"))
l
l %>% changeColors("bare_ground", terrain.colors(20))

I thought it might be a good fit for the leafem package, and it seems like something that could be useful for others as well. And from a more selfish point of view, it'd be nice for me if it was part of an already-existing package rather than its own tiny package, which is how I have it right now.

No worries if you'd rather not include it in the package. Also, I'm happy to make any changes to the code and/or documentation.

@dfriend21 dfriend21 changed the title Add change colors Add changeColors() for changing the color of a map layer on the fly May 21, 2023
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

Successfully merging this pull request may close these issues.

None yet

1 participant