-
Notifications
You must be signed in to change notification settings - Fork 506
docs: change (broken) Bing maps example to heatmap in {pkgdown} site #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
80671d0
ac4039a
d3821db
d8147be
6472d76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,31 +43,42 @@ Often when passing a list from R to JavaScript it is desirable to remove any nul | |
|
||
# Example | ||
|
||
Here is a small example which shows how you can integrate the Bing.com basemap layer [plugin](https://github.com/shramov/leaflet-plugins) | ||
Here is a small example which shows how you can integrate heatmap functionality using a [plugin](http://leaflet.github.io/Leaflet.heat/). | ||
|
||
```{r, fig.height=4} | ||
library(leaflet) | ||
library(htmltools) | ||
library(htmlwidgets) | ||
|
||
bingPlugin <- htmlDependency( | ||
"leaflet.plugins", "2.0.0", | ||
src = normalizePath("./js"), | ||
script = "Bing.min.js" | ||
# 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.) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments point out that the example is rather sparse and could benefit from description. Personally, I'd prefer to have these comments appear in prose rather than in comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I should have also mentioned that I don't feel particularly strongly about this. It's an obvious improvement; so if you have a stronger preference for the comments or don't have the time now I'd understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd agree they'd make more sense in the body of the document rather than the comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g., I'm not totally clear on what |
||
heatPlugin <- htmlDependency( | ||
"Leaflet.heat", | ||
"99.99.99", | ||
jack-davison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
src = c(href = "http://leaflet.github.io/Leaflet.heat/dist/"), | ||
script = "leaflet-heat.js" | ||
) | ||
|
||
# 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(-122.23, 37.75, zoom = 10) %>% | ||
registerPlugin(bingPlugin) %>% | ||
onRender("function(el, x) { | ||
var imagerySet = 'Aerial'; | ||
var bing = new L.BingLayer('LfO3DMI9S6GnXD7d0WGs~bq2DRVkmIAzSOFdodzZLvw~Arx8dclDxmZA0Y38tHIJlJfnMbGq5GXeYmrGOUIbS2VLFzRKCK0Yv_bAl6oe-DOc', | ||
{type: imagerySet}); | ||
this.addLayer(bing); | ||
}") | ||
# initialise leaflet map in R | ||
leaflet() %>% | ||
addTiles() %>% | ||
fitBounds(min(quakes$long), min(quakes$lat), max(quakes$long), max(quakes$lat)) %>% | ||
# Register heatmap plugin on this map instance | ||
registerPlugin(heatPlugin) %>% | ||
# Add custom JS logic; `this` refers to the Leaflet (JS) map object. | ||
onRender("function(el, x, data) { | ||
data = HTMLWidgets.dataframeToD3(data); | ||
data = data.map(function(val) { return [val.lat, val.long, val.mag*100]; }); | ||
L.heatLayer(data, {radius: 25}).addTo(this); | ||
}", data = quakes[c("lat", "long", "mag")]) | ||
``` | ||
|
Uh oh!
There was an error while loading. Please reload this page.