Upload 2 files
Browse files- depth_interactive_map_alpha.R +48 -36
- styles.css +6 -2
depth_interactive_map_alpha.R
CHANGED
|
@@ -209,18 +209,22 @@ PATP_DELITO_LABELS_EN <- c(
|
|
| 209 |
"Libertad personal" = "Personal freedom"
|
| 210 |
)
|
| 211 |
|
| 212 |
-
# Infrastructure point categories -- grouped from the raw
|
| 213 |
-
#
|
| 214 |
-
#
|
| 215 |
-
#
|
|
|
|
|
|
|
| 216 |
INFRA_CATS <- c(
|
| 217 |
-
"Shelter" = "#2D6E54",
|
| 218 |
-
"Food & Lodging" = "#B89307",
|
| 219 |
-
"Government" = "#3A4B5C",
|
| 220 |
-
"
|
| 221 |
-
"
|
| 222 |
-
"
|
| 223 |
-
"
|
|
|
|
|
|
|
| 224 |
)
|
| 225 |
|
| 226 |
CRIME_COLS <- list(
|
|
@@ -441,7 +445,8 @@ WEB_SQL_TEMPLATES <- list(
|
|
| 441 |
CASE
|
| 442 |
WHEN category = 'Shelter' THEN 'Shelter'
|
| 443 |
WHEN LOWER(category) IN ('food','restaurant','lodging') THEN 'Food & Lodging'
|
| 444 |
-
WHEN LOWER(category)
|
|
|
|
| 445 |
WHEN category = 'Legal/NGO' OR LOWER(category) = 'charity' THEN 'Legal & Aid'
|
| 446 |
WHEN LOWER(category) = 'police' THEN 'Police'
|
| 447 |
WHEN LOWER(category) IN ('hospital','medical') THEN 'Health'
|
|
@@ -593,9 +598,15 @@ WEB_SQL_TEMPLATES <- list(
|
|
| 593 |
wkt
|
| 594 |
FROM state_polygons",
|
| 595 |
|
|
|
|
|
|
|
|
|
|
| 596 |
src_routes =
|
| 597 |
-
"SELECT
|
| 598 |
-
|
|
|
|
|
|
|
|
|
|
| 599 |
|
| 600 |
src_via = "SELECT tipo, condicion, wkt FROM viaferrea",
|
| 601 |
|
|
@@ -656,7 +667,8 @@ WEB_SQL_TEMPLATES <- list(
|
|
| 656 |
CASE
|
| 657 |
WHEN category = 'Shelter' THEN 'Shelter'
|
| 658 |
WHEN LOWER(category) IN ('food','restaurant','lodging') THEN 'Food & Lodging'
|
| 659 |
-
WHEN LOWER(category)
|
|
|
|
| 660 |
WHEN category = 'Legal/NGO' OR LOWER(category) = 'charity' THEN 'Legal & Aid'
|
| 661 |
WHEN LOWER(category) = 'police' THEN 'Police'
|
| 662 |
WHEN LOWER(category) IN ('hospital','medical') THEN 'Health'
|
|
@@ -1147,13 +1159,12 @@ WEB_SPEC <- list(
|
|
| 1147 |
list(id = "pop-choro", type = "fill", src = "src_pop_mun",
|
| 1148 |
geom = "polygon", color = "pop_qstep", value = "pobtot",
|
| 1149 |
opacity = 0.7, visible = FALSE),
|
| 1150 |
-
# patp-choro
|
|
|
|
|
|
|
| 1151 |
list(id = "patp-choro", type = "fill", src = "src_patp",
|
| 1152 |
geom = "polygon", color = "patp_qstep", value = "t_part",
|
| 1153 |
opacity = 0.7, visible = FALSE, requires = "dim_patp_mun"),
|
| 1154 |
-
list(id = "pobreza-choro", type = "fill", src = "src_pobreza",
|
| 1155 |
-
geom = "polygon", color = "pobreza_qstep", value = "pobreza_pct",
|
| 1156 |
-
opacity = 0.7, visible = FALSE, requires = "dim_pobreza_mun"),
|
| 1157 |
list(id = "fosas-choro", type = "fill", src = "src_fosas",
|
| 1158 |
geom = "polygon", color = "fosas_step", value = "fosas_total",
|
| 1159 |
opacity = 0.65, visible = FALSE, requires = "dim_fosas_mun"),
|
|
@@ -1290,13 +1301,7 @@ WEB_SPEC <- list(
|
|
| 1290 |
delitos_fc_b_j_a = list(type = "cats", pal = "patp_delito",
|
| 1291 |
filterable = "patp_delito")
|
| 1292 |
)),
|
| 1293 |
-
list(kind = "radios", group = "patp")
|
| 1294 |
-
list(kind = "layer", value = "pobreza-choro",
|
| 1295 |
-
label = "Poverty",
|
| 1296 |
-
tooltip = "CONEVAL 2020 poverty / extreme poverty share by municipality. Enable the grid view to see this layer.",
|
| 1297 |
-
legend = list(type = "ramp", pal = "pobreza", unit = " %",
|
| 1298 |
-
labels = "qualitative")),
|
| 1299 |
-
list(kind = "radios", group = "pobreza")
|
| 1300 |
))
|
| 1301 |
),
|
| 1302 |
|
|
@@ -1330,10 +1335,6 @@ WEB_SPEC <- list(
|
|
| 1330 |
list(label = "Road connectivity index", value = "ind_conec"),
|
| 1331 |
list(label = "Predominant rural problem", value = "pr_pred_loc_rur"),
|
| 1332 |
list(label = "Common-jurisdiction crime", value = "delitos_fc_b_j_a")
|
| 1333 |
-
),
|
| 1334 |
-
pobreza = list(
|
| 1335 |
-
list(label = "Poverty (%)", value = "pobreza_pct"),
|
| 1336 |
-
list(label = "Extreme poverty (%)", value = "pobreza_ext_pct")
|
| 1337 |
)
|
| 1338 |
),
|
| 1339 |
|
|
@@ -3382,19 +3383,20 @@ server <- function(input, output, session) {
|
|
| 3382 |
dist_infra = NULL
|
| 3383 |
)
|
| 3384 |
|
| 3385 |
-
# Normalise the raw
|
| 3386 |
-
# (mirrors the SQL CASE in WEB_SQL_TEMPLATES$load_infra_pts).
|
| 3387 |
normalize_infra_cat <- function(category) {
|
| 3388 |
if (length(category) == 0) return(character(0))
|
| 3389 |
c_low <- tolower(category)
|
| 3390 |
out <- ifelse(category == "Shelter", "Shelter",
|
| 3391 |
ifelse(c_low %in% c("food","restaurant","lodging"), "Food & Lodging",
|
| 3392 |
-
ifelse(c_low
|
|
|
|
| 3393 |
ifelse(category == "Legal/NGO" | c_low == "charity", "Legal & Aid",
|
| 3394 |
ifelse(c_low == "police", "Police",
|
| 3395 |
ifelse(c_low %in% c("hospital","medical"), "Health",
|
| 3396 |
ifelse(c_low %in% c("religious","place-of-worship"), "Religious",
|
| 3397 |
-
"Other")))))))
|
| 3398 |
out
|
| 3399 |
}
|
| 3400 |
|
|
@@ -4353,8 +4355,18 @@ server <- function(input, output, session) {
|
|
| 4353 |
lazy_add_fill("routes", "src_routes", "routes-lines", function(prx, d)
|
| 4354 |
prx |> add_line_layer("routes-lines", source = d,
|
| 4355 |
line_color = COL_AMBER,
|
| 4356 |
-
|
| 4357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4358 |
if ("viaferrea-lines" %in% active)
|
| 4359 |
lazy_add_fill("via", "src_via", "viaferrea-lines", function(prx, d)
|
| 4360 |
prx |> add_line_layer("viaferrea-lines", source = d,
|
|
|
|
| 209 |
"Libertad personal" = "Personal freedom"
|
| 210 |
)
|
| 211 |
|
| 212 |
+
# Infrastructure point categories -- grouped from the raw `category` field in
|
| 213 |
+
# support_infrastructure. Embassy is split out of Government (consular
|
| 214 |
+
# protection is a distinct service for migrants, not bureaucratic admin), and
|
| 215 |
+
# an Other fallback catches new categories ingested later so they don't get
|
| 216 |
+
# silently lumped into an existing bucket. SQL CASE in
|
| 217 |
+
# WEB_SQL_TEMPLATES$load_infra_pts maps the raw values to these buckets.
|
| 218 |
INFRA_CATS <- c(
|
| 219 |
+
"Shelter" = "#2D6E54", # forest green
|
| 220 |
+
"Food & Lodging" = "#B89307", # ochre
|
| 221 |
+
"Government" = "#3A4B5C", # slate
|
| 222 |
+
"Embassy" = "#1F4A6B", # deep navy (international protection)
|
| 223 |
+
"Legal & Aid" = "#7E4A86", # mauve
|
| 224 |
+
"Police" = "#9E2A3A", # brick red
|
| 225 |
+
"Health" = "#0987A8", # teal
|
| 226 |
+
"Religious" = "#6B5640", # warm brown
|
| 227 |
+
"Other" = "#94a3b8" # neutral slate (fallback)
|
| 228 |
)
|
| 229 |
|
| 230 |
CRIME_COLS <- list(
|
|
|
|
| 445 |
CASE
|
| 446 |
WHEN category = 'Shelter' THEN 'Shelter'
|
| 447 |
WHEN LOWER(category) IN ('food','restaurant','lodging') THEN 'Food & Lodging'
|
| 448 |
+
WHEN LOWER(category) = 'government' THEN 'Government'
|
| 449 |
+
WHEN LOWER(category) = 'embassy' THEN 'Embassy'
|
| 450 |
WHEN category = 'Legal/NGO' OR LOWER(category) = 'charity' THEN 'Legal & Aid'
|
| 451 |
WHEN LOWER(category) = 'police' THEN 'Police'
|
| 452 |
WHEN LOWER(category) IN ('hospital','medical') THEN 'Health'
|
|
|
|
| 598 |
wkt
|
| 599 |
FROM state_polygons",
|
| 600 |
|
| 601 |
+
# Main migration routes -- `roads` table holds locality-to-locality segments
|
| 602 |
+
# for the migration-routes layer (from_name / to_name / length_m / road_tipo /
|
| 603 |
+
# wkt). The columns drive both the paint expression and the hover tooltip.
|
| 604 |
src_routes =
|
| 605 |
+
"SELECT from_name, to_name, road_tipo,
|
| 606 |
+
CAST(length_m AS DOUBLE) AS length_m,
|
| 607 |
+
wkt
|
| 608 |
+
FROM roads
|
| 609 |
+
WHERE wkt IS NOT NULL",
|
| 610 |
|
| 611 |
src_via = "SELECT tipo, condicion, wkt FROM viaferrea",
|
| 612 |
|
|
|
|
| 667 |
CASE
|
| 668 |
WHEN category = 'Shelter' THEN 'Shelter'
|
| 669 |
WHEN LOWER(category) IN ('food','restaurant','lodging') THEN 'Food & Lodging'
|
| 670 |
+
WHEN LOWER(category) = 'government' THEN 'Government'
|
| 671 |
+
WHEN LOWER(category) = 'embassy' THEN 'Embassy'
|
| 672 |
WHEN category = 'Legal/NGO' OR LOWER(category) = 'charity' THEN 'Legal & Aid'
|
| 673 |
WHEN LOWER(category) = 'police' THEN 'Police'
|
| 674 |
WHEN LOWER(category) IN ('hospital','medical') THEN 'Health'
|
|
|
|
| 1159 |
list(id = "pop-choro", type = "fill", src = "src_pop_mun",
|
| 1160 |
geom = "polygon", color = "pop_qstep", value = "pobtot",
|
| 1161 |
opacity = 0.7, visible = FALSE),
|
| 1162 |
+
# patp-choro paints in BOTH modes (mun-level + per-cell). Poverty + extreme
|
| 1163 |
+
# poverty live INSIDE patp-choro as chips now, so the standalone
|
| 1164 |
+
# pobreza-choro layer was removed.
|
| 1165 |
list(id = "patp-choro", type = "fill", src = "src_patp",
|
| 1166 |
geom = "polygon", color = "patp_qstep", value = "t_part",
|
| 1167 |
opacity = 0.7, visible = FALSE, requires = "dim_patp_mun"),
|
|
|
|
|
|
|
|
|
|
| 1168 |
list(id = "fosas-choro", type = "fill", src = "src_fosas",
|
| 1169 |
geom = "polygon", color = "fosas_step", value = "fosas_total",
|
| 1170 |
opacity = 0.65, visible = FALSE, requires = "dim_fosas_mun"),
|
|
|
|
| 1301 |
delitos_fc_b_j_a = list(type = "cats", pal = "patp_delito",
|
| 1302 |
filterable = "patp_delito")
|
| 1303 |
)),
|
| 1304 |
+
list(kind = "radios", group = "patp")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1305 |
))
|
| 1306 |
),
|
| 1307 |
|
|
|
|
| 1335 |
list(label = "Road connectivity index", value = "ind_conec"),
|
| 1336 |
list(label = "Predominant rural problem", value = "pr_pred_loc_rur"),
|
| 1337 |
list(label = "Common-jurisdiction crime", value = "delitos_fc_b_j_a")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1338 |
)
|
| 1339 |
),
|
| 1340 |
|
|
|
|
| 3383 |
dist_infra = NULL
|
| 3384 |
)
|
| 3385 |
|
| 3386 |
+
# Normalise the raw `category` strings into the INFRA_CATS buckets used by
|
| 3387 |
+
# the legend (mirrors the SQL CASE in WEB_SQL_TEMPLATES$load_infra_pts).
|
| 3388 |
normalize_infra_cat <- function(category) {
|
| 3389 |
if (length(category) == 0) return(character(0))
|
| 3390 |
c_low <- tolower(category)
|
| 3391 |
out <- ifelse(category == "Shelter", "Shelter",
|
| 3392 |
ifelse(c_low %in% c("food","restaurant","lodging"), "Food & Lodging",
|
| 3393 |
+
ifelse(c_low == "government", "Government",
|
| 3394 |
+
ifelse(c_low == "embassy", "Embassy",
|
| 3395 |
ifelse(category == "Legal/NGO" | c_low == "charity", "Legal & Aid",
|
| 3396 |
ifelse(c_low == "police", "Police",
|
| 3397 |
ifelse(c_low %in% c("hospital","medical"), "Health",
|
| 3398 |
ifelse(c_low %in% c("religious","place-of-worship"), "Religious",
|
| 3399 |
+
"Other"))))))))
|
| 3400 |
out
|
| 3401 |
}
|
| 3402 |
|
|
|
|
| 4355 |
lazy_add_fill("routes", "src_routes", "routes-lines", function(prx, d)
|
| 4356 |
prx |> add_line_layer("routes-lines", source = d,
|
| 4357 |
line_color = COL_AMBER,
|
| 4358 |
+
# Zoom-interpolated width so the network reads at a national view
|
| 4359 |
+
# without bloating into a solid mass when zoomed in on a city.
|
| 4360 |
+
line_width = list("interpolate", list("linear"), list("zoom"),
|
| 4361 |
+
4, 0.6, 8, 1.4, 12, 2.5),
|
| 4362 |
+
line_opacity = 0.55,
|
| 4363 |
+
# Tooltip names the connected localities + road quality. road_tipo
|
| 4364 |
+
# is Spanish in the source (Pavimentada / Vía sencilla / Terraceria
|
| 4365 |
+
# / Vía doble) -- left as-is to match the data the user maintains.
|
| 4366 |
+
tooltip = list("concat",
|
| 4367 |
+
"<b>", list("get", "from_name"),
|
| 4368 |
+
" to ", list("get", "to_name"), "</b>",
|
| 4369 |
+
"<br>", list("get", "road_tipo"))))
|
| 4370 |
if ("viaferrea-lines" %in% active)
|
| 4371 |
lazy_add_fill("via", "src_via", "viaferrea-lines", function(prx, d)
|
| 4372 |
prx |> add_line_layer("viaferrea-lines", source = d,
|
styles.css
CHANGED
|
@@ -2194,9 +2194,13 @@ button.mapbox-gl-draw_uncombine { display: none !important; }
|
|
| 2194 |
|
| 2195 |
#grid-icon-btn { position: relative; }
|
| 2196 |
|
| 2197 |
-
/* ---- Filterable categorical legend (click swatch to toggle) ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2198 |
.acc-legend-cats--filter {
|
| 2199 |
-
display: flex !important;
|
| 2200 |
flex-direction: column;
|
| 2201 |
gap: 3px;
|
| 2202 |
align-items: stretch;
|
|
|
|
| 2194 |
|
| 2195 |
#grid-icon-btn { position: relative; }
|
| 2196 |
|
| 2197 |
+
/* ---- Filterable categorical legend (click swatch to toggle) ---------------
|
| 2198 |
+
Layout for the visible state lives here, but visibility itself is owned by
|
| 2199 |
+
the parent rule `.acc-legend.legend-visible { display: block; }` / the
|
| 2200 |
+
per-shape `.legend-visible` rules above. Using `display: flex !important`
|
| 2201 |
+
here used to force the legend on even when the layer was toggled off; the
|
| 2202 |
+
layout-only properties below now apply whenever the parent flips visible. */
|
| 2203 |
.acc-legend-cats--filter {
|
|
|
|
| 2204 |
flex-direction: column;
|
| 2205 |
gap: 3px;
|
| 2206 |
align-items: stretch;
|