Skip to content

Instantly share code, notes, and snippets.

@slarosa
Last active April 19, 2017 11:07
Show Gist options
  • Save slarosa/20fcd70c3fbbb6b55a8f236adb0d44b0 to your computer and use it in GitHub Desktop.
Save slarosa/20fcd70c3fbbb6b55a8f236adb0d44b0 to your computer and use it in GitHub Desktop.
library(leaflet)
library(rgdal)
# Lo shapefile usato in questo esempio è liberamente scaricabile
# dal link http://bit.ly/2e9dyZf
setwd('/Users/slarosa/dev/r_leaflet')
datadir <- file.path(getwd(),"data")
basename <- "pai_2016_frane_wgs84"
shapefile <- file.path(datadir, paste(basename, ".shp", sep = ""))
frane <- readOGR(shapefile, layer=basename, verbose=FALSE)
leaflet(frane) %>%
addMiniMap() %>%
addTerminator %>%
addSimpleGraticule() %>%
addMeasure(
position = "topright",
primaryLengthUnit = "meters",
primaryAreaUnit = "sqmeters",
activeColor = "#3D535D",
completedColor = "#7D4479",
localization = 'it'
) %>%
addTiles(group = "OSM(default)") %>%
addProviderTiles("Stamen.Toner", group = "Stateman") %>%
addProviderTiles("Esri.WorldImagery", group = "ESRI") %>%
addLayersControl(baseGroup = c("OSM (default)", "ESRI", "Stateman")) %>%
addEasyButton(easyButton(
icon = 'fa-home',
onClick = JS("function(btn, map){ map.fitBounds([[37.9188,15.6385],
[40.1183,17.2064]]);}"))
) %>%
addEasyButton(easyButton(
icon = 'fa-crosshairs', title='Locate Me',
onClick = JS("function(btn, map){ map.locate({setView: true});}"))
) %>%
addPolygons(
stroke = TRUE, weight = 2, fillOpacity = 0.5, smoothFactor = 1.0,
color = ~colorFactor(c("yellow","green","orange","red"),
levels=frane$pericolosi)(pericolosi),
popup = paste("<b>Tipologia:</b>", frane$tipologia, "<br>",
"<b>Pericolosità:</b>", frane$pericolosi, "<br>",
"<b>Stato:</b>", frane$stato_atti, "<br>",
"<b>Comune:</b>", frane$comune)
)%>%
addLegend("bottomleft",
pal=colorFactor(c("yellow","green","orange","red"),
levels=frane$pericolosi),
values=frane$pericolosi,
title = "Pericolosità",
opacity = 1
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment