Hello,

We are currently using Openlayers within our website. Every browser (FF, Chrome, Safari) works fine except IE. We get an javascript error saying:

'data(...).openlayers' is null or not an object'
URI: http://domain.com/sites/all/modules/contrib/openlayers/js/openlayers.js
Rule 137

Rule 137 of openlayers.js:

$.each($('#'+map).data('openlayers').openlayers.getLayersByClass('OpenLayers.Layer.Vector'),

When choosing to display the OSM Mapnik layer, we still get this error but the map is being rendered. When choosing for Google Maps, we get this error but no map is being rendered.

Is this a bug in Openlayers or something else? I've created a test environment on http://hwg.qbixx.nl/node/2. I've enable both the OSM Mapnik and Google Maps layer.

Comments

MikeNGarrett’s picture

Encountering the same issue. I'm using mapbox and the map is rendering fine. It's the points on the map that aren't being rendered.

Edit:

I fixed the javascript errors, but am still have troubles with the points rendering. They are appearing on the map in the right positions, but the olv:oval/olv:fill/olv:stroke elements aren't rendering (at all).

I've added a background image to these elements and it seems to work, but this is a pretty horrid workaround.

This should show you where your elements are:
olv\:oval {
background: #000;
}

combicart’s picture

It seems that the javascript error only appears when an Openlayers map is displayed directly as part of a node. In my example the map only shows the location of the current node and is being displayed as a block. When creating an seperate 'Openlayers Map' page with views where all the nodes are shown, the error disappears.

The Google Maps problem, where the map isn't rendered has something to do with the 'imgPath' setting. See http://trac.osgeo.org/openlayers/ticket/2747 for more information.

flatfeat’s picture

I'm running into this same problem in IE 8. All other browsers appear to be fine. Seems to happen only on node pages, as well. The map on my homepage, which is in a block on a Panels page, does not produce this error.

Here's the full details of the error:

---------------------------------
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0; .NET4.0C; Zune 4.7)
Timestamp: Mon, 24 Jan 2011 01:22:46 UTC

Message: 'data(...).openlayers' is null or not an object
Line: 138
Char: 11
Code: 0
URI: http://www.mysite.com/sites/all/modules/openlayers/js/openlayers.js?Q
----------------------------------

I'm sorry, but this is all the info I can think of to include. If anyone needs any more details, let me know.

zzolo’s picture

Category: bug » support

Hi @combicart and others. Can you confirm that you are using custom image sets (specifically the Mapbox set)?

combicart’s picture

Hi zzolo,

Yes, we are using a custom image set (http://js.mapbox.com/theme/dark/). We partially solved this problem by creating our own image set, which is an exact copy of the dark theme, except for the 'blank.gif' file.

zzolo’s picture

Status: Active » Closed (works as designed)

So this issue is more of a problem of that image set and not this module.

Just to note, we are looking at providing a default set of images (those Mpabox ones) with the module and will have to address that as well.

combicart’s picture

The javascript error is a problem of the module. When opening a page, we still get the error message.
The second problem where the Google Maps map wasn't loading was a problem of the image set. By removing the blank.gif file the map showed up.

zzolo’s picture

Hi @combicart. Again, this should be addressed with that image set. This is not a part of this module.

combicart’s picture

Hi @zzolo,

The image set was only responsible for not displaying the Google Maps map.

The javascript error is still present and is being generated by this module. With and without an image set, I still receive the following javascript error in IE:

'data(...).openlayers' is null or not an object'
URI: http://domain.com/sites/all/modules/contrib/openlayers/js/openlayers.js
... 137

If you want I can give you the live URL where you can see the javascript error.

zzolo’s picture

Status: Closed (works as designed) » Active

Hi @combicart. I see. My misunderstanding.

Yeah, a real URL would be really helpful if its not too much trouble. Thats the part where it's redrawing the vector layers for IE since IE well, just kind of sucks. But, there should be no reason it is finding a map element without map data.

combicart’s picture

Hi @zzolo,

I've send you an DM with the live URL.

rootwork’s picture

subscribe

terbs’s picture

I'm also experiencing this error consistently in IE 7 and IE8 in Compatibility Mode (rolled back to 7)

Getting the same javascript error as the original poster. On first visit, the data layers appear correctly. On refresh the data disappears. The map data reappears when it's dragged or zoomed in/out.

I think it all comes down to the redrawvectors function being constructed improperly or running at the incorrect point in the stack.

Oddly enough, if I include the map twice the redrawvactors works fine. I think it depends how the map is implemented into the page. In my environment, IE breaks when the map is included as a block, but it works if it's included in the page.

Here's the URL for testing: http://savagerace.com/locations/orlando-fl

I'm running 6.x-2.0-alpha10

This is a big blemish on a great module :(
Please let me know any way I can help get this resolved!

jsabbitt’s picture

subscribe

zzolo’s picture

Hi all. I have looked into this some more, but am still not able to replicate it locally.

@aiquandol. I can see the same JS error in FF. Can you provide a list of modules you are using, as you have JS and CSS aggregation on and it is hard to tell what is going on.

terbs’s picture

@zzolo,

So sorry for sending you to that link with JS aggregation! I really appreciate you taking the time to look at this error.

Here's the same page in our dev environment, which has all the caching disabled. This is where the error is occuring.
http://savage.designzillas.com/locations/orlando-fl

Here's the exact same view exposed as a page instead of a block, this does NOT generate the error in IE for me. I think it's an important clue.
http://savage.designzillas.com/mappage

mparker17’s picture

Version: 6.x-2.0-alpha10 » 6.x-2.0-beta1

I can confirm that I also get the error 'data(...).openlayers' is null or not an object in http://example.com/sites/default/modules/openlayers/js/openlayers.js?z on line 137 at character 11 when using openlayers-6.x-2.0-beta1 when the map is rendered as a Page display (OpenLayers Map style) in a View (views-6.x-2.14) running on drupal-6.22.

I still get the error if I enable the Optimize JavaScript files setting in Administer -> Site configuration -> Performance (although it's in a different file and position).

I'll see if I can reproduce the error from a clean Drupal install.

nod_’s picture

Could you try this patch, please: https://drupal.org/node/1364304#comment-5338260

It's for the D7 version but it sould be the same thing. I believe that the issue is because we try to draw the map too early in IE. Did the page where the script failed had a couple of big images ?

And if it still fails, move the Drupal.attachBehaviors(this); inside the $(window).load()

zzolo’s picture

I think what the problem here is that the redrawVectors function is assuming too much.

        for (map in Drupal.settings.openlayers.maps) {
          $.each($('#' + map).data('openlayers')
            .openlayers.getLayersByClass('OpenLayers.Layer.Vector'),
            function(i, layer) {
              layer.redraw();
            }
          );
        }

That says that for all maps, lets redraw all Vector layers. This could be a problem if there are more than one map on the page, as it will redraw on the first map rendering, while the next one has not been rendered yet.

It should be something like:

  'redrawVectors': function(map) {
    $(window).load(
      function() {
        var layers = map.getLayersByClass('OpenLayers.Layer.Vector');
        for (i in layers) {
          layers[i].redraw();
        }
      }
    );
  },

Untested code, and since I dont haven an easy way to test IE, i don't want to commit it just yet.

zzolo’s picture

All that to say, @nod_'s patch looks like a better approach anyway. :)

mparker17’s picture

Looks like there was a bunch of activity on this thread while I was investigating... I haven't tried the patch referenced in #18 (#1364304: Blank Google Map in IE9, but works in FireFox, Chrome etc.) yet.

However, I have managed to get the tiles working on my own by disabling my custom map controls (at Administer -> Site building -> OpenLayers -> Presets -> (your preset) -> General information -> Image Path). Note that, even though the tiles work, I still get the JavaScript error.

Read below for details...

--

I saved just the source of the page experiencing the problem to a file on my IE8 test machine's desktop, and edited it, using find-replace so that all file references pointed to my Drupal install, then loaded my saved file in IE8. Surprisingly, the tiles appeared fine; although my custom map controls were broken images and I still got the JavaScript error.

I looked through the file to try to find the line that set the custom control images. I found it in the array that made up Drupal.settings.openlayers.maps["openlayers-map-auto-id-0"] (key = "image_path", my value = "sites\/default\/files\/site-configuration\/openlayers\/default_dark\/img\/"). It hadn't been caught by my find-replace operation because the slashes in the path were escaped with backslashes.

I corrected it manually, and re-loaded the page. Surprisingly, the tiles disappeared again (although still got the JavaScript error). Curious, I deleted the key-value pair entirely. The tiles reappeared, and the error remained.

Back on the website experiencing the problem, I went to Administer -> Site building -> OpenLayers -> Presets, edited the style being used for my map, cleared the Image Path textbox and clicked Save. I re-loaded the website page, and the tiles show up fine. I still get the error, however.

mparker17’s picture

I had to manually apply the patch referenced in #18 to openlayers-6.x-2.0-beta1 because the modified lines are in different places.

After applying the patch, the Javascript error was eliminated; but:

  • in all browsers, the map is zoomed out to the furthest level
  • in IE7 and IE8, the tiles still disappear if I use custom controls

This suggests to me that the disappearing tiles are unrelated to the Javascript error. Can anyone confirm this?

ken-g’s picture

Issue summary: View changes
Status: Active » Closed (outdated)