feat: show immediate administrative subdivisions and map coverage gaps

This commit is contained in:
2026-11-04 10:58:28 +02:00
parent 6dde36b5ca
commit bbc05f1df6
12 changed files with 399 additions and 26 deletions
@@ -18,7 +18,11 @@ export default function CatalogueInvestmentMap({
territoryId?: string;
mapKind?: InvestmentMapKind;
}) {
const { context, error } = useTerritoryGeometry(territoryId);
const { context, error } = useTerritoryGeometry(
territoryId,
undefined,
true,
);
return (
<InteractiveInvestmentMap
points={points}
@@ -54,14 +58,15 @@ export default function CatalogueInvestmentMap({
Sem limite administrativo acessível para o
território seleccionado.
{context.areas.length > 0
? ' Os limites de níveis superiores são apenas contexto e não representam a selecção.'
? ' Os limites disponíveis são contexto administrativo e não substituem o limite da selecção.'
: ''}
</p>
)}
{context?.truncated && (
<p role="alert">
Cobertura administrativa incompleta: são
apresentados até 100 limites.
consultadas até 100 geometrias e 500
subdivisões.
</p>
)}
</>
@@ -25,6 +25,7 @@ export type InvestmentMapFeature = {
};
export type InvestmentMapArea = {
selected_territory?: boolean;
child_territory?: boolean;
location_type?: string;
purpose?: string;
geometry: GeoJsonObject;
@@ -67,7 +68,7 @@ export default function InteractiveInvestmentMap({
}[mapKind];
const areaDescription = (area: InvestmentMapArea) =>
area.purpose === 'administrative_boundary'
? 'Limite administrativo da edição indicada; não representa um local de investimento'
? `${area.selected_territory ? 'Território seleccionado' : area.child_territory ? 'Subdivisão do território seleccionado' : 'Contexto de nível superior'} · Limite administrativo da edição indicada; não representa um local de investimento`
: area.purpose === 'declared_parcel'
? 'Perímetro declarado pelo Promotor; não é limite administrativo nem comprova disponibilidade legal'
: mapKind === 'documented_locations'
@@ -62,21 +62,32 @@ export function TerritoryGeometryDetails({
{!context.selected_geometry_available &&
context.areas.length > 0 && (
<p role="note">
O mapa mostra apenas limites dos níveis
superiores como contexto. Estes limites não
representam o território seleccionado.
O mapa mostra outros limites da hierarquia como
contexto. Estes limites não representam o
território seleccionado.
</p>
)}
<p>
{context.context_geometry_count} limites disponíveis na
hierarquia selecionada. São contexto administrativo, não
hierarquia consultada. São contexto administrativo, não
perímetro nem disponibilidade de investimento. A edição
e a atualidade jurídica são informações distintas.
</p>
{context.child_coverage?.location_type && (
<p role="status">
Subdivisões do nível imediatamente inferior com
limite nesta resposta:{' '}
{context.child_coverage.represented_count} de{' '}
{context.child_coverage.registered_count}{' '}
referências acessíveis. As restantes não têm limite
apresentado nesta consulta; isso não significa
inexistência do território.
</p>
)}
{context.truncated && (
<p role="alert">
Exibidos os primeiros 100 limites; cobertura
incompleta.
Consulta limitada a 100 geometrias e 500
subdivisões; cobertura incompleta.
</p>
)}
{renderMap && context.areas.length > 0 && (
@@ -93,7 +104,9 @@ export function TerritoryGeometryDetails({
{area.title} ·{' '}
{area.selected_territory
? 'Território seleccionado'
: 'Contexto de nível superior'}{' '}
: area.child_territory
? 'Subdivisão do território seleccionado'
: 'Contexto de nível superior'}{' '}
· Fonte:{' '}
{area.source_reference ?? 'Não indicada'} ·
Edição: {area.source_date ?? 'Não indicada'}
@@ -6,13 +6,21 @@ export type TerritoryGeometryContext = {
context_geometry_count: number;
areas: InvestmentMapArea[];
truncated: boolean;
child_coverage?: {
location_type: string | null;
registered_count: number;
represented_count: number;
reference_limit: number;
geometry_limit: number;
} | null;
};
export function useTerritoryGeometry(
territoryId?: string,
endpoint = '/api/v1/investment/territory-geometries',
includeChildren = false,
) {
const key = JSON.stringify([territoryId, endpoint]);
const key = JSON.stringify([territoryId, endpoint, includeChildren]);
const [result, setResult] = useState<{
key: string;
context: TerritoryGeometryContext | null;
@@ -23,7 +31,7 @@ export function useTerritoryGeometry(
setResult({ key, context: null, error: '' });
if (!territoryId) return () => controller.abort();
void fetch(
`${endpoint}?${new URLSearchParams({ territory_id: territoryId })}`,
`${endpoint}?${new URLSearchParams({ territory_id: territoryId, ...(includeChildren ? { include_children: '1' } : {}) })}`,
{
signal: controller.signal,
headers: { Accept: 'application/json' },
@@ -52,6 +60,6 @@ export function useTerritoryGeometry(
});
});
return () => controller.abort();
}, [key, territoryId, endpoint]);
}, [key, territoryId, endpoint, includeChildren]);
return result.key === key ? result : { key, context: null, error: '' };
}