Skip to content

Commit

Permalink
feat(blocks): support custom max zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Sep 12, 2024
1 parent 1cdd883 commit d84800a
Showing 1 changed file with 19 additions and 21 deletions.
40 changes: 19 additions & 21 deletions packages/blocks/src/root-block/edgeless/edgeless-root-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ export class EdgelessRootService extends RootService implements SurfaceContext {

getFitToScreenData(
padding: [number, number, number, number] = [0, 0, 0, 0],
inputBounds?: Bound[]
inputBounds?: Bound[],
maxZoom = ZOOM_INITIAL
) {
let bounds = [];
if (inputBounds && inputBounds.length) {
Expand All @@ -406,27 +407,24 @@ export class EdgelessRootService extends RootService implements SurfaceContext {
}

const [pt, pr, pb, pl] = padding;
const { viewport } = this;
let { centerX, centerY, zoom } = viewport;

if (bounds.length) {
const { width, height } = viewport;
const bound = getCommonBound(bounds);
if (bound) {
zoom = Math.min(
(width - FIT_TO_SCREEN_PADDING - (pr + pl)) / bound.w,
(height - FIT_TO_SCREEN_PADDING - (pt + pb)) / bound.h
);
zoom = clamp(zoom, ZOOM_MIN, ZOOM_INITIAL);

centerX = bound.x + (bound.w + pr / zoom) / 2 - pl / zoom / 2;
centerY = bound.y + (bound.h + pb / zoom) / 2 - pt / zoom / 2;
} else {
zoom = ZOOM_INITIAL;
}
} else {
zoom = ZOOM_INITIAL;
const bound = getCommonBound(bounds);
let { centerX, centerY, zoom } = this.viewport;

if (!bound) {
return { zoom, centerX, centerY };
}

const { width, height } = this.viewport;

zoom = Math.min(
(width - FIT_TO_SCREEN_PADDING - (pr + pl)) / bound.w,
(height - FIT_TO_SCREEN_PADDING - (pt + pb)) / bound.h
);
zoom = clamp(zoom, ZOOM_MIN, Math.min(maxZoom, ZOOM_MAX));

centerX = bound.x + (bound.w + pr / zoom) / 2 - pl / zoom / 2;
centerY = bound.y + (bound.h + pb / zoom) / 2 - pt / zoom / 2;

return { zoom, centerX, centerY };
}

Expand Down

0 comments on commit d84800a

Please sign in to comment.