fix: Validate coordinate points before processing to prevent freeze
This commit is contained in:
@@ -156,12 +156,18 @@ function Map({end, duration, slider, mapState, setMapState}) {
|
|||||||
const range = useMemo(() => parseSlider(end, duration, slider), [end, duration, slider]);
|
const range = useMemo(() => parseSlider(end, duration, slider), [end, duration, slider]);
|
||||||
|
|
||||||
const coords = useMemo(() => {
|
const coords = useMemo(() => {
|
||||||
if (!data || !data.length) return [];
|
if (!Array.isArray(data)) return [];
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
const [startTime, endTime] = range;
|
||||||
|
|
||||||
for (const point of data) {
|
for (const point of data) {
|
||||||
if ((!range || (point.time >= range[0] && point.time <= range[1]))) {
|
// Ensure the point and its time exist before checking the range
|
||||||
|
if (!point || !point.time) continue;
|
||||||
|
|
||||||
|
if (point.time >= startTime && point.time <= endTime) {
|
||||||
const { lat, lon } = point;
|
const { lat, lon } = point;
|
||||||
|
// Strictest possible check for valid, finite, numeric coordinates
|
||||||
if (typeof lat === 'number' && typeof lon === 'number' && isFinite(lat) && isFinite(lon)) {
|
if (typeof lat === 'number' && typeof lon === 'number' && isFinite(lat) && isFinite(lon)) {
|
||||||
result.push([lat, lon]);
|
result.push([lat, lon]);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user