fix: GeoJSON MultiPolygon — кольца оборачивать в полигоны ([[ring]])
Баг: для relation с 2+ внешними кольцами coordinates отдавался [ring0, ring1]
(глубина 3) при type=MultiPolygon — невалидный GeoJSON, Leaflet падал
('latlngs[0] undefined') → белый экран страницы анализа на кейсах с
мультиполигонами (РАС-кейс Минск: Камсамольскае возера из 2 колец).
Фронт: toLatLngs различает Polygon/MultiPolygon по глубине coords[0][0][0].
This commit is contained in:
@@ -173,7 +173,8 @@ def _water_geoms(elements: list[dict]) -> list[dict]:
|
|||||||
if not polygons:
|
if not polygons:
|
||||||
continue
|
continue
|
||||||
geom = (
|
geom = (
|
||||||
{'type': 'MultiPolygon', 'coordinates': polygons}
|
# GeoJSON MultiPolygon: [[ring0], [ring1]] — каждый полигон = список колец.
|
||||||
|
{'type': 'MultiPolygon', 'coordinates': [[p] for p in polygons]}
|
||||||
if len(polygons) > 1 else
|
if len(polygons) > 1 else
|
||||||
{'type': 'Polygon', 'coordinates': polygons[0]}
|
{'type': 'Polygon', 'coordinates': polygons[0]}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -129,9 +129,9 @@ const SearchMap = ({ tnpLat, tnpLon, maxDistance, zones, waterFeatures }) => {
|
|||||||
|
|
||||||
// Слой георекомендаций: водоёмы/болота (полигоны) + ж/д (линии) из /api/v1/water/{case_id}.
|
// Слой георекомендаций: водоёмы/болота (полигоны) + ж/д (линии) из /api/v1/water/{case_id}.
|
||||||
// Рисуется ПОД зонами, поверх тайлов OSM.
|
// Рисуется ПОД зонами, поверх тайлов OSM.
|
||||||
const toLatLngs = (coords) => Array.isArray(coords[0][0])
|
const toLatLngs = (coords) => Array.isArray(coords[0][0][0])
|
||||||
? coords.map((poly) => poly[0].map((c) => [c[1], c[0]])) // MultiPolygon
|
? coords.map((poly) => poly[0].map((c) => [c[1], c[0]])) // MultiPolygon: poly → внешнее кольцо
|
||||||
: coords[0].map((c) => [c[1], c[0]]); // Polygon
|
: coords[0].map((c) => [c[1], c[0]]); // Polygon: одно кольцо
|
||||||
const waterGeoJSON = (waterFeatures || [])
|
const waterGeoJSON = (waterFeatures || [])
|
||||||
.filter((f) => f.layer !== 'railway')
|
.filter((f) => f.layer !== 'railway')
|
||||||
.map((f) => ({ feature: f, positions: toLatLngs(f.geom.coordinates) }));
|
.map((f) => ({ feature: f, positions: toLatLngs(f.geom.coordinates) }));
|
||||||
|
|||||||
Reference in New Issue
Block a user