From be6ecf5dca8f70dcf098df6e407bdb9b94efb6be Mon Sep 17 00:00:00 2001 From: crschmidt Date: Mon, 22 May 2006 18:11:45 +0000 Subject: [PATCH] Store div offsets in event div object, caching them until a updateSize call. This provides a significant performance gain in places where the div contains hundreds or thousands of markers, because as the div element gets bigger, determining its size through Prototype.element.page() becomes slower by a factor of up to 4 (determined through profiling with venkman). git-svn-id: http://svn.openlayers.org/trunk/openlayers@271 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 8 +++++--- lib/OpenLayers/Map.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index de83e342e8..eefa2fbc02 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -72,10 +72,12 @@ OpenLayers.Events.prototype = { * @return {OpenLayers.Pixel} */ getMousePosition: function (evt) { - var offsets = Position.page(this.div); + if (!this.div.offsets) { + this.div.offsets = Position.page(this.div); + } return new OpenLayers.Pixel( - evt.clientX - offsets[0], - evt.clientY - offsets[1]); + evt.clientX - this.div.offsets[0], + evt.clientY - this.div.offsets[1]); }, /** diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 920816d8bc..fafe73eb93 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -207,7 +207,7 @@ OpenLayers.Map.prototype = { updateSize: function() { this.size = new OpenLayers.Size( this.div.clientWidth, this.div.clientHeight); - + this.events.div.offsets = null; // Workaround for the fact that hidden elements return 0 for size. if (this.size.w == 0 && this.size.h == 0) { this.size.w = parseInt(this.div.style.width);