#' Plot the occurrence data via map_leaftel
#'
#' @param datalist the result generated by the function Getoccdat
#' @return the occurrence map with legends
#' @examples
#' name <- Readname('Pinus contorta,Danaus plexippus,Canada')
#' data <- Getoccdat(name)
#' leaflet_occdat(data)
#' @import mapr
#' @import leaflet
#' @export
leaflet_occdat <- function(datalist){
#Get all datas
dat <- datalist[[1]]
species_ce <- datalist[[2]]
species_c <-datalist[[3]]
species_ne <- datalist[[4]]
species_n <- datalist[[5]]
countryname <- datalist[[6]]
checkcountry <- datalist[[7]]
#Record the used colors
colorslist <- c('#FE2E2E', '#64FE2E', '#2E9AFE', '#FE2EC8', '#FACC2E', '#2EFE9A', '#642EFE', '#FE642E', '#2EFE64', '#2E64FE', '#FE2E9A')
if(species_ne == 0){
colors_used <- colorslist[1:species_n]
}else {colors_used <- colorslist[1:species_ne]}
#Mapping
maps <- map_leaflet(dat, size = 2, color = colors_used)
maps
#Adding legend to the map
if(checkcountry == TRUE & species_ne != 0){
addLegend(maps, position = 'bottomright', colors = colors_used, labels = species_ce, opacity = 2, title = paste('Species in', countryname, sep = " "))
}else if(species_ne == 0){
addLegend(maps, position = 'bottomright', colors = colors_used, labels = species_ce, opacity = 2, title = paste('No species in', countryname,"Here are species over world", sep = " "))
}else{
addLegend(maps, position = 'bottomright', colors = colors_used, labels = species_ce, opacity = 2, title = 'Species')
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.