The function expects either line or point data as spatial data or as Simple Feature. Alternatively, coordinates can also be passed as numeric vectors.
Usage
addMovingMarker(
map,
lng = NULL,
lat = NULL,
layerId = NULL,
group = NULL,
duration = 2000,
icon = NULL,
popup = NULL,
popupOptions = NULL,
label = NULL,
labelOptions = NULL,
movingOptions = movingMarkerOptions(),
options = leaflet::markerOptions(),
data = leaflet::getMapData(map)
)
Arguments
- map
the map to add moving markers
- lng
a numeric vector of longitudes, or a one-sided formula of the form
~x
wherex
is a variable indata
; by default (if not explicitly provided), it will be automatically inferred fromdata
by looking for a column namedlng
,long
, orlongitude
(case-insensitively)- lat
a vector of latitudes or a formula (similar to the
lng
argument; the nameslat
andlatitude
are used when guessing the latitude column fromdata
)- layerId
In order to be able to address the moving markings individually, a layerId is required. If none is specified, one is created that is derived from the current timestamp.
- group
the name of the group the newly created layers should belong to (for
clearGroup
andaddLayersControl
purposes). Human-friendly group names are permitted–they need not be short, identifier-style names. Any number of layers and even different types of layers (e.g. markers and polygons) can share the same group name.- duration
Duration in milliseconds per line segment between 2 points. Can be a vector or a single number. Default is
1000
- icon
the icon(s) for markers;
- popup
a character vector of the HTML content for the popups (you are recommended to escape the text using
htmlEscape()
for security reasons)- popupOptions
A Vector of
popupOptions
to provide popups- label
a character vector of the HTML content for the labels
- labelOptions
A Vector of
labelOptions
to provide label options for each label. DefaultNULL
- movingOptions
a list of extra options for moving markers. See
movingMarkerOptions
- options
a list of extra options for markers. See
markerOptions
- data
the data object from which the argument values are derived; by default, it is the
data
object provided toleaflet()
initially, but can be overridden
See also
Other MovingMarker Functions:
movingMarkerOptions()
,
startMoving()
Examples
library(sf)
library(leaflet)
library(leaflet.extras2)
crds <- data.frame(structure(
c(
-67.5, -68.5, -69.6, -70.5, -71.3, -72.2, -72.7,
-72.9, -73, -72.4, -70.8, 15.8, 16.5, 17.3, 17.8, 18.3, 18.6,
19.8, 21.6, 23.5, 25.1, 27.9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
),
dim = c(11L, 3L), dimnames = list(NULL, c("X", "Y", "L1"))
))
df <- st_sf(st_sfc(st_linestring(as.matrix(crds), dim = "XYZ"), crs = 4326))
st_geometry(df) <- "geometry"
df <- st_zm(df)
leaflet() %>%
addTiles() %>%
addPolylines(data = df) %>%
addMovingMarker(
data = df,
movingOptions = movingMarkerOptions(autostart = TRUE, loop = TRUE),
label = "I am a pirate!",
popup = "Arrr"
)