This repository was archived by the owner on Mar 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonrender.R
More file actions
99 lines (82 loc) · 3.07 KB
/
onrender.R
File metadata and controls
99 lines (82 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
leaflet() %>% addTiles() %>%
onRender("
function(el, x) {
// Navigate the map to the user's location
this.locate({setView: true});
}
")
meh <- "😐";
yikes <- "😨";
df <- data.frame(
lng = quakes$long,
lat = quakes$lat,
html = ifelse(quakes$mag < 5.5, meh, yikes),
stringsAsFactors = FALSE
)
leaflet() %>% addTiles() %>%
fitBounds(min(df$lng), min(df$lat), max(df$lng), max(df$lat)) %>%
onRender("
function(el, x, data) {
for (var i = 0; i < data.lng.length; i++) {
var icon = L.divIcon({className: '', html: data.html[i]});
L.marker([data.lat[i], data.lng[i]], {icon: icon}).addTo(this);
}
}
", data = df)
library(leaflet)
library(htmltools)
library(htmlwidgets)
curvejs <- htmlDependency("Leaflet.curve", "0.9.1",
src = c(href="https://github.com/elfalem/Leaflet.curve/tree/gh-pages/src/"),
script = "leaflet.curve.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% addProviderTiles(providers$CartoDB.Positron) %>%
setView(lng = 5.1, lat = 47.27, zoom = 3) %>%
addPolylines(data = flows,
weight = ~ifelse(nombre>3,nombre^(1/2), 0),
label = hover,
stroke = T,
fill = F, fillOpacity = 0.8, dashArray = NULL,
smoothFactor = 1,
fillColor = colorRampPalette(c(rgb(0,0,1,1), rgb(0,0,1,0)), alpha = TRUE)(8),
color = scales::seq_gradient_pal(low = "lightblue", high = "lightgreen", space = "Lab")(seq(0, 1, length.out = 25))
) %>%
registerPlugin(curvejs) %>%
onRender("function(el, x) {
var path = L.curve(['M',[50.54136296522163,28.520507812500004],
'C',[52.214338608258224,28.564453125000004],
[48.45835188280866,33.57421875000001],
[50.680797145321655,33.83789062500001],
'V',[48.40003249610685],
'L',[47.45839225859763,31.201171875],
[48.40003249610685,28.564453125000004],'Z'],
{color:'red',fill:true}).addTo(map);
}")
migrationLayer <- htmlDependency("Leaflet.curve", "0.9.1",
src = c(href="https://github.com/lit-forest/leaflet.migrationLayer/tree/master/dist/"),
script = "leaflet.migrationLayer.js")
registerPlugin <- function(map, plugin) {
map$dependencies <- c(map$dependencies, list(plugin))
map
}
leaflet() %>% addProviderTiles(providers$CartoDB.Positron) %>%
setView(lng = 5.1, lat = 47.27, zoom = 3) %>%
addPolylines(data = flows,
weight = ~ifelse(nombre>3,nombre^(1/2), 0),
label = hover,
stroke = T,
fill = F, fillOpacity = 0.8, dashArray = NULL,
smoothFactor = 1,
fillColor = colorRampPalette(c(rgb(0,0,1,1), rgb(0,0,1,0)), alpha = TRUE)(8),
color = scales::seq_gradient_pal(low = "lightblue", high = "lightgreen", space = "Lab")(seq(0, 1, length.out = 25))
) %>%
registerPlugin(migrationLayer) %>%
onRender("function(el, x) {
var migrationLayer = new L.migrationLayer({
map: map,
data: flows
})
}")