When the geolocate behavior is enabled, but 'Center when located' (which is the bind option) is set to 'No', the map still centres on the user's current location.
The reason for this is that in the javascript file openlayers/plugins/behaviors/openlayers_behavior_geolocate.js, the value of options.bind is the string '0', rather than a boolean value. Later, in the library file libraries/openlayers/lib/OpenLayers/Control/Geolocate.js, in the geolocate() function, this.bind is used in an if statement. Because in JavaScript an non-empty string is always true, this.map.setCenter(center) is called. (JavaScript and PHP are different in this; in PHP, the string '0' would evaluate to false).
This means it's impossible to turn the 'Center when located' feature off.
For me, adding the following lines at the start of the anonymous function in openlayers_behavior_gelocate.js fixed the issue:
if (options.bind === '0') {
options.bind = false;
}
Comment | File | Size | Author |
---|---|---|---|
#2 | Openlayers_behaviors_center_when_located.patch | 780 bytes | mooey |
Comments
Comment #1
PolHi mooey,
Nice catch there, I would prefer doing the variable mapping directly in the PHP file. The lesser JS we have, the better it is.
Check the render() method of the geolocate behavior and try to adjust the variable casting in there.
I'll commit the changes as soon as I have your code.
Thank you very much!
Comment #2
mooey CreditAttribution: mooey commentedHi Pol
That makes sense.
I've attached a patch file. Because I don't know what the effect of changes $this->options would be, I've changed return $this->options to
$options = $this->options;
$options['bind'] = !!$options['bind'];
return $options;
Comment #3
PolGood, committed !
Can you test and report back ?
Thanks!
Comment #4
PolDiff: http://drupalcode.org/project/openlayers.git/commitdiff/e51799c?hp=11166...
Comment #5
mooey CreditAttribution: mooey commentedHi Pol
That works perfectly for me.
Cheers