Я хочу добавить пульсирующий маркер к карте, которую я построил с помощью R leaflet package Вот the plugin Я хочу использовать. Для того, чтобы сделать это, я написал следующий код из этого from this github accountПульсирующий плагин-маркер с пакетом листовок R
library(leaflet)
library(htmltools)
library(htmlwidgets)
# This tells htmlwidgets about our plugin name, version, and
# where to find the script. (There's also a stylesheet argument
# if the plugin comes with CSS files.)
esriPlugin <- htmlDependency("leaflet-icon-pulse",version = "1.0",
src = c(href = "https://raw.githubusercontent.com/mapshakers/leaflet-icon-pulse/master/src/"),
script = "L.Icon.Pulse.js",stylesheet ="L.Icon.Pulse.css")
# A function that takes a plugin htmlDependency object and adds
# it to the map. This ensures that however or whenever the map
# gets rendered, the plugin will be loaded into the browser.
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% setView(-52.520, 13.185, zoom = 5) %>%
# Register ESRI plugin on this map instance
registerPlugin(esriPlugin) %>%
# Add your custom JS logic here. The `this` keyword
# refers to the Leaflet (JS) map object.
onRender("function(el,x) {
var pulsingIcon = L.icon.pulse({iconSize:[20,20],color:'red'});
var marker = L.marker([52.9167,13.9333],{icon: pulsingIcon}).addTo(this);
}")
Однако, это не работает. Я получил серый прямоугольник вместо красивой карты с красивым пульсирующим маркером. Кто-нибудь видит что-то не так в моем коде?
Изменение первой линии конечного вызова карты для 'листовке()%>% addTiles()%>% setView (-52,520, 13,185, масштабирование = 5)%>%' и 'onRender' часть to 'onRender (" function (el, x) { var pulsingIcon = L.icon.pulse ({iconSize: [20,20], цвет: 'красный'}); var marker = L.marker ([13.185, -52.520], {icon: pulsingIcon}). AddTo (this); } ")' и вы увидите карту и маркер, хотя в моем случае это не пульсирует ... – TimSalabim
Да, я могу изменить окончательный вызов карты. Но у меня есть та же самая часть onRender, что и ваша. один? Кажется, вы не вставляете исправленную версию onRender. –
Разница в 'onRender', которую я написал, -' L.marker ([13.185, -52.520] ', где я меняю координаты так, чтобы маркер находился в центр длины карты, заданный с помощью 'setView'. – TimSalabim