-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Zoom in AOI when analysis is run (#906)
**Related Ticket:** #857 ### Description of Changes Zoom aoi when analysis gets run (note that this PR only handles AOI, not TOI) ### Notes & Questions About Changes Mapbox has fitBonds problem with some projections: mapbox/mapbox-gl-js#12565 Because of this issue, we have to do manual centering which might not look very smooth.
- Loading branch information
Showing
8 changed files
with
140 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useCallback } from 'react'; | ||
import { useAtom } from 'jotai'; | ||
import { select, ZoomBehavior } from 'd3'; | ||
import { onTOIZoomAtom } from '../atoms/timeline'; | ||
import { applyTransform } from '$components/exploration/components/timeline/timeline-utils'; | ||
|
||
export function useOnTOIZoom() { | ||
const [onTOIZoom, setOnTOIZoom] = useAtom(onTOIZoomAtom); | ||
|
||
const initialize = useCallback((zoomBehavior: ZoomBehavior<Element, unknown>, interactionRef: React.RefObject<HTMLElement>) => { | ||
setOnTOIZoom(() => (newX: number, newK: number) => { | ||
if (!newX || !newK) return; | ||
const { current: interactionElement } = interactionRef; | ||
if (!interactionElement) return; | ||
|
||
applyTransform( | ||
zoomBehavior, | ||
select(interactionElement), | ||
newX, | ||
0, | ||
newK | ||
); | ||
}); | ||
}, [setOnTOIZoom]); | ||
|
||
const safeOnTOIZoom = (newX: number, newK: number) => { | ||
if (onTOIZoom) { | ||
onTOIZoom(newX, newK); | ||
} | ||
}; | ||
|
||
return { initializeTOIZoom: initialize, onTOIZoom: safeOnTOIZoom }; | ||
} |