library(tidyverse)
library(sf)
library(osmdata)
library(glue)
library(leaflet)
library(htmltools)
Day 15 of 30DayMapChallenge: « OpenStreetMap » (previously).
Using data from OSM we’ll make a web map of defibrillators (AED) in Auvergne-Rhône-Alpes.
We send an Overpass API query with {osmdata}:
# France regions
# See https://r.iresmi.net/posts/2021/simplifying_polygons_layers/ for the data
<- read_sf("~/data/adminexpress/adminexpress_cog_simpl_000_2022.gpkg", layer = "region") |>
fr filter(insee_reg > "06")
# Get and cache OSM data for France
if (!file.exists("aed.rds")) {
<- opq(st_bbox(fr), osm_types = "node", timeout = 6000) |>
aed add_osm_features(features = c(
'"emergency"="defibrillator"')) |>
osmdata_sf() |>
pluck("osm_points") |>
st_join(fr, left = FALSE) |>
write_rds("aed.rds")
else {
} <- read_rds("aed.rds")
aed }
Automated external defibrillator in AURA
<- awesomeIcons(
icons library = "fa",
icon = "heart",
markerColor = "white",
iconColor = "darkgreen")
# Just keep the region data
|>
aed st_join(fr |>
filter(insee_reg == 84),
left = FALSE) |>
leaflet(options = leafletOptions(preferCanvas = TRUE)) |>
addTiles() |>
addAwesomeMarkers(
clusterOptions = markerClusterOptions(),
icon = icons,
popup = ~glue("
<table>
<tr><th style='font-weight:bold'>localisation</th>
<td>{htmlEscape(coalesce(`defibrillator:location:fr`, `defibrillator:location`))}</td></tr>
<tr><th>intérieur</th><td>{htmlEscape(coalesce(indoor, `indoor:description`))}</td></tr>
<tr><th>niveau</th><td>{htmlEscape(level)}</td></tr>
<tr><th>accès</th><td>{htmlEscape(access)}</td></tr>
<tr><th>horaires</th><td>{htmlEscape(opening_hours)}</td></tr>
<tr><th>opérateur</th><td>{htmlEscape(operator)}</td></tr>
<tr><th>tél.</th><td>{htmlEscape(phone)}</td></tr>
<tr><th>réf.</th><td>{htmlEscape(`ref:FR:GeoDAE`)}</td></tr>
<tr><th>particularité</th><td>{htmlEscape(defibrillator)}</td></tr>
<tr><th>description</th><td>{htmlEscape(coalesce(`description:fr`, description))}</td></tr>
</table>"))