popup: Create HTML strings for popups

Description Usage Arguments Details Value Examples

Description

Create HTML strings for popup tables used as input for mapview or leaflet. This optionally allows the user to include only a subset of feature attributes.

Create HTML strings for popup images used as input for mapview or leaflet.

Create HTML strings for popup graphs used as input for mapview or leaflet.

Usage

1
2
3
4
5
6
popupTable(x, zcol, row.numbers = TRUE, feature.id = TRUE)

popupImage(img, src = c("local", "remote"), embed = FALSE, ...)

popupGraph(graphs, type = c("png", "svg", "html"), width = 300,
  height = 300, ...)

Arguments

x

A Spatial* object.

zcol

numeric or character vector indicating the columns included in the output popup table. If missing, all columns are displayed.

row.numbers

logical whether to include row numbers in the popup table.

feature.id

logical whether to add 'Feature ID' entry to popup table.

img

A character vector of file path(s) or web-URL(s) to any sort of image file(s).

src

Whether the source is "local" (i.e. valid file path(s)) or "remote" (i.e. valid URL(s)).

embed

whether to embed the (local) images in the popup html as base64 ecoded. Set this to TRUE if you want to save and share your map, unless you want render many images, then set to FALSE and make sure to copy ../graphs when copying the map to a different location.

...

further arguments passed on to underlying methods such as height and width.

graphs

A list of figures associated with x.

type

Output filetype, one of "png" (default), "svg" or "html".

width

popup width in pixels.

height

popup height in pixels.

Details

Type svg uses native svg encoding via readLines. height and width are set via ... and passed on to svg
Type png embeds via "<img src = ...". height and width are set via ... and passed on to png
Type html embeds via "<iframe src = ...". height and width are set directly in pixels.

Value

A list of HTML strings required to create feature popup tables.

A list of HTML strings required to create popup graphs.

A list of HTML strings required to create popup graphs.

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
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
library(leaflet)

## include columns 1 and 2 only
mapview(franconia, popup = popupTable(franconia, zcol = 1:2))
mapview(breweries, zcol = "founded", legend = TRUE,
        popup = popupTable(breweries, zcol = c("founded", "village")))
leaflet() %>% addCircleMarkers(data = breweries)
leaflet() %>% addCircleMarkers(data = breweries,
                               popup = popupTable(breweries))

## Not run: 
## remote images -----
### one image
library(sf)

pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
                coords = c("x", "y"),
                crs = 4326)

img = "http://bit.ly/1TVwRiR"

mapview(pnt, popup = popupImage(img, src = "remote"))

### multiple file (types)
library(sp)
images = c(img,
            "https://upload.wikimedia.org/wikipedia/commons/9/91/Octicons-mark-github.svg",
            "https://www.r-project.org/logo/Rlogo.png",
            "https://upload.wikimedia.org/wikipedia/commons/d/d6/MeanMonthlyP.gif")

pt4 = data.frame(x = jitter(rep(174.764474, 4), factor = 0.01),
                  y = jitter(rep(-36.877245, 4), factor = 0.01))
coordinates(pt4) = ~ x + y
proj4string(pt4) = "+init=epsg:4326"

mapview(pt4, popup = popupImage(images)) # NOTE the gif animation

## local images -----
pnt = st_as_sf(data.frame(x = 174.764474, y = -36.877245),
                coords = c("x", "y"), crs = 4326)
img = system.file("img","Rlogo.png",package="png")
mapview(pnt, popup = popupImage(img))

## End(Not run)

## Not run: 
### example: svg -----

library(sp)

data(meuse)
coordinates(meuse) = ~ x + y
proj4string(meuse) = CRS("+init=epsg:28992")

## create plots with points colored according to feature id
library(lattice)
p = xyplot(copper ~ cadmium, data = meuse@data, col = "grey")
p = mget(rep("p", length(meuse)))

clr = rep("grey", length(meuse))
p = lapply(1:length(p), function(i) {
  clr[i] = "red"
  update(p[[i]], col = clr)
})

mapview(meuse, popup = popupGraph(p, type = "svg"))

### example: png -----
pt = data.frame(x = 174.764474, y = -36.877245)

coordinates(pt) = ~ x + y
proj4string(pt) = "+init=epsg:4326"

p2 = levelplot(t(volcano), col.regions = terrain.colors(100))

mapview(pt, popup = popupGraph(p2, width = 300, height = 400))

### example: html -----
mapview(breweries[1, ], map.types = "Esri.WorldImagery",
        popup = popupGraph(mapview(breweries[1, ])@map,
                           type = "html",
                           width = 500,
                           height = 400))

## End(Not run)

r-spatial/mapview documentation built on Nov. 11, 2018, 12:27 p.m.