Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript "unspecified error" in Open Layers

I am getting this error alt text http://img239.imageshack.us/img239/6936/jserror.png when the map loads.

The error is in the original, unmodified OpenLayers.js file on this line:

return!!(document.namespaces);

I have tried rewriting it to:

return (typeof(document.namespaces) != 'undefined');

and it worked but then I get same "unspecified" errors on further referrals to document.namespaces:

if(!document.namespaces.olv){document.namespaces.add("olv",this.xmlns); ...

I tried rewriting this to:

if(typeof(document.namespaces.olv) == 'undefined') { ...

but I get the same "unspecified error".

I only get this error on Internet Explorer (I tested on 7) and not in Firefox.

Any clues?

Thanks.

like image 415
Alin Avatar asked Jul 04 '09 08:07

Alin


2 Answers

The real problem is that document.namespaces is not ready in IE8 sometimes when triggering $(document).ready (because of VML)

You can use instead :

jQuery(window).load(function() {} ...);
like image 126
christophenoel Avatar answered Sep 21 '22 08:09

christophenoel


I have found the solution.

The problem was that I was creating the map when the DOM was ready with Jquery:

$(document).ready(function(){  ... //create map here [WRONG]

All you have to do is to create the map after the onload event:

window.onload = function() { ... // create map here [CORRECT]
like image 29
Alin Avatar answered Sep 19 '22 08:09

Alin