add_popups: Add popups to a layer

Description Usage Arguments Examples

View source: R/layers.R

Description

Usually you will add the popups in the add_layer function by setting the popup parameter.

Usage

1
add_popups(map, layer_id, popup)

Arguments

map

A mapboxer object.

layer_id

The ID of the layer to which you want to add the popups.

popup

A mustache template in which the tags refer to the properties of the layer's data object.

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
LAYER_ID <- "crashes"

mustache_tpl <- "
  <b>Date:</b> {{date}}</br>
  <b>Time:</b> {{time}}</br>
  <b>Number of persons injured:</b> {{injured}}
"

map <- motor_vehicle_collisions_nyc %>%
  as_mapbox_source() %>%
  mapboxer(
    center = c(-73.9165, 40.7114),
    zoom = 9
  ) %>%
  add_circle_layer(
    circle_color = "red",
    circle_blur = 1,
    filter = list(">", "injured", 0),
    id = LAYER_ID
  ) %>%
  add_popups(
    LAYER_ID,
    popup = mustache_tpl
  )

if (interactive()) map

Example output



mapboxer documentation built on Nov. 8, 2020, 4:21 p.m.