mirror of
https://github.com/zvx-echo6/navi.git
synced 2026-05-20 14:44:51 +02:00
fix: Correct MultiPolygon coordinate flattening for fitBounds
MultiPolygon coordinates need .flat(2) not .flat(1) to get actual coordinate pairs. With flat(1), we were iterating over rings instead of coordinates, causing invalid lat values > 90. Also added bounds validation before fitBounds to catch future issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
1bccfad22b
commit
3158537488
1 changed files with 12 additions and 6 deletions
|
|
@ -2401,7 +2401,7 @@ const MapView = forwardRef(function MapView(_, ref) {
|
||||||
try {
|
try {
|
||||||
const coords = boundaryGeometry.type === 'Polygon'
|
const coords = boundaryGeometry.type === 'Polygon'
|
||||||
? boundaryGeometry.coordinates[0]
|
? boundaryGeometry.coordinates[0]
|
||||||
: boundaryGeometry.coordinates.flat(1)
|
: boundaryGeometry.coordinates.flat(2)
|
||||||
|
|
||||||
if (coords.length > 0) {
|
if (coords.length > 0) {
|
||||||
let minLng = Infinity, maxLng = -Infinity, minLat = Infinity, maxLat = -Infinity
|
let minLng = Infinity, maxLng = -Infinity, minLat = Infinity, maxLat = -Infinity
|
||||||
|
|
@ -2411,11 +2411,17 @@ const MapView = forwardRef(function MapView(_, ref) {
|
||||||
if (lat < minLat) minLat = lat
|
if (lat < minLat) minLat = lat
|
||||||
if (lat > maxLat) maxLat = lat
|
if (lat > maxLat) maxLat = lat
|
||||||
}
|
}
|
||||||
map.fitBounds([[minLng, minLat], [maxLng, maxLat]], {
|
// Validate bounds before fitting
|
||||||
padding: 50,
|
if (minLng >= -180 && maxLng <= 180 && minLat >= -90 && maxLat <= 90 &&
|
||||||
duration: 700,
|
minLng < maxLng && minLat < maxLat) {
|
||||||
maxZoom: 16,
|
map.fitBounds([[minLng, minLat], [maxLng, maxLat]], {
|
||||||
})
|
padding: 50,
|
||||||
|
duration: 700,
|
||||||
|
maxZoom: 16,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.warn('Invalid bounds:', { minLng, maxLng, minLat, maxLat })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('fitBounds error:', e)
|
console.warn('fitBounds error:', e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue