Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
tmcw CreditAttribution: tmcw commentedThis 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).
Comment #2
tmcw CreditAttribution: tmcw commentedThe behaviors array is always set in 2.x, even if it's an empty array, so this patch isn't necessary.