Skip to content

Instantly share code, notes, and snippets.

@mdav43
Created September 3, 2021 06:05
Show Gist options
  • Save mdav43/e4c39206f9892dc05e349d836cd0be96 to your computer and use it in GitHub Desktop.
Save mdav43/e4c39206f9892dc05e349d836cd0be96 to your computer and use it in GitHub Desktop.
---
title: "R Notebook"
output: html_document
---
```{r message=FALSE, warning=FALSE, include=FALSE}
list.of.packages <- c("geojsonio", "leaflet")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(geojsonio)
library(leaflet)
# Edit the below line to point to your geojson file
jsonfile <- "data/raw/geojson/test2.geojson"
jsondata <- geojsonio::geojson_read(jsonfile, what = "sp")
```
```{r}
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addCircleMarkers(data=jsondata, opacity = 0.6, stroke = FALSE, radius = 2) %>%
addEasyButton(easyButton(
icon="fa-globe", title="Zoom to Level 1",
onClick=JS("function(btn, map){ map.setZoom(1); }"))) %>%
addEasyButton(easyButton(
icon="fa-crosshairs", title="Locate Me",
onClick=JS("function(btn, map){ map.locate({setView: true}); }")))
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment