Ticket #388 (closed bug: fixed)

Opened 7 years ago

Last modified 6 years ago

window resize messes with mouse position

Reported by: tschaub Owned by: sderle
Priority: minor Milestone: 2.4 Release
Component: general Version:
Keywords: Cc:
State:

Description (last modified by crschmidt) (diff)

I think #387 is really a bigger problem with window resizing.

  • Open up openlayers.org (in any browser)
  • Shift drag a box to zoom in on the map
  • Resize your browser window (so map changes position)
  • Shift drag again to see mis-positioned zoom box

I'll put 2.2, but I imagine that's unlikely.

Attachments

388.patch Download (2.7 KB) - added by sderle 6 years ago.
388-2.patch Download (1.5 KB) - added by sderle 6 years ago.
final patch to cause Map and PanZoomBar to reset their page offsets when the move/drag action starts
offset.patch Download (2.2 KB) - added by tschaub 6 years ago.
trash offset cache with every map.updateSize call

Change History

Changed 7 years ago by crschmidt

  • description modified (diff)
  • milestone changed from 2.2 Release to 2.3 Release

This bug is only visible now that we've fixed the other issues related to mouse movement, but this is not a new bug in 2.2, and has in fact existed since I originally started caching the offset data way back when. I'm going to mark this one as 2.3, because it's important, but it's not really related to #387 directly.

Changed 7 years ago by euzuro

  • milestone changed from 2.3 Release to 2.2 Release

im chat:

[16:38:14] cr5chmidt: open http://openlayers.org/ [16:38:17] cr5chmidt: mouse over the map [16:38:20] cr5chmidt: resize the window smaller [16:38:23] cr5chmidt: then zoombox [16:38:58] cr5chmidt: it has to be on a page where the element offsets change as the result of a resize of the page [16:39:00] euzuro: so you know what the problem is? [16:39:02] cr5chmidt: yep [16:39:10] cr5chmidt: element offsets are cahced the first time you mouseover a map [16:39:13] euzuro: ok. [16:39:17] cr5chmidt: the proble mis [16:39:28] cr5chmidt: there are any number of OpenLayers.Events objects [16:39:38] cr5chmidt: not only within OpenLayers [16:39:47] cr5chmidt: but also outside of OpenLayers [16:39:52] cr5chmidt: in applications [16:40:02] cr5chmidt: and we have to reset object.events.offset to null [16:40:40] euzuro: where does it get set originally in the code? [16:40:42] cr5chmidt: The offset of an element in the page? [16:41:05] cr5chmidt:  getMousePosition: function (evt) {

if (!this.element.offsets) {

this.element.offsets = OpenLayers.Util.pagePosition(this.element); this.element.offsets[0] += (document.documentElement.scrollLeft

document.body.scrollLeft);

this.element.offsets[1] += (document.documentElement.scrollTop

document.body.scrollTop);

}

[16:43:55] euzuro: i see. [16:45:25] euzuro: so basically [16:45:31] euzuro: that element.offsets is a cache [16:45:34] euzuro: which is safe [16:45:39] euzuro: ...until the window is resized [16:45:45] euzuro: or the element iself is repositioned [16:45:58] cr5chmidt: Right [16:46:01] euzuro: can we listen for that? [16:46:10] cr5chmidt: Not on the element itself [16:46:12] cr5chmidt: so far as I'm aware [16:46:22] cr5chmidt: and even if we could listen for it on the page [16:46:39] cr5chmidt: we wouldn't know which elements have offsets we need to reset [16:46:46] euzuro: right. [16:46:58] euzuro: some might move, some not. [16:47:55] cr5chmidt: Not caching it is a huge performance hit [16:47:58] cr5chmidt: that's why it is that way to begin with [16:48:01] euzuro: right [16:48:06] cr5chmidt: because it sped up mouse dragging by a factor of 3 [16:48:35] cr5chmidt: I think what we need [16:48:47] cr5chmidt: is a 'resizedCount' variable [16:48:49] cr5chmidt: which starts at 0 [16:48:54] cr5chmidt: and when we do getmouseposition [16:48:59] cr5chmidt: we check if the resizedCount has increased [16:49:01] cr5chmidt: and kill the cache [16:49:19] euzuro: aja [16:49:20] cr5chmidt: or something like that [16:50:20] cr5chmidt: Each object has to know if it has appropriately cleared its cache yet [16:50:23] euzuro: right [16:50:25] euzuro: exactly. [16:50:27] euzuro: so.... [16:50:27] cr5chmidt: so that's why we do the count [16:50:37] cr5chmidt: so we set resizeCount higher on Events class (static) [16:50:45] cr5chmidt: and then each Events instance keeps a count of lastResize[]

Changed 7 years ago by euzuro

  • milestone changed from 2.2 Release to 2.3 Release

Changed 6 years ago by crschmidt

  • owner set to tschaub

Changed 6 years ago by euzuro

  • milestone changed from 2.3 Release to 2.4 Release

Changed 6 years ago by sderle

  • owner changed from tschaub to sderle
  • status changed from new to assigned

crschmidt's verbal comment on this patch was that it didn't solve the issue of when the map div moves in the window without the window resizing. We agreed that there was no way to trap this event in the browser, and that the only thing to do was to require the AJAX developer to call a method to trigger the update on the map if the map moved on the page. As it happens, map.updateSize() already does this. The revised 388.patch augments the docs for this method.

Please review this patch for inclusion.

Changed 6 years ago by sderle

Changed 6 years ago by sderle

After further email from the list, I think it would make sense to recalculate the screen positions on *every* move start. It won't slow down the move start that much, because we only do it once, and it won't slow down the dragging at all. So please hold off on reviewing/committing this patch.

Changed 6 years ago by sderle

final patch to cause Map and PanZoomBar to reset their page offsets when the move/drag action starts

Changed 6 years ago by sderle

  • keywords review added

Changed 6 years ago by tschaub

Dragging a box on a right floated map viewport still demonstrates the problem (open an example with #map {float: right}, shift-drag to zoom in, resize page, shift-drag again to see improperly positioned zoom box.

map.updateSize needs to nullify map.events.element.offsets every time it is called - not only when its size changes.

I think the following patch is what we want.

Changed 6 years ago by tschaub

trash offset cache with every map.updateSize call

Changed 6 years ago by sderle

  • status changed from assigned to closed
  • resolution set to fixed

offset.patch applied as r2915

Changed 6 years ago by euzuro

  • keywords review removed
Note: See TracTickets for help on using tickets.