[OpenLayers-Trac] [OpenLayers] #388: window resize messes with mouse position

OpenLayers trac at openlayers.org
Wed Nov 8 10:28:40 EST 2006


#388: window resize messes with mouse position
----------------------+-----------------------------------------------------
  Reporter:  tschaub  |       Owner:             
      Type:  bug      |      Status:  new        
  Priority:  minor    |   Milestone:  2.2 Release
 Component:  general  |     Version:             
Resolution:           |    Keywords:             
----------------------+-----------------------------------------------------
Changes (by euzuro):

  * milestone:  2.3 Release => 2.2 Release

Comment:

 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[]

-- 
Ticket URL: <http://trac.openlayers.org/ticket/388>
OpenLayers <http://openlayers.org/>
A free AJAX map viewer


More information about the Trac mailing list