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
|
* Property: geolocation
|
||||||
* {Object} The geolocation engine, as a property to be possibly mocked.
|
* {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
|
* APIProperty: bind
|
||||||
@@ -90,6 +97,10 @@ OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
* {Boolean} The control was effectively activated.
|
* {Boolean} The control was effectively activated.
|
||||||
*/
|
*/
|
||||||
activate: function () {
|
activate: function () {
|
||||||
|
if (this.available && !this.geolocation) {
|
||||||
|
// set lazily to avoid IE9 memory leak
|
||||||
|
this.geolocation = navigator.geolocation;
|
||||||
|
}
|
||||||
if (!this.geolocation) {
|
if (!this.geolocation) {
|
||||||
this.events.triggerEvent("locationuncapable");
|
this.events.triggerEvent("locationuncapable");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -101,18 +101,6 @@
|
|||||||
map.removeControl(control);
|
map.removeControl(control);
|
||||||
map.setCenter(centerLL);
|
map.setCenter(centerLL);
|
||||||
}
|
}
|
||||||
function test_uncapable(t) {
|
|
||||||
t.plan(1);
|
|
||||||
var control = new OpenLayers.Control.Geolocate({
|
|
||||||
geolocation: null,
|
|
||||||
bind: false
|
|
||||||
});
|
|
||||||
control.events.register('locationuncapable', null, function() {
|
|
||||||
t.ok(true,'uncapable browser fired locationuncapable event');
|
|
||||||
});
|
|
||||||
map.addControl(control);
|
|
||||||
control.activate();
|
|
||||||
}
|
|
||||||
function test_destroy(t) {
|
function test_destroy(t) {
|
||||||
t.plan(1);
|
t.plan(1);
|
||||||
var control = new OpenLayers.Control.Geolocate({
|
var control = new OpenLayers.Control.Geolocate({
|
||||||
|
|||||||
Reference in New Issue
Block a user