Last active
June 9, 2022 11:24
-
-
Save geografif/b89b872703c2e012ff6c9546050e67d3 to your computer and use it in GitHub Desktop.
Plot points, labelling, set icon, set layer groups of basemap using leaflet package in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm(list = ls()) | |
setwd("D:/Learn/Rleaflet") | |
install.packages("shiny") | |
install.packages("leaflet") | |
library(leaflet) | |
library(htmltools) | |
library(sp) | |
library(rgdal) | |
pump <- readOGR("Lundpump.shp") | |
plot(pump) | |
pumpicon <- icons(ifelse(pump$status=="Working","bikeblue.png", | |
"bikered.png"), iconWidth=40,iconHeight=40) | |
m <- leaflet(pump) %>% | |
addProviderTiles(providers$CartoDB.Positron, group= "CartoDB") %>% | |
addProviderTiles(providers$Esri.WorldImagery, group = "Imagery") %>% | |
addTiles(group = "OSM") %>% | |
setView(lng=13.195, lat=55.705, zoom=14) %>% | |
addMarkers(lng=~xcoord, lat=~ycoord, icon=pumpicon, popup=~descriptio, | |
label=~Name, group = "Pump") %>% | |
addLayersControl( | |
baseGroups=c("CartoDB", "Imagery", "OSM"), | |
overlayGroups=c("Pump"), | |
options=layersControlOptions(collapsed=FALSE)) %>% | |
addEasyButton(easyButton( | |
icon="fa-crosshairs", title="Locate me", | |
onClick=JS("function(btn, map){ map.locate({setView: true});}"))); | |
print(m) | |
#Export as webpage, rename index.html | |
#Upload to repo | |
#Embed by <iframe src="relative path to the export folder"> </iframe> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment