Here is a code snippet extracted from the R leaftime package documentation examples. It generates a map with a timeline that displays points as they appear over time. I am interested in adding labels to these points to show their unique id numbers. Upon examining the code, it seems that the JS function is utilized to pass JavaScript to leaflet for map customization. I found a solution on how to label GeoJSON points in leaflet at this link, suggesting the use of the tooltip function. However, my attempts to modify the provided R code to implement this feature have been unsuccessful. Any help in achieving the desired outcome would be greatly appreciated.
library(leaflet)
library(leaftime)
library(htmltools)
# Define data frame
power <- data.frame(
"Latitude" = c(
33.515556, 38.060556, 47.903056, 49.71, 49.041667, 31.934167,
54.140586, 54.140586, 48.494444, 48.494444
),
"Longitude" = c(
129.837222, -77.789444, 7.563056, 8.415278, 9.175, -82.343889,
13.664422, 13.664422, 17.681944, 17.681944
),
"start" = seq.Date(as.Date("2015-01-01"), by = "day", length.out = 10),
"end" = as.Date("2015-01-10")
)
power$id<-seq.int(nrow(power))
# Convert data.frame using geojsonio
power_geo <- geojsonio::geojson_json(power,lat="Latitude",lon="Longitude")
leaflet(power_geo) %>%
addTiles() %>%
setView(44.0665,23.74667,2) %>%
addTimeline(
timelineOpts = timelineOptions(
pointToLayer = htmlwidgets::JS(
"
function(data, latlng) {
return L.circleMarker(latlng, {
radius: 10,
color: 'black',
fillColor: 'pink',
fillOpacity: 1
})
}
"
)
)
)