Example:

Drupal.behaviors.openlayers_behavior_layerswitcher = function(context) {
  var data = $(context).data('openlayers');
  if (data && data.map.behaviors['openlayers_behavior_layerswitcher']) {
    // Add control

This check fails if there is more than one map, because every map will get this attached to it, and if there is no behaviors array at all, this fails.

This needs to be done to pretty much all the behaviors.

Drupal.behaviors.openlayers_behavior_layerswitcher = function(context) {
  var data = $(context).data('openlayers');
  if (data && OL.isSet(data.map.behaviors) && data.map.behaviors['openlayers_behavior_layerswitcher']) {
    // Add control

Comments

tmcw’s picture

This looks valid. One thing I'd note about the patch: I'm in favor of removing the isSet function and replacing it with just

variable === undefined

Which is about the same length, character-wise as the function and is much clearer about how it works. I really think that the openlayers.helper.js functions should be completely eliminated, because they either eliminate more idiomatic javascript (like isSet), do things that jQuery does better (like triggerCustom), or do things you could easily do more quickly in the few calls that they have (like getObject).

tmcw’s picture

Status: Active » Fixed

The behaviors array is always set in 2.x, even if it's an empty array, so this patch isn't necessary.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.