teqo-backup/src/utilities/municipalityMapNavigation.ts
Francisco Ignácio Fontoura Solla 2c30944593 B8+: escala das malhas em unidades reais, contrato do map key e degradacao
F1 — a tolerancia de simplificacao e os digitos de quantizacao viraram
politica em unidades de solo em scripts/lib/topology.mjs, consumida pelos
dois scripts de geometria. Os quantis 0.35 copiados cortavam as 19 ZE de
Salvador a ~0.6 m2 e os 417 municipios a ~1.78 km2; com tolerancia
absoluta e a grade de ~103 m do estado, a malha das zonas caiu de 480 para
30.2 pontos/feature. bahia-municipalities segue byte-identico e o tripwire
de bytes deu lugar a pontos/feature.

F2 — featureMapKey passou a ser asserido sobre features reais das tres
malhas comprometidas (417 codarea, 27 code, 19 slug), e o comentario de
MAP_KEY_PROPERTIES agora diz o que o codigo faz: as propriedades sao
mutuamente exclusivas, nao ordenadas por especificidade.

F3 — a malha das zonas e um detalhe sobre o mapa, nao o mapa: se o chunk
falha, Salvador cai no poligono municipal que ja esta desenhado embaixo e
o resto da Bahia continua funcionando, com o motivo logado. A ressalva de
aproximacao saiu do gate de comparacao e passou a depender de
bundle.hasZoneMunicipalities, derivado no servidor de municipality.kind.

F4 — orfaos deletados: os dois acessores sem chamador, isZoneMapKey (o
servidor ja sabe a regra), o wrapper simplifyTopology e o helper
polygonCount com um branch inalcancavel. MunicipalityMapNavigation
colapsou em string | undefined e MunicipalitiesByMapKey em
Record<string, string>.
2026-07-27 01:59:36 -03:00

59 lines
2.1 KiB
TypeScript

import type { AccessibleMunicipality } from '@/lib/municipalityProximity'
type MunicipalityMapSlugEntry = {
slug: string
name: string
}
/** IBGE codarea → the accessible catalog units inside it (Salvador has 19). */
export type MunicipalitiesByIbgeCode = Record<string, MunicipalityMapSlugEntry[]>
/**
* Map key → the slug of the single unit it paints. Since B8 F2 the map draws one
* polygon per catalog unit — zone municipalities by slug, everything else by IBGE
* codarea — so this index is 1:1 where `MunicipalitiesByIbgeCode` is 1:N, and the
* name it used to carry alongside was 435 dead strings in the RSC payload of
* every visit to Início (the readout takes the name from the feature it painted).
*/
export type MunicipalitiesByMapKey = Record<string, string>
/**
* What the choropleth paints a unit by: a zone municipality has no code of its
* own (the whole city shares one), so it is keyed by its immutable catalog slug,
* which is also the polygon's key in `bahia-municipality-zones.topo.json`.
*/
export const mapKeyForMunicipality = (municipality: {
kind: 'municipio' | 'zona'
slug: string
ibgeCode: string
}): string => (municipality.kind === 'zona' ? municipality.slug : municipality.ibgeCode)
export const buildMunicipalitiesByIbgeCode = (
municipalities: readonly AccessibleMunicipality[],
): MunicipalitiesByIbgeCode => {
const byIbge: MunicipalitiesByIbgeCode = {}
for (const municipality of municipalities) {
const entries = byIbge[municipality.ibgeCode] ?? []
entries.push({ slug: municipality.slug, name: municipality.name })
byIbge[municipality.ibgeCode] = entries
}
for (const ibgeCode of Object.keys(byIbge)) {
byIbge[ibgeCode].sort((left, right) => left.name.localeCompare(right.name, 'pt-BR'))
}
return byIbge
}
export const buildMunicipalitiesByMapKey = (
municipalities: ReadonlyArray<AccessibleMunicipality & { kind: 'municipio' | 'zona' }>,
): MunicipalitiesByMapKey => {
const byMapKey: MunicipalitiesByMapKey = {}
for (const municipality of municipalities) {
byMapKey[mapKeyForMunicipality(municipality)] = municipality.slug
}
return byMapKey
}