trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
211 stars 74 forks source link

Update lfx-search-prod.js to allow searching of circle makers #218

Open wyuill opened 2 months ago

wyuill commented 2 months ago

allow searching of circle markers as per #143 by removing "e instanceof t.Path ||" in inst/htmlwidgets/build/lfx-search/lfx-search-prod.js

Tested search with addMarkers and addCircleMarkers in R 4.3.2

trafficonese commented 2 months ago

Thank you, but this should be addressed in the upstream repo, as the -prod.js files are automatically created, when building the JS-sources.

But can you maybe open a PR for it at leaflet-search I think this is the line, where it should be removed: https://github.com/stefanocudini/leaflet-search/blob/d29c5392b33cc31b338c3d17b5f8532fef5eae48/src/leaflet-search.js#L556C18-L556C45

trafficonese commented 2 months ago

And anyway, I think this is working already with the current Github version.

Could you install the latest version with remotes::install_github("trafficonese/leaflet.extras")

and then test this example:

library(shiny)
library(leaflet)
library(leaflet.extras)

cities <- read.csv(textConnection("
City,Lat,Long,Pop
Boston,42.3601,-71.0589,645966
Hartford,41.7627,-72.6743,125017
New York City,40.7127,-74.0059,8406000
Philadelphia,39.9500,-75.1667,1553000
Pittsburgh,40.4397,-79.9764,305841
Providence,41.8236,-71.4222,177994
"))

ui <- fluidPage(
  leafletOutput("map"),
  actionButton("clearsearchmarker", "Clear Search Marker")
)

server <- function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet(cities) %>% addTiles() %>%
      addCircleMarkers(lng = ~Long, lat = ~Lat,
                       radius = 10, popup = ~City, 
                       label = ~City,
                       group = "cities") %>%
      addSearchFeatures(
        targetGroups = "cities", options = searchFeaturesOptions(
        ))
  })

  observeEvent(input$clearsearchmarker, {
    leafletProxy("map") %>%
      clearSearchFeatures()
  })
}
shinyApp(ui, server)