Skip to content
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

version 0.6 combining changes from multiple pull requests #107

Merged
merged 15 commits into from
Feb 1, 2020

Conversation

timelyportfolio
Copy link
Contributor

This pull should represent the combination of #100, #103, and #97 thanks to the very generous contributions from @JoshOBrien @Gutschlhofer. Hopefully, this will be on CRAN soon. Sorry for the inexcusable delay.

Gutschlhofer and others added 15 commits May 21, 2019 12:04
Previously, some of that logic was in `editMod()` and some (the part
that conditionally set `allowSelfIntersection = FALSE` for 2-D
features) was in `editFeatures.sf()`.

Migrating this logic involved one complication. Whereas in
`editFeatures.sf()` one can directly query the `sf` object being
edited for its dimension, in the farther downstream `editMod()`, that
object is no longer available. By then, the `sf` object has been
processed (in `editFeatures.sf()`) by `leafem::addFeatures()` which
adds the features to the map object. As a result, in `editMod()`, I
now test for the presence of calls to `addPolylines()` or
`addPolygons()` among the `methods` elements in `leafmap$x$calls`. I
believe that covers all of the possibilities that were formerly caught
by `if(any(sf::st_dimension(x) == 2))`, but I have not exhaustively
tested this.

This commit also replaces repeated use of `editor[1]` with an
equivalent but clearer initial call to `editor <- match.arg(editor)`.
The new `editOptions=` 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.

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:

```r

library(sf)
library(mapedit)

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)

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)

optsB <- list(editOptions = list(remove = FALSE),
              circleOptions = FALSE,
              markerOptions = FALSE,
              circleMarkerOptions = FALSE,
              rectangleOptions = FALSE)
x <- editFeatures(pp, editor = "leaflet.extras", editorOptions = optsB)
```
Make new editorOptions() argument available in drawFeatures
@JoshOBrien
Copy link
Contributor

Great. Thanks for pulling this all together and pushing it up to CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants