[R-sig-Geo] "Preselecting" shapes on leaflet map shiny using mapedit::selectmod

Kent Johnson kent3737 at gmail.com
Thu Mar 22 14:11:50 CET 2018


On Thu, Mar 22, 2018 at 7:00 AM, <r-sig-geo-request at r-project.org> wrote:
>
> Message: 1
> Date: Thu, 22 Mar 2018 12:37:00 +1100
> From: nevil amos <nevil.amos at gmail.com>
> To: r-sig-geo at r-project.org
> Subject: [R-sig-Geo] "Preselecting" shapes on leaflet map shiny using
>         mapedit::selectmod
>
> Hi I  am  putting together a shiny map app in which I want to allow for
> selection or deselection of polygons from  a map layer.
> Importantly At the beginning of the process I would like a subset of the
> polygons to be already selected ( and they can then be deselected using a
> click if required).
> The final set of selected polygons is then saved to disk.
>
> Ideally I would like to be able ( eg using a shiny action button) to reset
> the selection to the pre-selected polygons.


I did something very similar to this using just leaflet and shiny (no
mapedit). I was drawing many polygons and wanted to change the state of a
polygon based on a click.

I don't have the code handy, but basically it was
- create an initial map drawing the polygons with the desired initial
state. Use a unique layerId for each polygon.
- listen to input$map_shape_click with observeEvent. On click, remove the
clicked polygon from the map with leaflet::removeShape(leafletProxy('map',
input$map_shape_click$layerId), change the state of the polygon, and add it
back to the map.
 - Save the state when a "Save" button is clicked.

If there are polygons you don't want to respond to clicks, you will have to
filter them out in the click handler using layerId.

See the Inputs/Events section of the leaflet docs here for more
information: https://rstudio.github.io/leaflet/shiny.html

HTH,
kent

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list