altert / OpenseadragonFabricjsOverlay

fabricjs canvas overlay for openseadragon
BSD 3-Clause "New" or "Revised" License
70 stars 64 forks source link

Fabric overlay not scaling with Openseadragon image #64

Open miordache93 opened 3 weeks ago

miordache93 commented 3 weeks ago

Hello,

I've been trying to use this plugin into my app, for adding some markups on top of the Openseadragon canvas. Given the fact i couldn't managed to position them right using top, left properties I started thinking that the fabric overlay isn't actually well positioned and neither scaled. Therefore i started with a simple example rendering a rectangular.

I've some parts of my code for example purpose. Any advice?

` const api = new OpenSeadragon.Viewer({ ...options, loadTilesWithAjax: true, tileSources: { ...(options.tileSources as OpenSeadragon.TileSourceOptions), ...getCustomTileSources(viewerData), getTileUrl: getTileUrl( { ...data, study: { ...data?.study, ...study, slides: study?.shuffledSlides || data?.study?.slides || [], }, } as ImageViewerApi, state.slidePosition ), }, element: refElem.current as unknown as HTMLElement, }) as OpenSeadragonViewer;

const fabricOverlay = api.fabricjsOverlay({ scale: 1000 }) as any;
const fabricCanvas = fabricOverlay.fabricCanvas() as fabric.Canvas;

 const react = new fabric.Rect({
    width: fabricCanvas.getWidth(),
    height: fabricCanvas.getHeight(),
    left: 0,
    top: 0,
    fill: 'red',
  });

  // fabricCanvas.centerObject(react);
  fabricCanvas.add(react);

  fabricCanvas.renderAll();

`

Screenshot 2024-10-31 at 17 05 00 Screenshot 2024-10-31 at 17 05 14 Screenshot 2024-10-31 at 17 05 55
miordache93 commented 3 weeks ago

@altert 🙏 Any ideas?