trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
214 stars 74 forks source link

extend the fillOpacity option in the function addGeoJSONChoropleth() #53

Open TrantorM opened 7 years ago

TrantorM commented 7 years ago

Hi @bhaskarvk Thank you very much for this wonderful package. You did a great job.

The option fillOpacity in the functionaddGeoJSONChoropleth() seems to work just with a constant value (e.g. fillOpacity = 0.7). Would it be possible to extend it, that it can handle also feature properties in the same way like the valueProperty can do? In this was, one could weight the opacity of the polygons e.g. according to the significance of the data. In the example below I want to control the opacity with the dist_num property, which is meaningless but it shows what I want to do.

library(leaflet)
library(leaflet.extras)   
topojson <- readr::read_file("https://rawgit.com/TrantorM/leaflet-choropleth/gh-pages/examples/basic_topo/crimes_by_district.topojson")

leaflet() %>% 
  setView(-75.14, 40, zoom = 11) %>%
  addProviderTiles("CartoDB.Positron") %>% 
  addGeoJSONChoropleth(
    topojson,
    valueProperty ='incidents',
    fillOpacity = JS("function(feature){return (feature.properties.dist_num / 100);}")
  )
bhaskarvk commented 7 years ago

Yes it is certainly possible to do this. I will add it to my list.

TrantorM commented 7 years ago

Thank you very much.

TrantorM commented 7 years ago

Hi @bhaskarvk

I saw that your are working again on the great leaflet.extra package. Is this issue still on your work list?

bhaskarvk commented 7 years ago

Yup, I hope to close out most issues in next 1 to 2 month period.

trafficonese commented 6 months ago

@TrantorM do you have a working solution for this? If yes, could you please open a PR? I would be happy to merge it!

TrantorM commented 6 months ago

@trafficonese sorry, I'm not working on this anymore.

trafficonese commented 6 months ago

Ok, but you're fork seems to work with different fillOpacities or am I wrong?