pluginFactory: Create plugin functions to implement Leaflet pure-JS...

Description Usage Arguments Value See Also Examples

View source: R/addJSPlugin.R

Description

pluginFactory() takes in a couple js files (code and dependencies) and creates a plugin function that applies this plugin to a given map. The new function also returns the map so it can be piped with the leaflet functions

Usage

1
2
pluginFactory(name = "JSPlugin", location, jsfilename, dependencies,
  stylesheet = NULL)

Arguments

name

A name for your plugin

location

The parent folder of your js file, dependency file, and css stylesheet

jsfilename

A .js filename relative to the parent folder at location that holds the source code for modifying the map object

dependencies

A .js filename(s) of all other js libraries the source code depends on

stylesheet

A .css stylesheet for adding styles to the entire page

Value

A function with arguments map, data, and ... to be used as a plugin to leaflet just like the leaflet::addCircles() function

See Also

Some code is used from this github gist by Joe Chang

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
df <- data.frame(
  lat =  42.9634 + stats::rnorm(100),
  lng = -85.6681 + stats::rnorm(100),
  size = runif(100, 5, 20),
  color = sample(colors(), 100)
)
addJS <-
  pluginFactory(
    "Some JS Plugin",
    system.file("js", "", package = "leaflethex"), "hexbin.js", "deps.js", stylesheet="hexbin.css")

leaflet(df, width = 600, height = 300) %>%
  addTiles() %>%
  addJS(radius = 20, highEndColor = "yellow")

leaflethex documentation built on Sept. 4, 2019, 9:03 a.m.