Reputation: 11
Wanted to see if anybody had experience controlling the color scheme/appearance of map tiles loaded into the Leaflet package for R.
I know it's possible in the bare javascript implementation of Leaflet, but I haven't found anything within the rstudio.github documentation for the Leaflet R package or elsewhere.
For my specific purpose I'd like to match the color scheme of the map tiles to the color scheme of the website I plan to host the Leaflet app on. Particularly, specifying colors for roads, water, and land.
Thanks for any insight!
Upvotes: 1
Views: 1056
Reputation: 26258
I've got a Google Maps widget in my googleway
package that accepts a styles
argument.
You need a valid API key to use Google
library(googleway)
map_key <- "your_api_key"
## style taken from https://snazzymaps.com/
## - paper style
style <- '[{"featureType":"administrative","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"landscape","elementType":"all","stylers":[{"visibility":"simplified"},{"hue":"#0066ff"},{"saturation":74},{"lightness":100}]},{"featureType":"poi","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"road.highway","elementType":"all","stylers":[{"visibility":"off"},{"weight":0.6},{"saturation":-85},{"lightness":61}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"road.arterial","elementType":"all","stylers":[{"visibility":"off"}]},{"featureType":"road.local","elementType":"all","stylers":[{"visibility":"on"}]},{"featureType":"transit","elementType":"all","stylers":[{"visibility":"simplified"}]},{"featureType":"water","elementType":"all","stylers":[{"visibility":"simplified"},{"color":"#5f94ff"},{"lightness":26},{"gamma":5.86}]}]'
google_map(key = map_key, styles = style)
Upvotes: 3
Reputation: 21489
The map is not rendered by Leaflet itself. Instead Leaflet downloads pre-rendered raster tiles. They are just images, usually png, sometimes jpeg.
As already explained by user SymbolixAU you can only choose a different tile provider. Leaflet provider demo shows various different providers you can use. This is not an exhaustive list, there are various more providers available on the Internet. However keep in mind that each provider has a different tile usage policy and most won't allow you to use their tiles on a heavy-traffic website or to do bulk downloads. And of course there are also paid-for tile providers available.
Alternatively you can choose to render your own tiles.
Upvotes: 3