Fix the dreaded resize bug so that the map recenters automatically when relatively-sized map divs change size.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@1174 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
|
"http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml" style="width:100%">
|
||||||
<head>
|
<head>
|
||||||
<script src="../lib/OpenLayers.js"></script>
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body style="width:100%">
|
||||||
<div style="width:100%; height:500px" id="map"></div>
|
<div style="width:100%; height:500px" id="map"></div>
|
||||||
<script defer="defer" type="text/javascript">
|
<script defer="defer" type="text/javascript">
|
||||||
var map = new OpenLayers.Map('map');
|
var map = new OpenLayers.Map('map');
|
||||||
|
|||||||
+15
-3
@@ -468,10 +468,22 @@ OpenLayers.Map.prototype = {
|
|||||||
*/
|
*/
|
||||||
updateSize: function() {
|
updateSize: function() {
|
||||||
var newSize = this.getCurrentSize();
|
var newSize = this.getCurrentSize();
|
||||||
|
var oldSize = this.getSize();
|
||||||
if (!newSize.equals(this.getSize())) {
|
if (oldSize == null)
|
||||||
this.events.element.offsets = null;
|
this.size = oldSize = newSize;
|
||||||
|
if (!newSize.equals(oldSize)) {
|
||||||
|
// move the layer container so that the map is still centered
|
||||||
|
var dx = (newSize.w - oldSize.w) / 2,
|
||||||
|
dy = (newSize.h - oldSize.h) / 2;
|
||||||
|
var lcStyle = this.layerContainerDiv.style;
|
||||||
|
lcStyle.left = (parseInt(lcStyle.left) + dx) + "px";
|
||||||
|
lcStyle.top = (parseInt(lcStyle.top ) + dy) + "px";
|
||||||
|
// reset the map center
|
||||||
|
this.layerContainerOrigin = this.center.clone();
|
||||||
|
// store the new size
|
||||||
this.size = newSize;
|
this.size = newSize;
|
||||||
|
// the div might have moved on the page, also
|
||||||
|
this.events.element.offsets = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user