Comments (9)
I wrote this function in RubberbandPolygon.js , which does already most of the job.
delLastPoint = () => { this.points.pop(); }
However, I am not sure, where to put best an eventlistener. I tryed to implement a keypress-event in RubberbandPolygonTool.js, yet this is triggered multiple times after pressing one time.
For now, I implemented an KeyListener in the ClickEvent:
onMouseUp = evt => { if (evt.ctrlKey) { this.rubberband.delLastPoint(); } else{ if (this.rubberband.isCollapsed) { this.emit('cancel', evt); this.stop(); } else { const { x , y } = this._toSVG(evt.layerX, evt.layerY); this.rubberband.addPoint([ x, y ]); } } }
But I am not happy with this solution. What do you think about it?
from annotorious-openseadragon.
To prevent ending up without any points, it might be a good idea to add this line:
delLastPoint = () => { if (this.points.length>2){ this.points.pop(); } }
from annotorious-openseadragon.
If you're looking at the OpenSeadragon plugin specifically, you could attach it to the same place where the Shift key is handled:
And maybe listen to a CTRL+Z to trigger .delLastPoint()
?
from annotorious-openseadragon.
works fine there!
I added:
if (evt.keyCode == 90 && evt.ctrlKey) {
if (this.tools.getToolName()==="polygon"){
this.tools.current.rubberband.delLastPoint();
}
};
in OSDAnnotationLayer's KeydownEvent
and to the DrawingToll:
getToolName(){
if (this._current===null){
return ""
}
else if (this._current instanceof RubberbandPolygonTool) {
return "polygon"
}
else if (this._current instanceof RubberbandRectTool) {
return "rect"
}
else{return "error"}
}
because I did not know how to check, which tool is active (you don't need this for boundingboxes)
do you want me to make an official pull request?
from annotorious-openseadragon.
Great. Yes, I think this would make a nice pull request! Can I make three small suggestions:
-
To keep things generic, what do you think about renaming the method from
delLastPoint
to, simply,undo
? That way, different tools in the future could handle CTRL+Z in different ways. -
What's "below" in the hierarchy from the
_current
tool shouldn't matter, or be visible to the annotation layer. Therefore, I would add anundo
method to the tool, even if it doesn't do anything else then delegate to the (inner)rubberband
instance. -
Instead of the tool sniffing workaround, you can simply do the following. (Assuming you already added the
undo
method to the tool.)
if (evt.keyCode == 90 && evt.ctrlKey) {
this.tools.current?.undo && this.tools.current.undo();
}
In this case, the code will first check whether this a current
drawing tool and whether it has an undo
method. And then, only if that's true, it will execute undo()
.
from annotorious-openseadragon.
I rewrote everything, however, there is still a problem, which I just now recognized. The tool is working, yet there are still several errors, telling, that rubberband is undefined...
from annotorious-openseadragon.
Can you post a code sample of what you have? You definitely should avoid accessing rubberband (as it's internal to the tool, so the outside shouldn't need to be aware of it). That's why I think an undo
method at the level of the tool would be a safer abstraction.
from annotorious-openseadragon.
In OSDAnnotationLayer:
document.addEventListener('keydown', evt => {
if (evt.keyCode == 90 && evt.ctrlKey) {
this.tools.undo();
}
this triggers an undo-function in DrawingTools:
undo = () =>{
//console.log(this);
this._current.undo();
}
from here, we come to rubberbandpolygontool:
undo = () =>{
console.log("this: ",this);
console.log("rubberband: ",this.rubberband);
this.rubberband.undo();
}
or to rubberbandrectool:
undo(){}
the funtion in rubberbandpolygontool triggers:
undo = () => {
if (this.points.length>2){
this.points.pop();
}
}
deleting one point without the rubberband is not possible as far as I understood, isn't it?
I could add a simple test, is rubberband is not null. Should already clear the errors. Anyhows. I find it a bit strange, that a keypress-event is triggered several times. Do you have an idea why?
Sincerely,
Erik
from annotorious-openseadragon.
Hm, this looks ok overall. I'd leave the undo()
method out of DrawingTools
and, in OSDAnnotationLayer
call this.tools.current.undo()
directly instead. But that's just a matter of taste. Do you have the code available in a public fork, so I could try this out myself?
Another thing: the RubberbandPolygon is only active while you are drawing. As soon as you close the shape, the RubberbandPolygon will be destroyed. Or, in other words, CTRL+Z will no longer work as soon as the editor popup has opened. Perhaps this is what's happening here?
from annotorious-openseadragon.
Related Issues (20)
- Autosave annotations when widget closes HOT 1
- Modify the size of the annotations edit points when zoomed out HOT 1
- Accessing annotation state in headless mode HOT 8
- setAnnotations throws an error HOT 2
- Disable hotkey altogether HOT 1
- annotorious-OSD in vue 3 HOT 1
- Set the viewport position and zoom HOT 2
- Annotorious selection box and OSD rotation HOT 1
- The AnnotationLayer class is console logging
- Is it possible to add a constraint when resizing annotations outside the image? HOT 1
- Adding two separate distinct svg Annotations HOT 1
- When can the editor support customization?
- How does the annotorious toolbar plugin detect button switching events?
- When the gigapixelMode property is enabled in annotorious-openseadragon, there is an error when drawing lines, I don't know what is the reason
- Using widgets? HOT 1
- How to customize more drawing tools?
- How to openseadragon annotorious - openseadragon, fabricjs combination used? HOT 2
- How do I convert annotations coordinates to openseadragon image coordinates HOT 1
- How do I convert Annotorious coordinates to openseadragon image coordinates。 can you help me ? HOT 2
- Hello, can the editor support custom?Hope to get your answer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from annotorious-openseadragon.