From ea4e7854098d5d2ee3e23791a9be912065f42951 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Mon, 22 May 2006 13:28:37 +0000 Subject: [PATCH] Huge performance win in caching this. Need to document updateSize, and probably set a 'resize' handler for the document or something like that to call it automatically. Note that GMaps v1 didn't have this concept: If you resized the map, you were stuck with it. GMapsv2 exposes a function to do this, so we're in line with that expectation. Profile difference: Before, 291 calls took 3 seconds. Now, 649 calls takes 3.49 milliseconds. Total Time: 2859.72 (min/max/avg 0.12/35.62/9.83) vs. Total Time: 3.49 (min/max/avg 0/1.53/0.01) git-svn-id: http://svn.openlayers.org/trunk/openlayers@260 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index da4dcd9670..e894727d48 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -96,6 +96,8 @@ OpenLayers.Map.prototype = { this.popups = new Array(); + this.updateSize(); + // always call map.destroy() Event.observe(window, 'unload', this.destroy.bindAsEventListener(this)); @@ -198,18 +200,19 @@ OpenLayers.Map.prototype = { * @returns {OpenLayers.Size} */ getSize: function () { - // should this be cached? - var size = new OpenLayers.Size( + return this.size; + }, + + updateSize: function() { + this.size = new OpenLayers.Size( this.div.clientWidth, this.div.clientHeight); // Workaround for the fact that hidden elements return 0 for size. - if (size.w == 0 && size.h == 0) { - size.w = parseInt(this.div.style.width); - size.h = parseInt(this.div.style.height); + if (this.size.w == 0 && this.size.h == 0) { + this.size.w = parseInt(this.div.style.width); + this.size.h = parseInt(this.div.style.height); } - return size; }, - /** * @return {OpenLayers.LonLat} */