leaflet.extras icon indicating copy to clipboard operation
leaflet.extras copied to clipboard

extend the fillOpacity option in the function addGeoJSONChoropleth()

Open TrantorM opened this issue 7 years ago • 7 comments

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);}")
  )

TrantorM avatar Jan 19 '17 15:01 TrantorM

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

bhaskarvk avatar Jan 19 '17 15:01 bhaskarvk

Thank you very much.

TrantorM avatar Jan 19 '17 15:01 TrantorM

Hi @bhaskarvk

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

TrantorM avatar Aug 04 '17 12:08 TrantorM

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

bhaskarvk avatar Aug 04 '17 16:08 bhaskarvk

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

trafficonese avatar Mar 10 '24 18:03 trafficonese

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

TrantorM avatar Mar 10 '24 21:03 TrantorM

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

trafficonese avatar Mar 11 '24 10:03 trafficonese