Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get correct coordinates for InfiniteViewer? #161

Open
ronny-lark opened this issue Dec 17, 2023 · 0 comments
Open

How to get correct coordinates for InfiniteViewer? #161

ronny-lark opened this issue Dec 17, 2023 · 0 comments

Comments

@ronny-lark
Copy link

Environments

  • Framework name: React
  • Framework version: 18
  • Component name: Selecto + InfiniteViewer
  • Component version: 1.26.3 + 0.28.1

Description

I am trying to "reacreate" the Moveable demo where you draw new moveables using Selecto.
However, I am unable to get the correct Selecto size and position after InviniteViewer is zoomed in.
I have this function being called in onSelectEnd:

const onFinishDrawing = (event: OnSelectEnd) => {
    const { rect } = event;
    const { width: w, height: h, left, top } = rect;
    annotate(image?.id, left, top, w, h);
  };

But it returns incorrect left and top, even when fully zoomed out; they are relative to the screen, even though there is a dragContainer.

      <InfiniteViewer
        ref={viewerRef}
        className='w-full h-full border border-solid'
        displayVerticalScroll={false}
        displayHorizontalScroll={false}
        margin={0}
        threshold={0}
        useMouseDrag={!dragging && !drawing}
        zoomRange={[1, 5]}
        zoom={zoom}
        onPinch={(e) => setZoom(e.zoom)}
      >
        <Box ref={boxRef} className='relative' h={height} w={width} data-testid={testIds.viewport}>
          <Image src={files[fileIndex]?.url} data-testid={testIds.image} />
          {annotations.map((annotation) => (
            <AnnotationBox
              key={annotation.id}
              annotation={annotation}
              zoom={zoom}
              onDragToggle={onDragToggle}
              onUpdateAnnotation={(coords) => reposition(annotation.id, coords)}
            />
          ))}
        </Box>
      </InfiniteViewer>
        <Selecto
          boundContainer
          dragContainer={boxRef.current as HTMLElement | null}
          preventDefault
          onSelectEnd={onFinishDrawing}
        />

bad select example

How can I get the correct measurements, relative to this image? As you can see from my snippet, I have a Box wrapper around the image and I do have the real image width and height.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant