Avoid touching the geolocation object until needed

IE9 leaks when `navigator.geolocation` is accessed (see #461).  The goal of this change is to avoid that leak in builds that include the Geolocate control but do not use it.
This commit is contained in:
Tim Schaub
2013-02-04 15:46:45 -07:00
parent 47e7c300a8
commit 84e36dd573
2 changed files with 12 additions and 13 deletions

View File

@@ -45,8 +45,15 @@ OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
/**
* Property: geolocation
* {Object} The geolocation engine, as a property to be possibly mocked.
* This is set lazily to avoid a memory leak in IE9.
*/
geolocation: navigator.geolocation,
geolocation: null,
/**
* Property: available
* {Boolean} The navigator.geolocation object is available.
*/
available: ('geolocation' in navigator),
/**
* APIProperty: bind
@@ -90,6 +97,10 @@ OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
* {Boolean} The control was effectively activated.
*/
activate: function () {
if (this.available && !this.geolocation) {
// set lazily to avoid IE9 memory leak
this.geolocation = navigator.geolocation;
}
if (!this.geolocation) {
this.events.triggerEvent("locationuncapable");
return false;