| 3 | import { useState } from "react"; |
| 4 | |
| 5 | function getPolygonPoints(coordinates: [number, number][][]): string { |
| 6 | const coords = coordinates[0]; |
| 7 | if (!coords || coords.length < 3) return "10,30 20,8 35,25 25,35"; |
| 8 | const lngs = coords.map(c => c[0]); |
| 9 | const lats = coords.map(c => c[1]); |
| 10 | const minLng = Math.min(...lngs); |
| 11 | const maxLng = Math.max(...lngs); |
| 12 | const minLat = Math.min(...lats); |
| 13 | const maxLat = Math.max(...lats); |
| 14 | const rX = maxLng - minLng || 0.001; |
| 15 | const rY = maxLat - minLat || 0.001; |
| 16 | const unique = coords.length > 3 && coords[0][0] === coords[coords.length - 1][0] && coords[0][1] === coords[coords.length - 1][1] |
| 17 | ? coords.slice(0, -1) : coords; |
| 18 | return unique.map(c => { |
| 19 | const x = 4 + ((c[0] - minLng) / rX) * 32; |
| 20 | const y = 36 - ((c[1] - minLat) / rY) * 32; |
| 21 | return `${x.toFixed(1)},${y.toFixed(1)}`; |
| 22 | }).join(" "); |
| 23 | } |
| 24 | |
| 25 | interface FieldCardProps { |
| 26 | field: Field; |