The problem is that behaviors get attached multiple times if we load maps via ajax, in an edit form for example (with #1273802: Geofield/Openlayers widget refactor). And if we have something like geolocation enabled, it reset all maps, not just the new one. This patch fixes that.
I know the patch is huge, the only meaningful change is this :
var data = $(context).data('openlayers');
if (data && data.map.behaviors['openlayers_behavior_CURRENTFEATURE']) {
in all includes/behaviors/js/*.js files is changed to
var data = $(context).data('openlayers'),
behavior = data && data.map.behaviors['openlayers_behavior_CURRENTFEATURE'];
if (!$(context).hasClass('openlayers-CURRENTFEATURE-processed') && behavior) {
// function code
$(context).addClass('openlayers-CURENTFEATURE-processed');
}I could have used jquery().once() and it'd have done the same thing, but the changes would be a bit more intrusive.
I also replaced all occurrence of data.map.behaviors['openlayers_behavior_CURRENTFEATURE'] into behavior, only inside the main if.
It was all handcrafted with love so there is no find/replace nonsense. I created a map with all behaviors enabled, worked fine and as designed.
The vast majority is whitespace change. I indented all the files the same way so it feels more coherent and added missing colons. That's what's making this patch huge.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | openlayers-fix-behavior-execution-1329560-9.patch | 527 bytes | nod_ |
| #6 | openlayers-fix-behavior-execution-1329560-5.patch | 41.02 KB | nod_ |
| #4 | openlayers-fix-behavior-execution-1329560-4.patch | 42.66 KB | nod_ |
| openlayers-fix-behavior-execution.patch | 44.7 KB | nod_ |
Comments
Comment #1
zzolo commented@nod_. Thanks so much for the patch. I don't have that much time to test this. Maybe someone else can come by and just confirm that this is good. A quick glance says ok.
A minor coding issue that is not even close to a blocker, but I really don't like this way of decalring variables in JS:
Besides being ugly, it leaves more room for not using var when it would change the scope of the variable drastically.
Comment #2
zzolo commentedHey, here's a thought related to this. If we are going to add more logic around every single behavior, maybe we should be abstracting this out more. Here is a real quick example of making a generic openlayers.addBehavior method to handle the same logic:
Comment #3
nod_I wanted to change it again once all the whitespace thing got commited to use jquery once().
Abstracting away works too, but i'm not even sure that
if (localBehavior)is even needed. I mean there are quite a lot of behaviors that don't even use the variable. so it could come down to :The problem could be if you have different maps with different settings on the same page.
But yeah I guess in the end abstracting is the way to go to shorten the code. I can work on a patch on top of the other one if you'd like.
Comment #4
nod_updated patch. abstracted the thing like you said zzolo. it's so much better and shorter now.
and
It's against 7.x-2.x of today i fixed a couple of leaking vars too.
the abstraction above is in a new file that i include in
openlayers.render.incwith a simpleIt's not in the patch as i didn't know if it was the right place to add it.
Comment #6
nod_happy now Mr. Bot ? :þ
Comment #7
zzolo commentedOverall, this looks good. A couple minor things. I would put the helper functions in the main openlayers.js file instead of a separate one.
I would still love it if someone else could test this out given that it is a large change and affects lots of code.
Comment #8
zzolo commentedHey, so I applied this patch (after cleaning it up a bit) specifically because I moved all the plugins into the appropriate place for better use of Ctools. Please test out.
Comment #9
nod_Awesome, thanks :)
A little something got forgotten on the way
Comment #10
zzolo commentedPatched. Many thanks.
For others' reference, more abstract conversation happening here: #1087572: Exposed filters with D7 OpenLayers Data displays