GithubHelp home page GithubHelp logo

leaflet.pm and mapedit about mapedit HOT 32 CLOSED

r-spatial avatar r-spatial commented on July 24, 2024
leaflet.pm and mapedit

from mapedit.

Comments (32)

codeofsumit avatar codeofsumit commented on July 24, 2024 2

@lbusett please open issues like that in the leaflet.pm repo where I track the issues.
I will answer your points here but please move the discussion about leaflet.pm features to that repo:
https://github.com/codeofsumit/leaflet.pm

To your points:

  • Yes, moving layers in edit mode can (and was in the past) a separate button. As I'm thinking about implementing rotation which has to be its own button, I might as well put moving back as well. Please open an issue for that, I'll make it a feature request

  • the cutting tool can't work in circles because leaflet doesn't support a multi-vertex shape with rounded sides. Not even sure if there is a library that can give me a valid geojson shape if you subtract a polygon from a circle. AFAIK: not possible.

  • your last point on styling is left up to the application that uses leaflet.pm. In this case mapedit. I'm also working on Geoman.io which will also provide layer styling but it's not part of leaflet.pm

from mapedit.

codeofsumit avatar codeofsumit commented on July 24, 2024 2

@tim-salabim yes, the abtraction would be to bind all toolbar buttons to keyboard shortcuts which is something I'm planning as well.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024 1

@tim-salabim actually that is what I expected. I'll work now on some logic to handle this case.

from mapedit.

codeofsumit avatar codeofsumit commented on July 24, 2024 1

Hi everyone, maintainer of leaflet.pm here 🙋‍♂️ . Just wanted to chim in real quick and say that I'm happy you are considering leaflet.pm.
I will tackle the performance issue asap. If there are any other issues you need sorted out, feel free to report them in the leaflet.pm repo and I'll make sure to respond asap and help out where I can.

Keep it up and happy new year 🎆

from mapedit.

codeofsumit avatar codeofsumit commented on July 24, 2024 1

@tim-salabim nice, will be easy to implement and it was on my list anyway. It will come!

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024 1

maybe moving the complete shape could be bound to a key press event? E.g. when pressing Alt + Click the polygon can be moved

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024 1

@tim-salabim @lbusett I added a handler for cut in r-spatial/leafpm@ec34732. Hope it is ok, but I chose to communicate as an edit for mapedit purposes. Please let me know if you think we need to separate out the logic between cut and edit in mapedit.

mapedit_cut

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

Thanks @timelyportfolio for implementing Leaflet.pm. My first impression is indeed a much nicer experience than with Leaflet.draw. The snapping is really useful. And being able to cut holes is also a very nice addition.

A few observations (after about 3 trials):

  1. when I use editFeatures(franconia[c(1, 5),], editor = "leafpm") and try to change the background layer twice, I see
Listening on http://127.0.0.1:7697
Warning: Error in : should be of type 'Feature'
  72: stop
  71: FUN
  70: lapply
  68: FUN
  67: lapply
  66: <reactive>
  50: crud
  49: <observer>
   6: shiny::runApp
   5: shiny::runGadget
   4: editMap.leaflet
   2: editFeatures.sf
Error: should be of type 'Feature'
  1. When trying to completely delete an existing hole, e.g. in editFeatures(franconia[5,], editor = "leafpm"), I get the following error:
Listening on http://127.0.0.1:7697
Error in FUN(X[[i]], ...) : polygons require at least 4 points

I think this can be easily caught by checking the returned features which in case of a POLYGON with hole(s) is a list of matrices. My guess is that sf trips over an empty list entry, i.e. the hole that has been deleted.

  1. On a more general note, I think the package name (and subsequently the editor choice entry) should be leaflet.pm to be in line with all other leaflet add-on R packages.

How should we proceed? Shall we keep leaflet.pm and the mapedit leafpm branch in your account for now or should we transfer both to r-spatial early and work from there? My preference would be the latter, as I tend to get confused quickly with PRs from forked repos to repos that are forked from the original...

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim thanks so much for the first round of feedback. I'll respond below.

  1. "when I use editFeatures(franconia[c(1, 5),], editor = "leafpm") and try to change the background layer twice, I see"

    I'm so sorry, but I could not figure out what you mean "try to change the background layer twice". Happy to look into this once I understand.

  2. cutting and deleting a hole

    I did not spend much time on cutting, so not surprised this does not work perfectly. I agree with you that handling this error on the R side seems straightforward. I'm glad that this does not appear to be an issue inside the Leaflet.pm JavaScript.

  3. package name and next steps

    leaflet.pm makes sense and is consistent with convention, but I dislike this convention for two reasons (I understand completely though if you overrule). One, naming the R package the same as the JavaScript repo can be confusing to users, and I have seen where issues are submitted on the JavaScript repo because the R user did not know the difference. Two, selfishly on my computer, I keep all my projects (JavaScript and R) in one parent directory. Having the JavaScript and R named the same means I have to do confusing things with path naming.

    I agree with transferring to r-spatial. I just wanted to get the first round of feedback to make sure I was on the correct path before making an implied commitment that comes with the r-spatial home.

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

@timelyportfolio I should have been more explicit about

  1. changing background layer twice
    this has nothing to do with the editing as such, it happens when you use the layer control and switch the background map from the default CartoDB.Positron to any of the other layers (once is fine, but changing again will crash the session). Here's a more explicit example:
m = leaflet() %>%
  addProviderTiles("CartoDB.Positron", group = "CartoDB.Positron") %>%
  addProviderTiles("CartoDB.DarkMatter", group = "CartoDB.DarkMatter") %>%
  addLayersControl(baseGroups = c("CartoDB.Positron", "CartoDB.DarkMatter"))

editFeatures(franconia[c(1, 5),], map = m, editor = "leafpm")

When you use the layer control at the topright of the map twice, the session crashes (at least for me).

  1. cutting and deleting
    I'll have a look at how to handle this on the R side once we migrated to r-spatial

  2. package name and next steps
    I completely agree with your reasoning and like your approach on package naming so I think we should stick with leafpm. I will also use apply this naming scheme to leaflet.glify and rename accordingly to leafgl - let's make this a thing!
    I think transferring package leafpm and the leaflpm branch in mapedit to r-spatial as it is now is fine.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim I understand now, and I'll work on a fix. I'll transfer leafpm and the mapedit leafpm branch in just a bit. Thanks!

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim transfers to r-spatial complete

I also changed references from timelyportfolio to r-spatial.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim I believe I fixed the tile switching bug in r-spatial/leafpm@8e18b0a. While we are on the topic, I wanted to mention for posterity that Leaflet.pm is fairly aggressive on its monitoring of leaflet layers. This is a nice feature in that unlike Leaflet.draw it will pick up anything that is added to leaflet and allow us to edit it in the future. However, for our purposes, I think we need to be specific to what we would like to edit (beyond just tile layers). For instance, lines and polygons with lots of points, such as all of trails and franconia, will cause the map to lock up. I guess we should add a warning somewhere so users are not surprised by this behavior.

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

@timelyportfolio I will test tomorrow as I am not near a computer right now. Regarding the aggressiveness, I don't think its a big issue as editing all of Franconia with leaflet.draw also never was a pleasant experience. But leaflet.pm seems to be on the task
geoman-io/leaflet-geoman#366
So I guess there is hope that there will be a solution in the future.

I will have a go at solving the issue regarding deletion of holes tomorrow, as thus is an issue that can arise when intersecting polygon layers so would be very nice to have.

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

@timelyportfolio with 0f8aeb7 I believe the issue of deleting holes is solved. Do you remember why you needed to specifically cast the geometries that were to be merged here? I feel it is not necessary (anymore) and without the casting, deleting of holes works as expected.

I have however encountered another problem while testing if other operations are affected. When trying to edit POINT features with editor leafpm, the edit toolbar is not shown...

editFeatures(breweries, editor = "leafpm")

I guess this is an issue in leafpm rather than mapedit, but am not sure.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim I really appreciate your help with this. I believe the cast is explained by the marathon discussion in #48. I am guessing Leaflet.pm handles multi* and holes while Leaflet.draw doesn't/didn't. I will test real quickly and report back.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim the intent of the lines you removed was to to match the original sf as much as possible, since leaflet does not have a concept of MULTI*. For instance,

library(sf)
library(mapview)
library(mapedit)
editFeatures(franconia[2,], editor="leafpm")
# then edit anything

Before your change, the returned sf would be cast back to MULTIPOLYGON, while after your change will be POLYGON. I think the original behavior casting back to the original class is more correct. Perhaps, we can just wrap with a try...catch. I'll try this to see if it is acceptable.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim How are you deleting holes? Also, I have not added the complete mechanism for handling cutting with leafpm.

Important: the cutted layer will be replaced, not updated. Listen to the pm:cut event to update your layer references in your code. The pm:cut event will provide you with the original layer and returns the resulting layer(s) that is/are added to the map as a Polygon or MultiPolygon.

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

Here's a simple multiplygon example. I delete holes by removing the vertices of a hole by right-clicking on them. For me this example returns a MULTIPOLYGON, so doesn't change what goes in.

library(sf)
library(leaflet)
library(mapview)
library(mapedit)
library(leafpm)

outer1 = matrix(c(0,0,10,0,10,10,0,10,0,0),ncol=2, byrow=TRUE)
hole1 = matrix(c(1,1,1,2,2,2,2,1,1,1),ncol=2, byrow=TRUE)
hole2 = matrix(c(5,5,5,6,6,6,6,5,5,5),ncol=2, byrow=TRUE)
outer2 = matrix(c(11,0,11,1,12,1,12,0,11,0),ncol=2, byrow=TRUE)

pts1 = list(outer1, hole1, hole2)
pts2 = list(outer2)

pl1 = st_sf(geom = st_sfc(st_polygon(pts1)))
pl2 = st_sf(geom = st_sfc(st_polygon(pts2)))

mpl = st_sf(geom = st_combine(rbind(pl1, pl2)))

tst = editFeatures(mpl, editor = "leafpm")

The same holds true if I edit pl1 for example. POLYGON in - POLYGON out

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim thanks, got it. Wanted to make sure that I was not missing an easy way to remove a hole in one go. I just pushed a tryCatch 279831c that will handle this case and also still make sure an edited franconia[5,] returns MULTIPOLYGON. Will you please test when you get a moment?

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

Weird, with your change I now see MULTIPOLYGON in - POLYGON out when deleting a hole...
Here's my sessioninfo just in case it's to do with sf etc.

devtools::session_info()
Session info -------------------------------------------------------------------------
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 system   x86_64, linux-gnu           
 ui       RStudio (1.2.1114)          
 language en_GB:en                    
 collate  en_GB.UTF-8                 
 tz       Europe/Berlin               
 date     2019-01-06                  

Packages -----------------------------------------------------------------------------
 package        * version    date       source                            
 assertthat       0.2.0      2017-04-11 CRAN (R 3.5.1)                    
 base           * 3.5.1      2018-07-03 local                             
 base64enc        0.1-3      2015-07-28 CRAN (R 3.5.1)                    
 bindr            0.1.1      2018-03-13 CRAN (R 3.5.1)                    
 bindrcpp         0.2.2      2018-03-29 CRAN (R 3.5.1)                    
 class            7.3-14     2015-08-30 CRAN (R 3.5.0)                    
 classInt         0.3-1      2018-12-18 cran (@0.3-1)                     
 codetools        0.2-15     2016-10-05 CRAN (R 3.5.0)                    
 colorspace       1.3-2      2016-12-14 CRAN (R 3.5.1)                    
 compiler         3.5.1      2018-07-03 local                             
 crayon           1.3.4      2017-09-16 CRAN (R 3.5.1)                    
 crosstalk        1.0.0      2016-12-21 CRAN (R 3.5.1)                    
 datasets       * 3.5.1      2018-07-03 local                             
 DBI              1.0.0      2018-05-02 CRAN (R 3.5.1)                    
 devtools         1.13.6     2018-06-27 CRAN (R 3.5.1)                    
 digest           0.6.18     2018-10-10 cran (@0.6.18)                    
 dplyr            0.7.8      2018-11-10 cran (@0.7.8)                     
 e1071            1.7-0      2018-07-28 CRAN (R 3.5.1)                    
 glue             1.3.0      2018-07-17 CRAN (R 3.5.1)                    
 graphics       * 3.5.1      2018-07-03 local                             
 grDevices      * 3.5.1      2018-07-03 local                             
 grid             3.5.1      2018-07-03 local                             
 htmltools        0.3.6      2017-04-28 CRAN (R 3.5.1)                    
 htmlwidgets      1.3        2018-09-30 cran (@1.3)                       
 httpuv           1.4.5.1    2018-12-18 cran (@1.4.5.1)                   
 jsonlite         1.6        2018-12-07 cran (@1.6)                       
 later            0.7.5      2018-09-18 cran (@0.7.5)                     
 lattice          0.20-35    2017-03-25 CRAN (R 3.5.0)                    
 leaflet        * 2.0.2      2018-08-27 cran (@2.0.2)                     
 leaflet.extras   1.0.0      2018-04-21 CRAN (R 3.5.1)                    
 leafpm         * 0.0.0.9000 2019-01-06 Github (r-spatial/leafpm@8e18b0a) 
 magrittr         1.5        2014-11-22 CRAN (R 3.5.1)                    
 mapedit        * 0.5.0      2019-01-06 local                             
 mapview        * 2.6.3      2019-01-05 Github (r-spatial/mapview@a7e601b)
 memoise          1.1.0      2017-04-21 CRAN (R 3.5.1)                    
 methods        * 3.5.1      2018-07-03 local                             
 mime             0.6        2018-10-05 cran (@0.6)                       
 miniUI           0.1.1.1    2018-05-18 CRAN (R 3.5.1)                    
 munsell          0.5.0      2018-06-12 CRAN (R 3.5.1)                    
 pillar           1.3.1      2018-12-15 cran (@1.3.1)                     
 pkgconfig        2.0.2      2018-08-16 CRAN (R 3.5.1)                    
 png              0.1-7      2013-12-03 CRAN (R 3.5.1)                    
 promises         1.0.1      2018-04-13 CRAN (R 3.5.1)                    
 purrr            0.2.5      2018-05-29 CRAN (R 3.5.1)                    
 R6               2.3.0      2018-10-04 cran (@2.3.0)                     
 raster           2.8-4      2018-11-03 cran (@2.8-4)                     
 RColorBrewer     1.1-2      2014-12-07 CRAN (R 3.5.1)                    
 Rcpp             1.0.0      2018-11-07 cran (@1.0.0)                     
 rlang            0.3.0.1    2018-10-25 cran (@0.3.0.1)                   
 rstudioapi       0.8        2018-10-02 cran (@0.8)                       
 satellite        1.0.1      2017-10-18 CRAN (R 3.5.1)                    
 scales           1.0.0      2018-08-09 CRAN (R 3.5.1)                    
 sf             * 0.7-3      2019-01-05 Github (r-spatial/sf@085fcbe)     
 shiny          * 1.2.0      2018-11-02 cran (@1.2.0)                     
 sp               1.3-1      2018-06-05 CRAN (R 3.5.1)                    
 stats          * 3.5.1      2018-07-03 local                             
 stats4           3.5.1      2018-07-03 local                             
 tibble           2.0.0      2019-01-04 cran (@2.0.0)                     
 tidyselect       0.2.5      2018-10-11 cran (@0.2.5)                     
 tools            3.5.1      2018-07-03 local                             
 units            0.6-2      2018-12-05 cran (@0.6-2)                     
 utils          * 3.5.1      2018-07-03 local                             
 viridisLite      0.3.0      2018-02-01 CRAN (R 3.5.1)                    
 webshot          0.5.1      2018-09-28 cran (@0.5.1)                     
 withr            2.1.2      2018-03-15 CRAN (R 3.5.1)                    
 xtable           1.8-3      2018-08-29 cran (@1.8-3)                     
 yaml             2.2.0      2018-07-25 CRAN (R 3.5.1)

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim in 6106b90 I fixed the problem you mentioned, and I added a warning if we run into any cast errors. For instance, if we completely remove the hole in your example, then an intermediate step when there are only two points results in an error when casting, but the final result is correct. However, if a user stops the deletion with two points remaining, then the final will be "incorrect" and the feature will stay as a POLYGON rather than MULTIPOLYGON.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim took way longer than I expected, but I discovered that Leaflet.pm does not handle circle markers. I thought I could hack support into our binding, but it is more complicated than I expected. What are your thoughts? Should we convert circle markers to markers when using leaflet.pm? Should we warn if we find circle markers?

library(leaflet)
library(leafpm)
leaflet() %>% addTiles() %>% addMarkers(lng=10.88922,lat=49.71979,group="point") %>% addPmToolbar(targetGroup="point")
leaflet() %>% addTiles() %>% addCircleMarkers(lng=10.88922,lat=49.71979,group="point") %>% addPmToolbar(targetGroup="point")

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

@codeofsumit thanks for chiming in here. What's your opinion on suppoerting circlemarkers?

I discovered that Leaflet.pm does not handle circle markers. I thought I could hack support into our binding, but it is more complicated than I expected.

from mapedit.

lbusett avatar lbusett commented on July 24, 2024

Having a look now: very interesting and potentially useful. Some first-test considerations (based on a simple nc2 <- editFeatures(nc, editor = "leafpm"):

  1. The leafpm editor allows to add "holes" quite easily. This is a nice addition to mapedit. At the moment, however, the sf object returned when clicking "Done" does not seem to retain the edits done with the "cut" tool. Deleting or modifying a polygon works (working on Windows, all packages up to date).

  2. Do not know if it is possible, but an additional useful feature would be to be able to split a polygon in two sub-polys by selecting just two points on its boundary.

  3. When editing a polygon (i.e., moving vertexes), clicking on "Cancel" does not seem to work (the edit is "saved" instead.

HTH!

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

Thanks @lbusett ! Very helpful!

  1. I think @timelyportfolio has not integrated cutting fully
  2. nice idea, but I fear this would require something like turf.js if we wanted it on the javascript side.
  3. this is a question for @codeofsumit I guess.

Again, cheers for testing and feedback! Much appreciated.

from mapedit.

lbusett avatar lbusett commented on July 24, 2024

@tim-salabim @codeofsumit

Glad to help as I can: this can be a key functionality to allow developing shiny applications with basic gis-like functionality.

A couple of additional points:

  • On both the "standard" and leafpm editors, when in editing mode on polygons if I click nearby but not really "over" a vertex and then move the mouse (or also if I try to pan on the map by clicking and dragging to move to another area), the whole polygon is shifted. This often forces to cancel the edits (which as I mentioned works on the standard editor, but not on the "leafpm" one) and restart. I think that the "move whole polygon" functionality would need a dedicated button, or be disabled. I do not know if this is possible / complicated. However, trying the leaflet.draw demo here:

http://leaflet.github.io/Leaflet.draw/docs/examples/full.html

I do not see this behaviour: I am able to move entire polys only for circles / rectangles by clicking on the centroid, while for irregular polys the "functionality" is disabled.

The leafpm demo at https://geoman.io/editor/# shows the same "problem"

@codeofsumit can this be addressed? I think that it may considerably affect user interaction.

  • The cutting tool does not currently seem to work for circles (both in mapedit and in the leafpm demo)

  • As a side note : I was wondering if it is in any way possible to "style" the editing map differently (e.g., by changing the color / transparency of polygons, size of the vertexes, etcetera). I had a quick look and I could not find a way.

from mapedit.

lbusett avatar lbusett commented on July 24, 2024

@codeofsumit Sure: I will open corresponding issues in your repo. I was commenting here because I do not really know what is "done" in mapEdit and what is coming "directly" from your library, and two of the issues affect also the "standard" mapedit editor.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@lbusett great feedback and ideas, thanks so much! @tim-salabim is correct in that I have not added the code to handle cutting. I should have this implemented by the end of the weekend.

@codeofsumit thanks for chiming in. Leaflet.pm is fantastic, and I'm extremly happy to make it available to a broader set of users. We really appreciate all your efforts.

from mapedit.

tim-salabim avatar tim-salabim commented on July 24, 2024

@timelyportfolio just gave it a quick test and seems to work nicely 👍 !
I think using edit to communicate the cuts is fine.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

@tim-salabim I posted a very rough draft of a r-spatial blog post https://github.com/timelyportfolio/r-spatial.org/blob/gh-pages/_rmd/2019-01-31-mapedit_leafpm.Rmd. Please let me know if you have thoughts, comments.

from mapedit.

timelyportfolio avatar timelyportfolio commented on July 24, 2024

Closing for now. I will track leaflet.pm and make sure that leafpm stays up-to-date.

from mapedit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.