/** * Static Bahia municipality and identity-territory geometries for the campaign map. * * TopoJSON files are generated by `pnpm build:geometries` from IBGE Malhas (municípios) * and dissolved by the official Territórios de Identidade composition in * bahiaTerritories. See scripts/build-bahia-geometries.mjs for full provenance. * * Framework-free: safe to import from client components in B3 (Leaflet surfaces). */ import { feature } from 'topojson-client' import type { Feature, MultiPolygon, Polygon } from 'geojson' import type { GeometryCollection, Topology } from 'topojson-specification' import municipalityTopologyJson from '@/lib/geometries/bahia-municipalities.topo.json' import territoryTopologyJson from '@/lib/geometries/bahia-identity-territories.topo.json' export type BahiaMunicipalityProperties = { codarea: string name: string } export type BahiaTerritoryProperties = { code: string name: string } export type BahiaMunicipalityFeature = Feature< Polygon | MultiPolygon, BahiaMunicipalityProperties > export type BahiaTerritoryFeature = Feature type MunicipalityTopology = Topology<{ municipalities: GeometryCollection }> type TerritoryTopology = Topology<{ territories: GeometryCollection }> export const bahiaMunicipalitiesTopology = municipalityTopologyJson as unknown as MunicipalityTopology export const bahiaIdentityTerritoriesTopology = territoryTopologyJson as unknown as TerritoryTopology const municipalityFeatures = feature( bahiaMunicipalitiesTopology, bahiaMunicipalitiesTopology.objects.municipalities, ).features as BahiaMunicipalityFeature[] const territoryFeatures = feature( bahiaIdentityTerritoriesTopology, bahiaIdentityTerritoriesTopology.objects.territories, ).features as BahiaTerritoryFeature[] const municipalityByCodarea = new Map( municipalityFeatures.map((entry) => [entry.properties.codarea, entry]), ) const territoryByCode = new Map( territoryFeatures.map((entry) => [entry.properties.code, entry]), ) export const getMunicipalityFeature = ( codarea: string, ): BahiaMunicipalityFeature | undefined => municipalityByCodarea.get(codarea) export const getTerritoryFeature = (code: string): BahiaTerritoryFeature | undefined => territoryByCode.get(code) export const bahiaMunicipalityFeatures: readonly BahiaMunicipalityFeature[] = municipalityFeatures export const bahiaTerritoryFeatures: readonly BahiaTerritoryFeature[] = territoryFeatures