我正在尝试添加传单tracksymbol插件,
https://github.com/lethexa/leaflet-tracksymbol
,到目前为止我已经试过了:
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
但我在地图上看不到任何标记…即使我只是把第一次观察结果传给
onRender
功能。我在想我做错了什么?我不确定问题是否出在我的依赖源代码、实际的html代码等方面。我花了一天的时间试图呈现这个问题,尽可能多地阅读堆栈溢出,但只是没有主意。我希望能帮上忙。能够在地图上看到一艘船前进的方向,将使地图上的信息更加丰富。
我很感激你的帮助。提前谢谢你。-奈特