[OpenLayers-Users] Firefox help needed for google sphericalMercator <OpenLayers.Bounds is not a constructor>

Linda_Rawson linda.rawson at gmail.com
Thu Jan 10 15:49:23 EST 2008


I found the solution.  It seems there is a slight difference in the DOM
between the two browsers.

function loadScript(path, notCtx) {
  var url = urlPath(path, notCtx);
  // Internet Explorer
  if (navigator.appName.indexOf("Microsoft") == 0) {
	  document.write ('<' + 'script src="' + url + '"'+'
type="text/javascript"><' + '/script>');
  } else {
	var element = document.createElement('script');
    // set the 'src' attribute of the element
    element.setAttribute('src', url);
    element.setAttribute('type', 'text/javascript');
    // insert the new node into the current document
    document.getElementsByTagName("head")[0].appendChild(element);  
  }
}

function init() {
  // Internet Explorer
  if (navigator.appName.indexOf("Microsoft") == 0) {

  var sloc = "";
  var SCRIPT_NAME = "googleKey.js";
  var scripts = document.getElementsByTagName('script');
  for (var i = 0; i < scripts.length; i++) {
    var src = scripts[i].getAttribute('src');
    if (src) {
      var index = src.lastIndexOf(SCRIPT_NAME); 
      // is it found, at the end of the URL?
      if ((index > -1) && (index + SCRIPT_NAME.length == src.length)) {  
        sloc = src.slice(0, -SCRIPT_NAME.length);
        break;
      }
    }
  }
  ____path = sloc;
  }

  loadScript(GOOGLE_TILES_SERVER + GOOGLE_TILES_KEY, true);
}

Linda


Linda_Rawson wrote:
> 
> Ok.  I need the ability to load the googlekey outside the default page.
> 
> So in sphericalMercator.html it is loaded this way:
> 
>     <script
> src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
> 
> I created this file called google.js which is the following:
> 
> ////////////////////
> var
> GOOGLE_TILES_KEY="ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ";
> var GOOGLE_TILES_SERVER="http://maps.google.com/maps?file=api&v=2&key=";
> var ____path = "";
> function urlPath(path, notCtx) {
>     var incCtx = notCtx || false;
>     var url = (!incCtx ? ____path : "") + path;
>     return url;
> }
> function loadScript(path, notCtx) {
>   var url = urlPath(path, notCtx);
>   document.write ('<' + 'script src="' + url + '"'+'
> type="text/javascript"><' + '/script>');
> }
> function init() {
>   var sloc = "";
>   var SCRIPT_NAME = "googleKey.js";
>   var scripts = document.getElementsByTagName('script');
>   for (var i = 0; i < scripts.length; i++) {
>     var src = scripts[i].getAttribute('src');
>     if (src) {
>       var index = src.lastIndexOf(SCRIPT_NAME);
>       // is it found, at the end of the URL?
>       if ((index > -1) && (index + SCRIPT_NAME.length == src.length)) {
>         sloc = src.slice(0, -SCRIPT_NAME.length);
>         break;
>       }
>     }
>   }
>   ____path = sloc;
>   loadScript(GOOGLE_TILES_SERVER + GOOGLE_TILES_KEY, true);
> }
> init();
> 
> ////////////////////
> 
> This works fine in internet explorer but in firefox I get:
> 
> OpenLayers.Bounds is not a constructor
> 
> Any ideas?
> -- 
> Linda Rawson
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
> 
> 

-- 
View this message in context: http://www.nabble.com/Firefox-help-needed-for-google-sphericalMercator-%3COpenLayers.Bounds-is-not-a-constructor%3E-tp14724839p14743368.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.




More information about the Users mailing list