informatics-isi-edu / openseadragon-viewer

2D viewer with openseadragon
Apache License 2.0
5 stars 2 forks source link

Drawing tools #53

Closed rastogi-bhavya closed 3 years ago

rastogi-bhavya commented 3 years ago

De-Selecting tool

I have also added the feature to de-select an annotation tool.

Line Drawing

The line drawing part was similar to the other annotation tools, so I did not had to create any new flow for adding, saving and editing a line.

Polygon Drawing

Since a polygon has multiple edge, the user needs to drag the mouse pointer again to add a new edge. The new vertex will be added between the first and last vertices of the polygon, thus creating the new edge.

Mouse trackers are used to draw the SVG. They are added at the start of drawing and removed at the end of the drawing event.

To add a polygon I had to make changes to the how the drawing works

Old Code

  1. When the user ends drawing (stops dragging the mouse pointer and let go's of the mouse), i.e. onMouseDragToDrawEnd was which deleted the mouse tracker -> saved the SVG -> added new mouse tracker for the same type of annotation tool
  2. When the drawing stopped, all the mouse trackers were removed

New Code

  1. When the user ends drawing, i first check if he was drawing a polygon or not. If he was not then we use the above mentioned flow. If he was drawing a polygon then I add this point to the set of polygon points _currentDrawingEvent.
  2. When the drawing is stopped, before removing all the mouse trackers I check if '_currentDrawingEvent' is not null, i.e. I am checking if I need to save a polygon or not. If it is not null then I save the polygon SVG and remove its tracker. I dont have to add a new tracker for polygon because the stop drawing event is only called when a different annotation tool is selected or the polygon tool is de-selected.

Synchronization Problem

The drawingStop & updateMode are called in the same function (onClickChangeBtn) in annotation-tool.js. Both of these events work with tracker, i.e. drawingStop deletes them adn updateMode add them, given the right parameters. This caused the mouse tracker for a new annotation to be deleted by the previous drawingStop event.

Current Solution

Added a set timeout for updateMode, this prevent the above problem. But this also creates a new problem i.e., the user cannot start drawing a new object before the timeout duration, as the new tracker has not been added.

Other Issue

issue: #52

rastogi-bhavya commented 3 years ago

New Approach

(changes to master branch) Add a check in onMouseDragToDrawEnd to see for which shape has this function been called. If it is Polygon then call insertPointAtDrawEnd, else follow the normal procedure. The logic behind this approach is that, we are saving every SVG object on drawEnd. We just need to make sure that when drawing a polygon we don't remove the mouse tracker that polygon until the user either de-selects the polygon or switches to a different tool.