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() {
|
updateSize: function() {
|
||||||
// the div might have moved on the page, also
|
// the div might have moved on the page, also
|
||||||
this.events.clearMouseCache();
|
|
||||||
var newSize = this.getCurrentSize();
|
var newSize = this.getCurrentSize();
|
||||||
var oldSize = this.getSize();
|
if (newSize && !isNaN(newSize.h) && !isNaN(newSize.w)) {
|
||||||
if (oldSize == null) {
|
this.events.clearMouseCache();
|
||||||
this.size = oldSize = newSize;
|
var oldSize = this.getSize();
|
||||||
}
|
if (oldSize == null) {
|
||||||
if (!newSize.equals(oldSize)) {
|
this.size = oldSize = newSize;
|
||||||
|
|
||||||
// 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.equals(oldSize)) {
|
||||||
var center = this.getCenter();
|
|
||||||
|
// store the new size
|
||||||
if (this.baseLayer != null && center != null) {
|
this.size = newSize;
|
||||||
var zoom = this.getZoom();
|
|
||||||
this.zoom = null;
|
//notify layers of mapresize
|
||||||
this.setCenter(center, zoom);
|
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();
|
map.updateSize();
|
||||||
t.eq(moveToCnt, 1, "updateSize move the map if it has a center");
|
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>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="map" style="width: 600px; height: 300px;"/>
|
<div id="map" style="width: 600px; height: 300px;"/>
|
||||||
|
<div style="display: none;"><div id="invisimap"></div></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user