Maintenance Love :)
This commit is contained in:
parent
302f9b4026
commit
8cfeeabb93
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import * as turf from '@turf/turf';
|
||||
import { generateGridSearchCells } from '@polymech/shared';
|
||||
import { generateGridSearchCells, extractGridWaypoints, SimulatorGridCell, GridSearchHop, GridFeature } from '@polymech/shared';
|
||||
import { GridSimulatorSettings, GridSearchSimulatorProps } from '../types';
|
||||
|
||||
function useLocalStorage<T>(key: string, initialValue: T) {
|
||||
@ -36,7 +36,7 @@ export function useGridSimulatorState({
|
||||
setSimulatorScanner
|
||||
}: GridSearchSimulatorProps) {
|
||||
|
||||
const [gridCells, setGridCells] = useState<any[]>([]);
|
||||
const [gridCells, setGridCells] = useState<SimulatorGridCell[]>([]);
|
||||
const [progressIndex, setProgressIndex] = useState(0);
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
const [speed, setSpeed] = useState(0.5);
|
||||
@ -64,12 +64,12 @@ export function useGridSimulatorState({
|
||||
|
||||
const [isCalculating, setIsCalculating] = useState(false);
|
||||
const [calcStats, setCalcStats] = useState({ current: 0, total: 0, valid: 0 });
|
||||
const skippedCellsRef = useRef<any[]>([]);
|
||||
const skippedCellsRef = useRef<SimulatorGridCell[]>([]);
|
||||
|
||||
const stopRequestedRef = useRef<boolean>(false);
|
||||
const reqRef = useRef<number>();
|
||||
const lastTickRef = useRef<number>(0);
|
||||
const globalProcessedHopsRef = useRef<any[]>([]);
|
||||
const globalProcessedHopsRef = useRef<SimulatorGridCell[]>([]);
|
||||
|
||||
const [ghsBounds, setGhsBounds] = useState({ minPop: 0, maxPop: 1000000, minBuilt: 0, maxBuilt: 1000000 });
|
||||
|
||||
@ -105,18 +105,8 @@ export function useGridSimulatorState({
|
||||
}
|
||||
}, [pickerPolygons]);
|
||||
|
||||
const getFinalHopList = () => {
|
||||
return gridCells
|
||||
.filter(c => c.properties.sim_status !== 'skipped')
|
||||
.map((c, i) => {
|
||||
const pt = turf.centroid(c).geometry.coordinates;
|
||||
return {
|
||||
step: i + 1,
|
||||
lng: Number(pt[0].toFixed(6)),
|
||||
lat: Number(pt[1].toFixed(6)),
|
||||
radius_km: c.properties.search_radius_km ? Number(c.properties.search_radius_km.toFixed(2)) : undefined
|
||||
};
|
||||
});
|
||||
const getFinalHopList = (): GridSearchHop[] => {
|
||||
return extractGridWaypoints(gridCells.filter(c => c.properties.sim_status !== 'skipped'));
|
||||
};
|
||||
|
||||
const getCurrentSettings = (): GridSimulatorSettings => ({
|
||||
@ -134,10 +124,10 @@ export function useGridSimulatorState({
|
||||
return;
|
||||
}
|
||||
|
||||
const features: any[] = [];
|
||||
const features: GridFeature[] = [];
|
||||
pickerPolygons.forEach(fc => {
|
||||
if (fc && fc.features) {
|
||||
features.push(...fc.features);
|
||||
features.push(...(fc.features as GridFeature[]));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { GridGeneratorOptions } from '@polymech/shared';
|
||||
import { GridGeneratorOptions, GridFeature, SimulatorGridCell } from '@polymech/shared';
|
||||
import type { FeatureCollection, Polygon, MultiPolygon, Point, LineString, Feature } from 'geojson';
|
||||
|
||||
type SimulatorBaseConfig = Required<Omit<GridGeneratorOptions, 'features' | 'onFilterCell' | 'skipPolygons'>>;
|
||||
|
||||
@ -11,9 +12,9 @@ export interface GridSimulatorSettings extends SimulatorBaseConfig {
|
||||
|
||||
export interface GridSearchSimulatorProps {
|
||||
pickerRegions: any[];
|
||||
pickerPolygons: any[];
|
||||
onFilterCell?: (cell: any) => boolean;
|
||||
setSimulatorData: (data: any) => void;
|
||||
setSimulatorPath: (data: any) => void;
|
||||
setSimulatorScanner: (data: any) => void;
|
||||
pickerPolygons: FeatureCollection<Polygon | MultiPolygon>[];
|
||||
onFilterCell?: (cell: GridFeature | SimulatorGridCell | Feature<any, any>) => boolean;
|
||||
setSimulatorData: (data: FeatureCollection<Polygon | MultiPolygon | Point, any>) => void;
|
||||
setSimulatorPath: (data: FeatureCollection<LineString, any>) => void;
|
||||
setSimulatorScanner: (data: FeatureCollection<Point, any>) => void;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user