-
Notifications
You must be signed in to change notification settings - Fork 506
Added removeFeatureGeoJSON, addFeatureGeoJSON, and styleFeatureGeoJSON #163
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
Conversation
…N, shiny interactions data with associated styles.css and countries.geojson
@yihui can you do an initial review of this please? I'll also review after JSM (maybe next week). |
I just reviewed the code and it looks pretty good to me. I'll test the examples later. Thanks @cholcomb! |
I noticed line 5 of shiny_interactions.R says |
invokeMethod(map, getMapData(map), 'removeFeatureGeoJSON', layerId, featureId) | ||
} | ||
|
||
#' @param data in GeoJSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to get rid of this line.
@@ -943,6 +943,42 @@ addGeoJSON = function(map, geojson, layerId = NULL, group = NULL, | |||
invokeMethod(map, getMapData(map), 'addGeoJSON', geojson, layerId, group, options) | |||
} | |||
|
|||
#' @param style a JSON string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or a list
Sorry guys, is this one ready to go? Were you waiting on me? |
Hi @jcheng5 - this feature would be very useful for our OHI Shiny App any status update?? |
Not at the moment, but we just hired a new software engineer and she'll likely be working on Leaflet first. So help is on the way :) |
I created a new PR #303 for this with the new way of doing JS stuff. |
This PR adds a simple version of the aforementioned functions for GeoJSON. For
removeFeatureGeoJSON
, you provide a featureId and layerId (you must have an id in in the GeoJSON, such as geojson$features[[1]]$id whichleaflet-shiny
returns as featureId on events.addFeatureGeoJSON
adds a feature to an existing GeoJSON. Finally,setStyleGeoJSON
also currently requires a style in JSON.There is also a new example, shiny_interactions.R that shows many of the use cases of these functions. You can remove and add back features and then restyle the remaining features, and features are highlighted with mouse hover events. Please note that in a real-use case scenario, the data upon which the coloring is based would not be static. The speed could be improved by setting many styles at once instead of performing a loop for each feature. In addition, the highlighting functionality could be handled on the client side without passing events to R.