OpenLayers OpenLayers

Changeset 1174

Show
Ignore:
Timestamp:
08/09/06 17:17:06 (2 years ago)
Author:
sderle
Message:

Fix the dreaded resize bug so that the map recenters automatically when relatively-sized map divs change size.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/xhtml.html

    r1098 r1174  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    22        "http://www.w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd"> 
    3         <html xmlns="http://www.w3.org/1999/xhtml"> 
    4         <head> 
     3<html xmlns="http://www.w3.org/1999/xhtml" style="width:100%"> 
     4<head> 
    55<script src="../lib/OpenLayers.js"></script> 
    66</head> 
    7 <body
     7<body style="width:100%"
    88  <div style="width:100%; height:500px" id="map"></div> 
    99  <script defer="defer" type="text/javascript"> 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r1173 r1174  
    469469    updateSize: function() { 
    470470        var newSize = this.getCurrentSize(); 
    471          
    472         if (!newSize.equals(this.getSize())) { 
     471        var oldSize = this.getSize(); 
     472        if (oldSize == null) 
     473            this.size = oldSize = newSize; 
     474        if (!newSize.equals(oldSize)) { 
     475            // move the layer container so that the map is still centered 
     476            var dx = (newSize.w - oldSize.w) / 2, 
     477                dy = (newSize.h - oldSize.h) / 2; 
     478            var lcStyle = this.layerContainerDiv.style; 
     479            lcStyle.left = (parseInt(lcStyle.left) + dx) + "px"; 
     480            lcStyle.top  = (parseInt(lcStyle.top ) + dy) + "px"; 
     481            // reset the map center 
     482            this.layerContainerOrigin = this.center.clone(); 
     483            // store the new size 
     484            this.size = newSize; 
     485            // the div might have moved on the page, also 
    473486            this.events.element.offsets = null; 
    474             this.size = newSize; 
    475487        } 
    476488    },