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

leafpm removes markers added using leafletProxy #113

Closed chintanp closed 4 years ago

chintanp commented 4 years ago

I don't think this is the intended behavior and/or how it should be avoided, but if I add markers using leafletProxy, then those markers can be removed from the leafpm toolbar remove button. This does not happen with leaflet.extras.

The behavior can be seen in this video:

leafpm_delete_button

And the code is as below:

library(mapedit)
library(mapview)
library(leaflet)
library(shiny)

#m <- mapview(breweries)@map
newBreweries <-
    breweries %>%
    dplyr::mutate(longitude = unlist(purrr::map(breweries$geometry, 1)),
                  latitude = unlist(purrr::map(breweries$geometry, 2))) %>%
    sf::st_drop_geometry()
m <-
    leaflet() %>% addTiles()

ui <- tagList(editModUI("test-edit", height = 600))

server <- function(input, output, session) {
    crud <- callModule(
        editMod,
        "test-edit",
        leafmap = m,
        targetLayerId = "notPoints",
        editor = "leafpm"
    )

    leaflet::leafletProxy("test-edit-map") %>% addMarkers(
        lng = newBreweries$longitude,
        lat = newBreweries$latitude,
        group = 'Points',
        popup = newBreweries$Name
    )

    observeEvent(input[["test-edit-map_draw_deleted_features"]], {
        print('raw delete event will only update on delete')
    })

}
shinyApp(ui, server)

Is there a way, I can avoid leafpm from deleting already existing features on the map? I tried this with and without targetLayerId and got the same result.

timelyportfolio commented 4 years ago

@chintanp I see two bugs.

leafpm with new layers

One of the features of leafpm over leaflet.extras is the easier manipulation of existing layers. You are correct in targetLayerId is the way to control the behavior. Unfortunately leafpm does not currently disable edit with layers added after initial render. I'll try to make this change, and have added this to https://github.com/r-spatial/leafpm/issues/2 to track.

leafpm deleting all in layer

There is a bug that I noticed yesterday, and the behavior has changed. Deleting one feature deletes all in the layer. This should not happen. I have created a new issue https://github.com/r-spatial/leafpm/issues/3.

chintanp commented 4 years ago

Issue pertaining to leafpm tracked elsewhere, closing this for now, as we do not see this with leaflet.extras and therefore is external to mapedit.