Hello, I notice an issue with openlayers behaviour. Basically in browser console I get the error message: Cannot read property 'map_name' of undefined When I check maps object in console: Drupal.settings.openlayers.maps I get this: Object {openlayers-map: undefined} In map configuration Layers & Styles in OVERLAY LAYERS section I selected my custom layer which is based on view (Layer Type: OpenLayers views) but if I select a different layer in OVERLAY LAYERS section for example "Placeholder for Geofield Formatter" then I can get maps object. I don't know what wrong is but it worked before I updated openlayers module. I need to get to this object because my custom module stop working because of that.

If you need more information or you can't recreate the issue, please let me know.
Thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pol’s picture

Status: Active » Postponed (maintainer needs more info)

Hi,

I'm not able to reproduce the error, could you check with the latest development version ?

Thanks

rafalB’s picture

Hi Pol, thank you for your response, I've just tried with the latest development version and I got the same issue. Now I don't get the message Cannot read property 'map_name' of undefined but I still can't get the maps object in a browser console. Currently all modules which I am using with open layers they are up to date the same Drupal core. I've noticed that I can't get maps object with Drupal.settings.openlayers.maps
settings openlayers map

but when I look at html source in browser I can see javascript code with all those settings. I am assuming that the code might be broken but I might be wrong.
java script settings

I created a feature so you should be able to recreate it. The feature contains content type, view, and openlayers settings.
Please let me know if you need more details.

rafalB’s picture

Status: Postponed (maintainer needs more info) » Active
Pol’s picture

Assigned: Unassigned » Pol

Working on it.

Pol’s picture

I have committed two fix which are probably a part of the solution.

First one: http://drupalcode.org/project/openlayers.git/commit/f49bcd1
Second one: http://drupalcode.org/project/openlayers.git/commit/dcec6c3

The second fix is just a fix of the first one.

Could you test with the 7.x-2.x version and report back ? thanks !

rafalB’s picture

Hi Pol, I've just tested the latest version 7.x-2.x and I still have the same issue, I can't get full maps object, in console I get: opelayers-map: undefined probably by broken javascript but I might be wrong.

Pol’s picture

Status: Active » Closed (cannot reproduce)

I'm sorry, I'm not able to reproduce the problem.

I reverted your feature, so I have cancelled my changes and with OL 7.x-2.x I have not a single error and the map is displayed correctly.

Only local images are allowed.

I'll close it, reopen if needed.

rafalB’s picture

Hi Pol, the map is displayed correctly for me as well, in fact it wasn't a problem, my problem is that I can't get the full javascript object in browser console for maps, basically comment #2 explains everything. Could you tell me what you get if you enter Drupal.settings.openlayers.maps in browser console? Thank you.

rafalB’s picture

Status: Closed (cannot reproduce) » Active
Pol’s picture

Status: Active » Fixed

Indeed, I'm unable to retrieve the JS object using that method.

Nevertheless, you can use:

jQuery("#openlayers-map").data().openlayers.map

To get it, and this is the best method to use to get it.

rafalB’s picture

Thank you Pol for your answer, I am going to use your way to get the JS object. BTW it is weird that the method Drupal.settings.openlayers.maps doesn't work anymore. I used it before and it worked for me, I still think that javascript is broken because javascript in header has the Drupal.settings.openlayers structure but for some reasons the javascript is never performed.
broken java script
I noticed that it happens only for custom OVERLAY LAYERS but if you select for example

Placeholder for Geofield Formatter

layers in Layers & styles tab then you can access to JS object with Drupal.settings.openlayers.maps
layers and styles
I am not sure if it is a bug or it should work like that but for me the behaviour has been changed since I updated version to the latest one.
I think it would be worth to fix it. Anyway thank you for your help.

Pol’s picture

Status: Fixed » Active

I suppose that it's a problem caused by geofield.

If you use a previous beta version of OpenLayers, do you have the same ?

Maybe we should have a look at this file ?

zaporylie’s picture

For me it doesn't matter if I have Geofield on or off. Probably for rafalB as well. The problem is any layer on initially hidden map.

This code (inside try {}) throws exception:

            // Run the layer addition first
            Drupal.openlayers.addLayers(map, openlayers);

/openlayers/js/openlayers.js (lines 83-84).

So this code will be never executed:

            // Ensure redraw as maps stays blank until first zoom otherwise (observed with EPSG:2056)
            openlayers.moveTo(openlayers.getCenter(), openlayers.getZoom(), {
              forceZoomChange: true
            });

            // Attach data to map DOM object
            $(this).data('openlayers', {'map': map, 'openlayers': openlayers});

            // Finally, attach behaviors
            Drupal.attachBehaviors(this);

Workaround is to hide openlayer map with jQuery .hide() method instead of CSS display: none;