R/create_popup_content.R

Defines functions create_popup_content

Documented in create_popup_content

################################################################################
#
#'
#' Create Leaflet marker popup content
#'
#' Given point location data, this function facilitates the creation of
#' corresponding vector of character values to show in the popup for Leaflet
#' markers.
#'
#' @param df A data.frame containing information corresponding to each mapped
#'   point location.
#'
#' @return A vector of character values with length equal to the number of
#'   mapped point locations
#'
#' @examples
#' create_popup_content(df = diamagueneLocations)
#'
#' @export
#'
#
################################################################################

create_popup_content <- function(df) {
  ##
  infraType <- paste("<b>Type:</b> ", stringr::str_to_sentence(df$infra), sep = "")
  schoolType <- paste("<b>School type:</b> ", stringr::str_to_sentence(df$school_type), sep = "")
  desc <- paste("<b>Description:</b> ", df$description, sep = "")
  ## Add text
  tooltip <- vector(mode = "character", length = nrow(df))
  tooltip[df$infra == "ecole"] <- paste(infraType, schoolType, desc, sep = "<br/>")[df$infra == "ecole"]
  tooltip[df$infra != "ecole"] <- paste(infraType, desc, sep = "<br/>")[df$infra != "ecole"]
  ## Add figure
  tooltip <- paste("<img src='images/",
                   stringr::str_remove(string = df$png, pattern = ".png"),
                   "_tn.jpg' align='center' /> <br/>", tooltip, sep = "")
  ## Return tooltip vector
  return(tooltip)
}
validmeasures/uypa documentation built on Nov. 5, 2019, 11:59 a.m.