Making it so the Map constructor doesn't fail when the provided viewport element isn't displayed. r=ahocevar (closes #2461)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10022 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1326,30 +1326,32 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
*/
|
||||
updateSize: function() {
|
||||
// the div might have moved on the page, also
|
||||
this.events.clearMouseCache();
|
||||
var newSize = this.getCurrentSize();
|
||||
var oldSize = this.getSize();
|
||||
if (oldSize == null) {
|
||||
this.size = oldSize = newSize;
|
||||
}
|
||||
if (!newSize.equals(oldSize)) {
|
||||
|
||||
// store the new size
|
||||
this.size = newSize;
|
||||
|
||||
//notify layers of mapresize
|
||||
for(var i=0, len=this.layers.length; i<len; i++) {
|
||||
this.layers[i].onMapResize();
|
||||
if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) {
|
||||
this.events.clearMouseCache();
|
||||
var oldSize = this.getSize();
|
||||
if (oldSize == null) {
|
||||
this.size = oldSize = newSize;
|
||||
}
|
||||
|
||||
var center = this.getCenter();
|
||||
|
||||
if (this.baseLayer != null && center != null) {
|
||||
var zoom = this.getZoom();
|
||||
this.zoom = null;
|
||||
this.setCenter(center, zoom);
|
||||
if (!newSize.equals(oldSize)) {
|
||||
|
||||
// store the new size
|
||||
this.size = newSize;
|
||||
|
||||
//notify layers of mapresize
|
||||
for(var i=0, len=this.layers.length; i<len; i++) {
|
||||
this.layers[i].onMapResize();
|
||||
}
|
||||
|
||||
var center = this.getCenter();
|
||||
|
||||
if (this.baseLayer != null && center != null) {
|
||||
var zoom = this.getZoom();
|
||||
this.zoom = null;
|
||||
this.setCenter(center, zoom);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -1360,10 +1360,31 @@
|
||||
map.updateSize();
|
||||
t.eq(moveToCnt, 1, "updateSize move the map if it has a center");
|
||||
}
|
||||
|
||||
function test_invisible_map(t) {
|
||||
/**
|
||||
* This test confirms that initializing a map using an element that is
|
||||
* not currently displayed doesn't cause any trouble.
|
||||
*/
|
||||
t.plan(1);
|
||||
|
||||
var map, msg = "initializing a map on an undisplayed element";
|
||||
try {
|
||||
map = new OpenLayers.Map("invisimap");
|
||||
} catch (err) {
|
||||
msg += ": " + err;
|
||||
}
|
||||
t.ok(!!map, msg);
|
||||
|
||||
if (map) {
|
||||
map.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 600px; height: 300px;"/>
|
||||
<div style="display: none;"><div id="invisimap"></div></div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user