Skip to content

Instantly share code, notes, and snippets.

@bhaskarvk
Created September 26, 2016 13:32
Show Gist options
  • Save bhaskarvk/0c665350557e8ff79a9870cecc88f571 to your computer and use it in GitHub Desktop.
Save bhaskarvk/0c665350557e8ff79a9870cecc88f571 to your computer and use it in GitHub Desktop.
library(leaflet)
library(htmltools)
library(htmlwidgets)
# Convert the JS and CSS from
# https://github.com/mapshakers/leaflet-icon-pulse/tree/master/src
# to proper URLs using rawgit.com
pluginDependency <- htmlDependency(
"leaflet-icon-pulse",version = "1.0",
src = c(href="https://rawgit.com/mapshakers/leaflet-icon-pulse/master/src/"),
script = "L.Icon.Pulse.js",stylesheet ="L.Icon.Pulse.css"
)
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>%
addProviderTiles("CartoDB.DarkMatter") %>%
setView(-122.4105513,37.78250256, zoom = 12) %>%
registerPlugin(pluginDependency) %>%
onRender("function(el,x) {
var pulsingIcon =
L.icon.pulse({iconSize:[5,5],color:'red',heartbeat:0.5});
var pulsingIcon2 =
L.icon.pulse({iconSize:[10,10],color:'orange',heartbeat:2});
var marker =
L.marker([37.78,-122.41],{icon: pulsingIcon}).bindPopup(
'<b>Hello world!</b><br>I am a popup.').openPopup().addTo(this);
var marker =
L.marker([37.75,-122.39],{icon: pulsingIcon2}).addTo(this);
}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment