Skip to content

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

Closed
wants to merge 9 commits into from

Conversation

chris-holcomb
Copy link

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 which leaflet-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.

@jcheng5
Copy link
Member

jcheng5 commented Aug 12, 2015

@yihui can you do an initial review of this please? I'll also review after JSM (maybe next week).

@yihui
Copy link
Member

yihui commented Aug 13, 2015

I just reviewed the code and it looks pretty good to me. I'll test the examples later. Thanks @cholcomb!

@chris-holcomb
Copy link
Author

I noticed line 5 of shiny_interactions.R says library(rescale) instead of library(scales).... Also we probably want to rename setStyleGeoJSON to styleFeatureGeoJSON because this function is just for styling one feature. I went ahead and committed those changes.

@chris-holcomb chris-holcomb changed the title Added removeFeatureGeoJSON, addFeatureGeoJSON, and setStyleGeoJSON Added removeFeatureGeoJSON, addFeatureGeoJSON, and styleFeatureGeoJSON Aug 13, 2015
invokeMethod(map, getMapData(map), 'removeFeatureGeoJSON', layerId, featureId)
}

#' @param data in GeoJSON
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or a list

@jcheng5
Copy link
Member

jcheng5 commented Sep 23, 2015

Sorry guys, is this one ready to go? Were you waiting on me?

@jamiecmontgomery
Copy link

Hi @jcheng5 - this feature would be very useful for our OHI Shiny App any status update??

@jcheng5
Copy link
Member

jcheng5 commented Feb 24, 2016

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 :)

@bhaskarvk bhaskarvk self-assigned this Oct 4, 2016
@bhaskarvk
Copy link
Collaborator

I created a new PR #303 for this with the new way of doing JS stuff.

@bhaskarvk bhaskarvk closed this Oct 4, 2016
@bhaskarvk bhaskarvk added duplicate Already catalogued and removed in progress labels Oct 4, 2016
@bhaskarvk bhaskarvk added this to the v1.1 milestone Oct 4, 2016
@jrisi256 jrisi256 mentioned this pull request Apr 2, 2018
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Already catalogued
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants