r-spatial / mapedit

Interactive editing of spatial data in R
https://www.r-spatial.org/r/2019/03/31/mapedit_leafpm.html
Other
218 stars 33 forks source link

New editorOptions= argument for lower-level toolbar customization #100

Closed JoshOBrien closed 5 years ago

JoshOBrien commented 5 years ago

The new editorOptions= argument takes a user-supplied list of named options that are ultimately passed on to either leafpm::addPmToolbar() or leaflet.extras::addDrawToolbar(), depending on the value of the editor= argument. (This addresses #92 and incorporates suggestions made in the discussion resulting from #97)

When editor = "leafpm", the list can consist of one or more elements with names "toolbarOptions", "drawOptions", "editOptions", and "cutOptions". For details, see ?leafpm::addPmToolbar.

When editor = "leaflet.extras", allowable names for list elements are "polylineOptions, "polygonOptions", "circleOptions", "rectangleOptions", "makerOptions", "circleMarkerOptions", and "editOptions". For details, see ?leaflet.extras::addDrawToolbar.

Currently, there is no checking or validation of the list passed in to editorOptions=, so users will need to take particular care that the list's structure (including the names of all of its elements) match with what is expected by the leafpm::addPmToolbar() or leaflet.extras::addDrawToolbar() functions.

Here are few simple examples demonstrating the new argument's usage:


library(sf)
library(mapedit)

##------------------------------------------------------------------------------
## Simple example for testing
##------------------------------------------------------------------------------
x <- list(matrix(c(11,0,11,1,12,1,12,0,11,0), ncol = 2, byrow = TRUE))
pp <- st_sf(geom = st_sfc(st_polygon(x)), crs = 4326)
## ll <- st_sf(geom = st_sfc(st_linestring(matrix(1:4,2))), crs = 4326)

##------------------------------------------------------------------------------
## Passing options to leafpm editor
##------------------------------------------------------------------------------
optsA <- list(drawOptions = list(snappable = FALSE,
                                 hintlineStyle = list(color = "red",
                                                      opacity = 0.5),
                                 templineStyle = list(color = "red")),
              editOptions = list(snappable = FALSE))
x <- editFeatures(pp, editor = "leafpm", editorOptions = optsA)

##------------------------------------------------------------------------------
## Passing options to leaflet.extras editor
##------------------------------------------------------------------------------
## A stripped down toolbar
optsB <- list(editOptions = list(remove = FALSE),
              circleOptions = FALSE,
              markerOptions = FALSE,
              circleMarkerOptions = FALSE,
              rectangleOptions = FALSE)
x <- editFeatures(pp, editor = "leaflet.extras", editorOptions = optsB)

## A more complicated example, resetting several colors
myShapeOpts <-
    leaflet.extras::drawShapeOptions(color = "red", fillColor = "red",
                                     opacity = 0.5, fillOpacity = 0.1,
                                     weight = 4)
optsC <- list(circleOptions = list(shapeOptions = myShapeOpts),
              polygonOptions = list(shapeOptions = myShapeOpts),
              rectangleOptions = list(shapeOptions = myShapeOpts))
x <- editFeatures(pp, editor = "leaflet.extras", editorOptions = optsC)
tim-salabim commented 5 years ago

@JoshOBrien this looks good to me. See my comment here. I haven't tested any of it though (just looked over it).

timelyportfolio commented 5 years ago

@JoshOBrien @tim-salabim I have merged #98 and this pull into develop branch for a short review period and then plan to merge to master and submit to CRAN. Thanks everyone for the contributions. I love it when open source works as it should.

Sorry for the very long delay. This is not how I anticipate operating going forward.

timelyportfolio commented 5 years ago

@tim-salabim will you please test develop which includes #98 and #100?

timelyportfolio commented 5 years ago

@tim-salabim I ran CRAN-checks and everything passes except for #102.

tim-salabim commented 5 years ago

@timelyportfolio. I just arrived in the us. Will try to find some time to test this week.

timelyportfolio commented 5 years ago

@JoshOBrien looks like force push closed this pull request. Was this intentional? If you made changes I will try to add into develop.

JoshOBrien commented 5 years ago

Oops. No, not intentional, so please disregard.

On Mon, Jul 22, 2019, 05:10 timelyportfolio notifications@github.com wrote:

@JoshOBrien https://github.com/JoshOBrien looks like force push closed this pull request. Was this intentional? If you made changes I will try to add into develop.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/r-spatial/mapedit/pull/100?email_source=notifications&email_token=AA2RGJNPGXKR3AUUX2W5HUDQAWPRZA5CNFSM4HUERFFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2PW4IQ#issuecomment-513764898, or mute the thread https://github.com/notifications/unsubscribe-auth/AA2RGJNH25SA5KAPW5EOAZ3QAWPRZANCNFSM4HUERFFA .

tim-salabim commented 5 years ago

@timelyportfolio I've had a test run. The only thing I fund missing is that the new editorOptions() argument is not available in drawFeatures. Should be an easy fix though. Other than that, things seem to behave as expected, though I did not check all available options. I feel comfortable for this to go live (CRAN) if you are.

Thanks guys for this awesome addition!!