I am trying to add the leaflet-tracksymbol plugin, https://github.com/lethexa/leaflet-tracksymbol, to a map I am making inside of R. So far I have tried this:
library(htmltools)
library(htmlwidgets)
library(leaflet)
library(leaflet.extras)
library(magrittr)
tmp<- data.frame(mmsi=c(1234567, 9876554), speed=c(3.5, 5.4),
course=c(270.2, 155.4), rot=c(0,0.4), heading=c(267, 230),
latitude=c(25.92855, 25.18627), longitude=c(51.61341, 56.58021),
trackId=c(123,456), fill=c(TRUE, TRUE), fillColor=c("#0000ff",
"#228B22"), fillOpacity=c(1.0,1.0), stroke=c(TRUE, TRUE),
color=c("#000000", "#000000"), opacity=c(1.0,1.0), weight=c(1.0,1.0))
trackMarkerPlugin <- htmltools::htmlDependency("leaflet.tracksymbol",
"1.0.8", src = c(href = "https://rawgit.com/lethexa/leaflet-
tracksymbol/master/leaflet-tracksymbol.min.js"))
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
trackMarkerMap<- leaflet::leaflet(data=tmp[c(1),]) %>%
addProviderTiles(providers$CartoDB.Positron, group ="CartoDB.Positron", options = providerTileOptions(detectRetina = T)) %>%
fitBounds(~(min(longitude)-.07), ~(min(latitude)-.07), ~(max(longitude)+.07), ~(max(latitude)+.07)) %>%
registerPlugin(trackMarkerPlugin) %>%
htmlwidgets:: onRender("function(el, x, data) {
data = HTMLWidgets.dataframeToD3(data);
data = data.map(function(val) { return [val.mmsi, val.speed, val.course, val.rot, val.heading, val.latitude, val.longitude, val.trackId, val.fill, val.fillColor, val.fillOpacity, val.stroke, val.color, val.opacity, val.weight]; });
var latlng = L.latlng(latitude, longitude);
var speed = speed;
var course = course;
var heading = heading;
L.trackSymbol(latlng, {
trackId: trackId,
fill: fill,
fillColor: fillColor,
fillOpacity: fillOpacity,
stroke: stroke,
color: color,
opacity: opacity,
weight: weight,
speed: speed,
course: course,
heading: heading
}).addTo(this); }", data = tmp[c(1),] %>% dplyr::select(mmsi, speed, course, rot, heading, latitude, longitude, trackId, fill, fillColor, fillOpacity, stroke, color, opacity, weight))
trackMarkerMap
But I am unable to see any sort of markers on the map...even if I pass just the first observation to the onRender
function. I am wondering what I am doing wrong? I am unsure if the problem is in my dependency sourcing, actual HTML code, etc. I have spent the day trying to get this to render, read as much as I can on stack overflow, but am simply out of ideas. I would love some help with this. Being able to see the direction a ship is going on the map would make it just that much more informative.
I am grateful for any help. Thank you in advance. -nate