add_popups {mapboxer}R Documentation

Add popups to a layer

Description

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

Usage

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

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

[Package mapboxer version 0.4.0 Index]