r-spatial / leafpop

Include Tables, Images and Graphs in Leaflet Popups
Other
112 stars 15 forks source link

addPopupImages incorrect if addMarkers include clusterOptions = leaflet::markerClusterOptions() #21

Closed oggioniale closed 3 years ago

oggioniale commented 3 years ago

in the following code, in which the clusterOptions = leaflet::markerClusterOptions() argument is included, the content of addMarkers popup is not visible and the image that appear is always the same: the first in the vector (in the case of this code the vector is allExif).

map <- map %>% 
  leaflet::addMarkers(
    lng = allExif$GPSLongitude
    , lat = allExif$GPSLatitude
    , popup = paste0(
      "Capture Date and Time: ", allExif$DateTimeOriginal, "<br/>",
      "Exposure: ", allExif$ExposureMode, "<br/>",
      "Focal Length: ", allExif$FocalLength, "<br/>",
      "ISO Speed Rating: ", allExif$ISO, "<br/>",
      # "Flash" = , "<br/>",
      "Model: ", allExif$Model, "<br/>",
      "Lens: ", allExif$Lens, "<br/>"
      , "<hr>"
    )
    , group = 'Photo markers'
    , clusterOptions = leaflet::markerClusterOptions()
  ) %>%
  leafpop::addPopupImages(
    image = allExif$SourceFile
    , group = 'Photo markers'
    , width = allExif$ImageWidth/5
    , height = allExif$ImageHeight/5
  )
map
tim-salabim commented 3 years ago

Can you provide a reproducible example?

oggioniale commented 3 years ago

Yes of sure following the example provided in the addPopupImages help:

library(sf)
images = c("http://bit.ly/1TVwRiR",
           "https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg",
           "https://www.r-project.org/logo/Rlogo.png",
           "https://upload.wikimedia.org/wikipedia/commons/d/d6/MeanMonthlyP.gif")

pt4 = data.frame(x = jitter(rep(174.764474, 4), factor = 0.01),
                 y = jitter(rep(-36.877245, 4), factor = 0.01))
pt4 = st_as_sf(pt4, coords = c("x", "y"), crs = 4326)

leaflet::leaflet() %>%
  leaflet::addTiles() %>%
  leaflet::addMarkers(
    data = pt4, 
    group = "points", 
    clusterOptions = leaflet::markerClusterOptions()
  ) %>%
  leafpop::addPopupImages(images, group = "points", width = 400) # NOTE the gif animation
tim-salabim commented 3 years ago

Thanks, I'll look into it soon

tim-salabim commented 3 years ago

Should work now. Can you please retry?

oggioniale commented 3 years ago

YES!!! It work now!