Querying elements from osm and doing practical things with them is really a useful and fun way of code “hacking” for me. In this case, I wanted to show farmers markets with a reactive map like leaflet like I’ve done before in my journal entries. In this case, I wanted to make it easy to browse the times, seasons, and contact info for farmers markets in the Anchorage, Alaska area. I think with some refinement this map could be useful to sellers and buyers to determine which farmers markets they can fit into their schedules.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
library(tidyverse) library(osmdata) library(leaflet) library(htmlwidgets) marketplace <- opq(c(xmin = -150.494625, ymin = 60.771028, xmax = -148.866047, ymax = 61.550720)) %>% add_osm_feature("amenity", "marketplace") %>% osmdata_sf() marketplace_points <- marketplace$osm_points greenLeafIcon <- makeIcon( iconUrl = "https://leafletjs.com/examples/custom-icons/leaf-green.png", iconWidth = 38, iconHeight = 95, iconAnchorX = 22, iconAnchorY = 94, shadowUrl = "https://leafletjs.com/examples/custom-icons/leaf-shadow.png", shadowWidth = 50, shadowHeight = 64, shadowAnchorX = 4, shadowAnchorY = 62 ) content <- paste(sep = "<br/>", paste0("<b><a href='", marketplace_points$website,"'>", marketplace_points$name, "</a></b>"), paste("<i>", marketplace_points$description, "</i>"), #paste(marketplace_points$addr.housenumber, marketplace_points$addr.street), #paste(marketplace_points$addr.city, marketplace_points$addr.state, marketplace_points$addr.postcode), paste("Phone:", marketplace_points$phone), paste("Email:", marketplace_points$email), #paste("Hours:", marketplace_points$opening_hours), paste( paste0("<b><a href='", marketplace_points$website,"'>", "Website", "</a></b>")) ) (m <- leaflet(marketplace$osm_points) %>% addTiles() %>% addMarkers(icon = greenLeafIcon, popup = lapply(content, htmltools::HTML))) saveWidget(m, "farmers_markets.html") #write.csv(marketplace_points, file = "marketplace_points.csv")