hack to catch as best as possible the resize event in both mozilla and IE. we cant catch the actual resize on the div in IE, so we do that. in mozilla the best we can do is catch the resize of the window. so that is what we do.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@860 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -132,9 +132,20 @@ OpenLayers.Map.prototype = {
|
||||
this.events = new OpenLayers.Events(this, div, this.EVENT_TYPES);
|
||||
|
||||
this.updateSize();
|
||||
|
||||
// update the internal size register whenever the div is resized
|
||||
this.events.register("resize", this, this.updateSize);
|
||||
|
||||
// Because Mozilla does not support the "resize" event for elements other
|
||||
// than "window", we need to put a hack here.
|
||||
//
|
||||
if (navigator.appName.contains("Microsoft")) {
|
||||
// If IE, register the resize on the div
|
||||
this.events.register("resize", this, this.updateSize);
|
||||
} else {
|
||||
// Else updateSize on catching the window's resize
|
||||
// Note that this is ok, as updateSize() does nothing if the
|
||||
// map's size has not actually changed.
|
||||
Event.observe(window, 'resize',
|
||||
this.updateSize.bindAsEventListener(this));
|
||||
}
|
||||
|
||||
//set the default options
|
||||
this.setOptions(options);
|
||||
@@ -349,22 +360,41 @@ OpenLayers.Map.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* This function should be called by any external code which dynamically
|
||||
* changes the size of the map div (because mozilla wont let us catch the
|
||||
* "onresize" for an element)
|
||||
*/
|
||||
updateSize: function() {
|
||||
this.size = new OpenLayers.Size(
|
||||
this.div.clientWidth, this.div.clientHeight);
|
||||
this.events.div.offsets = null;
|
||||
var newSize = this.getCurrentSize();
|
||||
|
||||
if (!newSize.equals(this.getSize())) {
|
||||
this.events.div.offsets = null;
|
||||
this.size = newSize;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @returns A new OpenLayers.Size object with the dimensions of the map div
|
||||
* @type OpenLayers.Size
|
||||
*/
|
||||
getCurrentSize: function() {
|
||||
|
||||
var size = new OpenLayers.Size(this.div.clientWidth,
|
||||
this.div.clientHeight);
|
||||
|
||||
// Workaround for the fact that hidden elements return 0 for size.
|
||||
if (this.size.w == 0 && this.size.h == 0) {
|
||||
if (size.w == 0 && size.h == 0) {
|
||||
var dim = Element.getDimensions(this.div);
|
||||
this.size.w = dim.width;
|
||||
this.size.h = dim.height;
|
||||
size.w = dim.width;
|
||||
size.h = dim.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);
|
||||
if (size.w == 0 && size.h == 0) {
|
||||
size.w = parseInt(this.div.style.width);
|
||||
size.h = parseInt(this.div.style.height);
|
||||
}
|
||||
return size;
|
||||
},
|
||||
|
||||
/********************************************************/
|
||||
|
||||
Reference in New Issue
Block a user