normalizePolygons static method
Normalizes dynamic polygon input into standard 4-level coordinates:
[polygon][ring][point][lon, lat].
Implementation
static List<List<List<List<double>>>> normalizePolygons(dynamic input) {
if (input == null || input is! List || input.isEmpty) {
return const [];
}
final first = input.first;
if (first is! List || first.isEmpty) {
return const [];
}
final second = first.first;
if (second is! List || second.isEmpty) {
return const [];
}
final third = second.first;
if (third is num) {
// 3-level list: [ring/polygon][point][lon, lat] -> wrap each ring as a single-ring polygon
return input
.map<List<List<List<double>>>>(
(ring) => [
(ring as List)
.map<List<double>>(
(pt) => [
((pt as List)[0] as num).toDouble(),
(pt[1] as num).toDouble(),
],
)
.toList(),
],
)
.toList();
} else if (third is List) {
// 4-level list: [polygon][ring][point][lon, lat]
return input
.map<List<List<List<double>>>>(
(poly) =>
(poly as List)
.map<List<List<double>>>(
(ring) =>
(ring as List)
.map<List<double>>(
(pt) => [
((pt as List)[0] as num).toDouble(),
(pt[1] as num).toDouble(),
],
)
.toList(),
)
.toList(),
)
.toList();
}
return const [];
}