addGlPoints: add polylines to a leaflet map using Leaflet.glify

Description Usage Arguments Details Functions Examples

View source: R/glify-points.R

Description

Leaflet.glify is a web gl renderer plugin for leaflet. See https://github.com/robertleeplummerjr/Leaflet.glify for details and documentation.

Usage

 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
addGlPolylines(
  map,
  data,
  color = cbind(0, 0.2, 1),
  opacity = 0.6,
  group = "glpolylines",
  popup = NULL,
  weight = 1,
  layerId = NULL,
  src = FALSE,
  ...
)

addGlPoints(
  map,
  data,
  fillColor = "#0033ff",
  fillOpacity = 0.8,
  radius = 10,
  group = "glpoints",
  popup = NULL,
  layerId = NULL,
  src = FALSE,
  ...
)

addGlPolygons(
  map,
  data,
  color = cbind(0, 0.2, 1),
  fillColor = color,
  fillOpacity = 0.8,
  group = "glpolygons",
  popup = NULL,
  layerId = NULL,
  src = FALSE,
  ...
)

Arguments

map

a leaflet map to add points/polygons to.

data

sf/sp point/polygon data to add to the map.

color

Object representing the color. Can be of class integer, character with color names, HEX codes or random characters, factor, matrix, data.frame, list, json or formula. See the examples or makeColorMatrix for more information.

opacity

feature opacity. Numeric between 0 and 1. Note: expect funny results if you set this to < 1.

group

a group name for the feature layer.

popup

Object representing the popup. Can be of type character with column names, formula, logical, data.frame or matrix, Spatial, list or JSON. If the lenght does not match the number of rows in the dataset, the popup vector is repeated to match the dimension.

weight

line width/thicknes in pixels for addGlPolylines.

layerId

the layer id

src

whether to pass data to the widget via file attachments.

...

Passed to to_json for the data coordinates.

fillColor

fill color.

fillOpacity

fill opacity.

radius

point size in pixels.

Details

MULTILINESTRINGs are currently not supported! Make sure you cast your data to LINETSRING first (e.g. using sf::st_cast(data, "LINESTRING").

MULTIPOLYGONs are currently not supported! Make sure you cast your data to POLYGON first (e.g. using sf::st_cast(data, "POLYGON").

Functions

Examples

 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
if (interactive()) {
library(leaflet)
library(leafgl)
library(sf)

storms = st_as_sf(atlStorms2005)

cols = heat.colors(nrow(storms))

leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.Positron) %>%
  addGlPolylines(data = storms, color = cols, popup = TRUE, opacity = 1)
}

if (interactive()) {
library(leaflet)
library(leafgl)
library(sf)

n = 1e5

df1 = data.frame(id = 1:n,
                 x = rnorm(n, 10, 1),
                 y = rnorm(n, 49, 0.8))
pts = st_as_sf(df1, coords = c("x", "y"), crs = 4326)

cols = topo.colors(nrow(pts))

leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
  addGlPoints(data = pts, fillColor = cols, popup = TRUE)

}

if (interactive()) {
library(leaflet)
library(leafgl)
library(sf)

gadm = st_as_sf(gadmCHE)
gadm = st_cast(gadm, "POLYGON")
cols = grey.colors(nrow(gadm))

leaflet() %>%
  addProviderTiles(provider = providers$CartoDB.DarkMatter) %>%
  addGlPolygons(data = gadm, color = cols, popup = TRUE)
}

leafgl documentation built on July 2, 2020, 4:02 a.m.