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;
}

Files: 

Comments

Hi 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!

Hi 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;

Status:Active» Fixed

Good, committed !
Can you test and report back ?

Thanks!

Hi Pol

That works perfectly for me.

Cheers

Status:Fixed» Closed (fixed)

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