import { useState } from 'react'; import { api, button, card } from './shared'; type Feature = { id: string; geometry: { type: string; coordinates: unknown[] }; properties: { purpose: string; source: string; observed_at: string }; }; function rings(value: unknown): number[][][] { if (!Array.isArray(value) || !value.length) return []; if (typeof value[0] === 'number') return [[value as number[]]]; if (Array.isArray(value[0]) && typeof value[0][0] === 'number') return [value as number[][]]; return value.flatMap(rings); } export default function ZoneMap({ id }: { id: string }) { const [features, setFeatures] = useState(null); const [error, setError] = useState(''); const [busy, setBusy] = useState(false); const points = (features ?? []).flatMap((f) => rings(f.geometry.coordinates).flat(), ); const xs = points.map((p) => p[0]), ys = points.map((p) => p[1]); const west = xs.length ? Math.min(...xs) : 0, south = ys.length ? Math.min(...ys) : 0; const dx = xs.length ? Math.max(...xs) - west : 1, dy = ys.length ? Math.max(...ys) - south : 1; const project = (p: number[]) => [ 20 + ((p[0] - west) / (dx || 1)) * 600, 300 - ((p[1] - south) / (dy || 1)) * 280, ]; return (

Localização e geometrias autorizadas

{error &&

{error}

} {features?.length === 0 && (

Não existe geometria autorizada para divulgação nesta ficha.

)} {!!features?.length && ( <>

Esquema das geometrias cadastradas, sem mapa-base. Não serve para demarcação ou atribuição de estatuto.

{features.map((f) => ( {f.properties.purpose} ·{' '} {f.properties.source} {rings(f.geometry.coordinates).map((ring, i) => ring.length === 1 ? ( ) : ( project(p).join(','), ) .join(' ')} fill="none" stroke="#065f46" strokeWidth="2" /> ), )} ))} )}
); }