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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user