feat(viewport-helpers): return promises
This commit is contained in:
@@ -188,27 +188,27 @@ export function XYPanZoom({
|
||||
d3ZoomInstance.on('zoom', null);
|
||||
}
|
||||
|
||||
function setViewportConstrained(
|
||||
async function setViewportConstrained(
|
||||
viewport: Viewport,
|
||||
extent: CoordinateExtent,
|
||||
translateExtent: CoordinateExtent
|
||||
): ZoomTransform | undefined {
|
||||
): Promise<ZoomTransform | undefined> {
|
||||
const nextTransform = viewportToTransform(viewport);
|
||||
const contrainedTransform = d3ZoomInstance?.constrain()(nextTransform, extent, translateExtent);
|
||||
|
||||
if (contrainedTransform) {
|
||||
setTransform(contrainedTransform);
|
||||
await setTransform(contrainedTransform);
|
||||
}
|
||||
|
||||
return contrainedTransform;
|
||||
return new Promise((resolve) => resolve(contrainedTransform));
|
||||
}
|
||||
|
||||
function setViewport(viewport: Viewport, options?: PanZoomTransformOptions) {
|
||||
async function setViewport(viewport: Viewport, options?: PanZoomTransformOptions) {
|
||||
const nextTransform = viewportToTransform(viewport);
|
||||
|
||||
setTransform(nextTransform, options);
|
||||
await setTransform(nextTransform, options);
|
||||
|
||||
return nextTransform;
|
||||
return new Promise<ZoomTransform>((resolve) => resolve(nextTransform));
|
||||
}
|
||||
|
||||
function syncViewport(viewport: Viewport) {
|
||||
|
||||
@@ -21,8 +21,6 @@ export const isWrappedWithClass = (event: any, className: string | undefined) =>
|
||||
export const isRightClickPan = (panOnDrag: boolean | number[], usedButton: number) =>
|
||||
usedButton === 2 && Array.isArray(panOnDrag) && panOnDrag.includes(2);
|
||||
|
||||
export const getD3Transition = (selection: D3SelectionInstance, duration = 0) =>
|
||||
typeof duration === 'number' && duration > 0 ? selection.transition().duration(duration) : selection;
|
||||
export const getD3Transition = (selection: D3SelectionInstance, duration = 0, onEnd = () => {}) =>
|
||||
typeof duration === 'number' && duration > 0 ? selection.transition().duration(duration).on('end', onEnd) : selection;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user