Source Code for JavaScript Mapping Tools: util.js

Source code of a graphical tool for drawing and computing distances over Google maps.

Run Tool | index.html | main.css | formatters.js | geoCircle.js | geoCode.js | geo.js | index.js | mapControls.js | tableManager.js | util.js | wayPoint.js | wayPointsManager.js


// Copyright 2006-2008 (c) Paul Demers  <paul@acscdg.com>

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA., or visit one 
// of the links here:
//  http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//  http://www.acscdg.com/LICENSE.txt

//////////////////////////////////////////////////////////////////

//
// Utility functions for resizing windows.

// Web site with this code running: http://www.acscdg.com/

//
//// External dependencies:
// _fullyLoaded, _mapElement, _map from index.js.

//
//// Utility method for browser compatibility.
function WindowSize(width, height)
{
  this.width = width;
  this.height = height;
}

function getWindowSize()
{
  var width, height;
  if (self.innerHeight) // all except Explorer
  {
    width = self.innerWidth;
    height = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  {
    width = document.documentElement.clientWidth;
    height = document.documentElement.clientHeight;  // Explorer 6 Strict Mode
  }
  else if (document.body) // other Explorers
  {
    width = document.body.clientWidth;
    height = document.body.clientHeight;
  }

  return new WindowSize(width, height);
}
////
//


//
//// Spacer constants:
var mapWidthOffset = 680;  // go live value 680
var mapHeightOffset = 190; // go live value 190
var mapWidthInnerOffset = 10; // go live value 10
////
//

//
//// Called when the browser is resized.
function resizeBody()
{
  if (!_fullyLoaded)
    return;

  // Grab the center before resizing.  It will be restored later.
  var mapCenter = _map.getCenter();

  // This is needed on IE6, or else sometimes the map is blank until it is resized by hand.
  if (mapCenter == null)
    return;

  var wSize = getWindowSize();
  var wWidth = wSize.width;
  var wHeight = wSize.height;

//GLog.write(_innerElement.offsetWidth + " " + _tableElement.offsetWidth + " " + _innerElement.offsetHeight);

  var mWidth = _innerElement.offsetWidth - _tableElement.offsetWidth - mapWidthInnerOffset;  
  if (mWidth < 0)
    mWidth = wWidth - mapWidthOffset;  // The first time through in IE, the widths are the same.

  _mapElement.style.width = mWidth + "px";

  var mHeight = wHeight - mapHeightOffset;
  _mapElement.style.height = mHeight + "px";

//GLog.write(mWidth + " " + mHeight);

  _map.checkResize();

  _map.setCenter(mapCenter);

}