introduce new property on the Map called autoUpdateSize which lets applications take control of window resizing / device orientation changes if they want to

This commit is contained in:
Bart van den Eijnden
2012-08-17 10:13:04 +02:00
parent 2843a18602
commit 3b9ce4ca2d
2 changed files with 73 additions and 20 deletions

View File

@@ -377,6 +377,13 @@ OpenLayers.Map = OpenLayers.Class({
*/
fallThrough: true,
/**
* APIProperty: autoUpdateSize
* {Boolean} Should OpenLayers automatically update the size of the map
* when the resize event is fired. Default is true.
*/
autoUpdateSize: true,
/**
* Property: panTween
* {<OpenLayers.Tween>} Animated panning tween object, see panTo()
@@ -579,6 +586,7 @@ OpenLayers.Map = OpenLayers.Class({
this.events.on(this.eventListeners);
}
if (this.autoUpdateSize === true) {
// Because Mozilla does not support the "resize" event for elements
// other than "window", we need to put a hack here.
if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 9) {
@@ -593,6 +601,7 @@ OpenLayers.Map = OpenLayers.Class({
OpenLayers.Event.observe(window, 'resize',
this.updateSizeDestroy);
}
}
// only append link stylesheet if the theme property is set
if(this.theme) {
@@ -744,12 +753,14 @@ OpenLayers.Map = OpenLayers.Class({
OpenLayers.Event.stopObserving(window, 'unload', this.unloadDestroy);
this.unloadDestroy = null;
if (this.autoUpdateSize === true) {
if (this.updateSizeDestroy) {
OpenLayers.Event.stopObserving(window, 'resize',
this.updateSizeDestroy);
} else {
this.events.unregister("resize", this, this.updateSize);
}
}
this.paddingForPopups = null;

View File

@@ -2090,6 +2090,48 @@
t.ok(center.equals(new OpenLayers.LonLat(-13.25, 56)), "Center is correct and not equal to maxExtent's center");
}
function test_autoUpdateSize(t) {
t.plan(1);
OpenLayers.Event.unloadCache();
var resizeListener = false;
var register = OpenLayers.Events.prototype.register;
OpenLayers.Events.prototype.register = function(name, el , func) {
if (name === 'resize') {
resizeListener = true;
}
};
var map = new OpenLayers.Map({
events: {
register: function(name, el, func) {
if (name === 'resize') {
resizeListener = true;
}
}
},
autoUpdateSize: false,
div: 'map',
layers: [
new OpenLayers.Layer('name', {
isBaseLayer: true,
wrapDateLine: true
})
]
});
map.setCenter(new OpenLayers.LonLat(-1.3, 50.8), 4);
for (var key in OpenLayers.Event.observers) {
var obj = OpenLayers.Event.observers[key];
for (var i=0, ii=obj.length; i<ii; ++i) {
var listener = obj[i];
if (listener.name === 'resize' && listener.element === window) {
resizeListener = true;
}
}
}
t.eq(resizeListener, map.autoUpdateSize, "resize listener not registered when autoUpdateSize is false");
map.destroy();
OpenLayers.Events.prototype.register = register;
}
</script>
</head>
<body>