perf(monitor): synchronize map follow frames
This commit is contained in:
@@ -14,6 +14,7 @@ const markerSetMap = vi.fn();
|
|||||||
const markerSetPosition = vi.fn();
|
const markerSetPosition = vi.fn();
|
||||||
const labelSetPosition = vi.fn();
|
const labelSetPosition = vi.fn();
|
||||||
const setZoomAndCenter = vi.fn();
|
const setZoomAndCenter = vi.fn();
|
||||||
|
const setCenter = vi.fn();
|
||||||
const panTo = vi.fn();
|
const panTo = vi.fn();
|
||||||
const mapOff = vi.fn();
|
const mapOff = vi.fn();
|
||||||
const mapDestroy = vi.fn();
|
const mapDestroy = vi.fn();
|
||||||
@@ -45,6 +46,7 @@ class TestMap {
|
|||||||
getZoom = getZoom;
|
getZoom = getZoom;
|
||||||
getBounds = getBounds;
|
getBounds = getBounds;
|
||||||
setZoomAndCenter = setZoomAndCenter;
|
setZoomAndCenter = setZoomAndCenter;
|
||||||
|
setCenter = setCenter;
|
||||||
panTo = panTo;
|
panTo = panTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +233,7 @@ afterEach(() => {
|
|||||||
markerSetPosition.mockReset();
|
markerSetPosition.mockReset();
|
||||||
labelSetPosition.mockReset();
|
labelSetPosition.mockReset();
|
||||||
setZoomAndCenter.mockReset();
|
setZoomAndCenter.mockReset();
|
||||||
|
setCenter.mockReset();
|
||||||
panTo.mockReset();
|
panTo.mockReset();
|
||||||
mapOff.mockReset();
|
mapOff.mockReset();
|
||||||
mapDestroy.mockReset();
|
mapDestroy.mockReset();
|
||||||
@@ -467,7 +470,8 @@ test('renders one selected plate and smoothly follows it until the map is dragge
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
await waitFor(() => expect(markerSetPosition).toHaveBeenLastCalledWith(wgs84ToGcj02(113.27, 23.14)), { timeout: 1_800 });
|
await waitFor(() => expect(markerSetPosition).toHaveBeenLastCalledWith(wgs84ToGcj02(113.27, 23.14)), { timeout: 1_800 });
|
||||||
expect(panTo).toHaveBeenLastCalledWith(wgs84ToGcj02(113.27, 23.14), 10_000);
|
expect(setCenter).toHaveBeenLastCalledWith(wgs84ToGcj02(113.27, 23.14));
|
||||||
|
expect(panTo).not.toHaveBeenCalled();
|
||||||
expect(setZoomAndCenter).toHaveBeenCalledTimes(1);
|
expect(setZoomAndCenter).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
const follow = screen.getByRole('button', { name: '跟随车辆' });
|
const follow = screen.getByRole('button', { name: '跟随车辆' });
|
||||||
|
|||||||
@@ -524,7 +524,10 @@ export function FleetMap({ vehicles, selectedVin, onSelect, monitorMap, onSelect
|
|||||||
const label = labelMarkersRef.current.get(motion.point.id);
|
const label = labelMarkersRef.current.get(motion.point.id);
|
||||||
label?.marker.setPosition?.(motion.point.lnglat);
|
label?.marker.setPosition?.(motion.point.lnglat);
|
||||||
if (label) label.position = motion.point.lnglat;
|
if (label) label.position = motion.point.lnglat;
|
||||||
if (selectedVinRef.current === motion.point.id) selectionRef.current?.setPosition?.(motion.point.lnglat);
|
if (selectedVinRef.current === motion.point.id) {
|
||||||
|
selectionRef.current?.setPosition?.(motion.point.lnglat);
|
||||||
|
if (followSelectedRef.current) mapRef.current?.setCenter?.(motion.point.lnglat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const schedule = () => {
|
const schedule = () => {
|
||||||
@@ -653,8 +656,8 @@ export function FleetMap({ vehicles, selectedVin, onSelect, monitorMap, onSelect
|
|||||||
if (currentZoom < 15) mapRef.current.setZoomAndCenter?.(15, mapPosition);
|
if (currentZoom < 15) mapRef.current.setZoomAndCenter?.(15, mapPosition);
|
||||||
else mapRef.current.panTo?.(mapPosition, MAP_INTERACTION_PAN_DURATION_MS);
|
else mapRef.current.panTo?.(mapPosition, MAP_INTERACTION_PAN_DURATION_MS);
|
||||||
centeredVinRef.current = selectedVin;
|
centeredVinRef.current = selectedVin;
|
||||||
} else if (selectionPositionRef.current && selectionPositionRef.current !== positionKey && followSelectedRef.current) {
|
} else if (selectionPositionRef.current && selectionPositionRef.current !== positionKey && followSelectedRef.current && !movingPointIDsRef.current.has(selectedVin)) {
|
||||||
mapRef.current.panTo?.(mapPosition, pointMoveDurationMs(target.reportIntervalMs));
|
mapRef.current.panTo?.(mapPosition, MAP_INTERACTION_PAN_DURATION_MS);
|
||||||
}
|
}
|
||||||
const previousPositionKey = selectionPositionRef.current;
|
const previousPositionKey = selectionPositionRef.current;
|
||||||
selectionPositionRef.current = positionKey;
|
selectionPositionRef.current = positionKey;
|
||||||
|
|||||||
Reference in New Issue
Block a user