openlayers / ol2

OpenLayers v2 - deprecated!
Other
1.47k stars 771 forks source link

Map in a position:fixed div misplaces mouse cursor #1389

Open czigor opened 10 years ago

czigor commented 10 years ago

I have a map in a scrollable, position:fixed div. It is possible to place markers on the map. However, occassionally after using the scrollbar of both the div and the browser the marker does not appear under the mouse cursor but shifted the vertically.

To reproduce: download the html in http://pastie.org/9523512. The html page is vertically long so the browser window should have a scrollbar. Additional to this there is a high inner div with a scrollbar. This div has the OL map.

  1. Scroll down a bit with the window scrollbar.
  2. Scroll to the bottom of the OL div to see the map.
  3. Place a marker on the map. It appears OK.
  4. Scroll up a bit in the OL div and try to place a marker again. It is in a lower position than the mouse pointer.

Note that you probably need to rewrite line 33 to add your own marker image.

If the above steps do not reproduce the error try scrolling up and down both the window and the OL div.

The bug appears in Firefox32 and Chrome37.

czigor commented 10 years ago

I suspect that OpenLayers.Events.getMousePosition() does not handle "overflow-y: scroll;" divs properly.

I'm not an expert on lengths, so I am digging further into this. E.g. http://stackoverflow.com/questions/55677/how-do-i-get-the-coordinates-of-a-mouse-click-on-a-canvas-element

czigor commented 10 years ago

Now I think that the problem is that Openlayers.Events.clearMouseCache(); is not called when the scrollable div wrapper (the map div's parent) is scrolled. As a workaround I have bound a 'scroll' event to the scrollable div wrapper and called clearMouseCache(); inside it. It works. I don't know what OpenLayers could do about this though.