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
This commit is contained in:
@@ -72,10 +72,12 @@ OpenLayers.Events.prototype = {
|
|||||||
* @return {OpenLayers.Pixel}
|
* @return {OpenLayers.Pixel}
|
||||||
*/
|
*/
|
||||||
getMousePosition: function (evt) {
|
getMousePosition: function (evt) {
|
||||||
var offsets = Position.page(this.div);
|
if (!this.div.offsets) {
|
||||||
|
this.div.offsets = Position.page(this.div);
|
||||||
|
}
|
||||||
return new OpenLayers.Pixel(
|
return new OpenLayers.Pixel(
|
||||||
evt.clientX - offsets[0],
|
evt.clientX - this.div.offsets[0],
|
||||||
evt.clientY - offsets[1]);
|
evt.clientY - this.div.offsets[1]);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ OpenLayers.Map.prototype = {
|
|||||||
updateSize: function() {
|
updateSize: function() {
|
||||||
this.size = new OpenLayers.Size(
|
this.size = new OpenLayers.Size(
|
||||||
this.div.clientWidth, this.div.clientHeight);
|
this.div.clientWidth, this.div.clientHeight);
|
||||||
|
this.events.div.offsets = null;
|
||||||
// Workaround for the fact that hidden elements return 0 for size.
|
// Workaround for the fact that hidden elements return 0 for size.
|
||||||
if (this.size.w == 0 && this.size.h == 0) {
|
if (this.size.w == 0 && this.size.h == 0) {
|
||||||
this.size.w = parseInt(this.div.style.width);
|
this.size.w = parseInt(this.div.style.width);
|
||||||
|
|||||||
Reference in New Issue
Block a user