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
This commit is contained in:
crschmidt
2006-05-22 13:28:37 +00:00
parent f5b1cc270c
commit ea4e785409

View File

@@ -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}
*/