annotorious / annotorious-v1

Project has moved to http://github.com/annotorious/annotorious
https://annotorious.com
MIT License
592 stars 142 forks source link

OpenLayers: handle resizing of the map DIV correctly #70

Open rsimon opened 11 years ago

rsimon commented 11 years ago

Via @klokantech: "[...] while testing I have realised Annotorious is not able to handle resize of the DIV with the map - which is quite bad for our fullscreen layouts."

Root cause is that the HTML element needs to be told the absolute width and height in pixels. A "percentage" width/height is not supported by design. I'll address this in two parts:

The second part is likely not part of release 0.7!

rsimon commented 11 years ago

Note: for OpenLayers, the best strategy would be to change the way the Canvas is added to the map: Annotorious should not create another wrapping DIV, but attach the canvas directly to the original map DIV.

rsimon commented 11 years ago

As reported by @gergely-ujvari, the same issue applies to normal images that are resized dynamically. It should be possible though to attach a Window resize listener, and recalculate image pixel width on resize. Only needs a good test case & example page.

dwhly commented 11 years ago

Rainer, this may be a good example page too: http://ajw.asahi.com/article/0311disaster/fukushima/AJ201311030016

If I create an annotation when the image is small, like so: http://image3.dokku.hypothes.is/a/LqyVp8eRTPe4qK9tQtFxZg

And then click the "expand" icon at the upper right of image, then the selector does not refer correctly to the same part of the image.

I'm using the image annotator available via the bookmarklet at the bottom of our test server here: http://image3.dokku.hypothes.is/

rsimon commented 11 years ago

Hi Dan,

wow - that's a pretty tricky example & I'm surprised this works this well at all. I couldn't figure out what exactly happens on that page (lack of time). But apparently, clicking the "expand" button "transplants" the image DOM element from one DIV into another.

But it seems to pick up the surrounding Annotorious wrapper correctly, so the main issue is indeed the image resizing. Some thoughts:

rsimon commented 11 years ago

Note: changes to the DOM can be monitored (on most browsers?) it seems! See:

http://www.quirksmode.org/js/events/DOMtree.html http://davidwalsh.name/dom-events-javascript

I.e. a possible fix could therefore be to attach a DOM Tree Event listener, and reset Annotorious whenever the DOM is modified - or, ideally, only the subtree(s) containing the annotated image(s) - if it is possible to determine this.

rsimon commented 11 years ago

Continuing the discussion in Issue #86, since it is actually becoming quite distinct from the original scope of the original (OpenLayers-related) issue.

rsimon commented 11 years ago

Last commit fixes this issue to the extent required for Release 0.7!