feat: expose map layer controls and explicit data coverage

This commit is contained in:
2026-10-29 23:15:11 +02:00
parent 87b74f0c2a
commit 8ddfa93f45
6 changed files with 434 additions and 7 deletions
@@ -0,0 +1,94 @@
import type {
InvestmentMapArea,
InvestmentMapFeature,
} from './interactive-investment-map';
export default function InvestmentMapCoverage({
points,
areas,
unlocated,
truncated,
}: {
points: InvestmentMapFeature[];
areas: InvestmentMapArea[];
unlocated: number;
truncated: boolean;
}) {
const rows = [
{
label: 'Marcadores de investimento',
records: points.map((point) => point.properties),
},
{ label: 'Áreas e limites', records: areas },
];
return (
<section
className="space-y-2 rounded border p-3"
aria-label="Cobertura dos dados do mapa"
>
<h3 className="font-semibold">Cobertura desta consulta</h3>
{truncated && (
<p role="note">
Resultados limitados pela consulta. Refine os filtros; as
contagens abaixo não representam o total do cadastro.
</p>
)}
<div className="overflow-x-auto">
<table className="w-full text-left text-sm">
<caption className="text-left">
Registos recebidos para os filtros actuais, incluindo
camadas ocultas.
</caption>
<thead>
<tr>
<th scope="col">Camada</th>
<th scope="col">Registos</th>
<th scope="col">Sem fonte indicada</th>
<th scope="col">Sem data indicada</th>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.label}>
<th scope="row">{row.label}</th>
<td>{row.records.length}</td>
<td>
{
row.records.filter(
(record) =>
!record.source_reference?.trim(),
).length
}
</td>
<td>
{
row.records.filter(
(record) =>
!record.source_date?.trim(),
).length
}
</td>
</tr>
))}
</tbody>
</table>
</div>
<p>
Investimentos com ponto nesta resposta:{' '}
{new Set(points.map((point) => point.properties.id)).size}. Um
investimento pode ter vários marcadores.
</p>
<p>
Investimentos sem ponto público utilizável nesta consulta:{' '}
{unlocated}.
{unlocated > 0 && ' As fichas continuam disponíveis abaixo.'}
</p>
<p className="text-sm">
A indicação de fonte ou data não comprova cobertura completa nem
actualidade. Ausência de registos não significa ausência de
investimento. Esta consulta não mede disponibilidade de
recursos, infra-estruturas ou mão-de-obra.
</p>
</section>
);
}
@@ -1,6 +1,7 @@
import SearchState from '@/components/search-state';
import { useEffect, useState } from 'react';
import TerritoryGeometryPreview from './territory-geometry-preview';
import InvestmentMapCoverage from './investment-map-coverage';
import InteractiveInvestmentMap, {
type InvestmentMapFeature,
type InvestmentMapArea,
@@ -21,6 +22,10 @@ export default function InvestmentMapPanel({
const [error, setError] = useState('');
const [retry, setRetry] = useState(0);
const [areas, setAreas] = useState<InvestmentMapArea[]>([]);
const [truncated, setTruncated] = useState(false);
const [showPoints, setShowPoints] = useState(true);
const [showAreas, setShowAreas] = useState(true);
const [matched, setMatched] = useState(0);
useEffect(() => {
const controller = new AbortController();
const params = new URLSearchParams(JSON.parse(key));
@@ -28,6 +33,8 @@ export default function InvestmentMapPanel({
setError('');
setMissing([]);
setAreas([]);
setTruncated(false);
setMatched(0);
fetch(`/api/v1/investment/map?${params}`, {
signal: controller.signal,
headers: { Accept: 'application/json' },
@@ -41,10 +48,14 @@ export default function InvestmentMapPanel({
setPoints(data.features);
setAreas(data.areas ?? []);
setMissing(data.unlocated ?? []);
setError(
data.truncated
? 'Cobertura limitada: refine os filtros.'
: '',
setTruncated(Boolean(data.truncated));
setMatched(
data.matched_count ??
new Set(
(data.features as InvestmentMapFeature[]).map(
(point) => point.properties.id,
),
).size + (data.unlocated?.length ?? 0),
);
})
.catch(() => {
@@ -57,13 +68,53 @@ export default function InvestmentMapPanel({
<section className="space-y-3">
<SearchState
scope="Registos consultados pelo mapa"
countLabel="registos, incluindo os que não têm coordenadas"
countLabel="investimentos, incluindo os que não têm coordenadas"
loading={points === null && !error}
error={error}
total={(points?.length ?? 0) + missing.length}
total={matched}
retry={() => setRetry((value) => value + 1)}
/>
<InteractiveInvestmentMap points={points} areas={areas} />
<fieldset className="flex flex-wrap gap-4 rounded border p-3">
<legend className="font-semibold">
Camadas desta consulta
</legend>
<label>
<input
type="checkbox"
checked={showPoints}
onChange={(event) =>
setShowPoints(event.target.checked)
}
/>{' '}
Investimentos com ponto
</label>
<label>
<input
type="checkbox"
checked={showAreas}
onChange={(event) => setShowAreas(event.target.checked)}
/>{' '}
Áreas e limites
</label>
</fieldset>
{!showPoints && !showAreas && (
<p role="status">
Camadas ocultas. Active uma camada para voltar a consultar
os registos no mapa.
</p>
)}
<InteractiveInvestmentMap
points={points === null ? null : showPoints ? points : []}
areas={showAreas ? areas : []}
/>
{points !== null && (
<InvestmentMapCoverage
points={points}
areas={areas}
unlocated={missing.length}
truncated={truncated}
/>
)}
<TerritoryGeometryPreview
territoryId={
territoryId ||