diff --git a/lib/OpenLayers/Control/Geolocate.js b/lib/OpenLayers/Control/Geolocate.js index f2fcb91910..4b5b43958e 100644 --- a/lib/OpenLayers/Control/Geolocate.js +++ b/lib/OpenLayers/Control/Geolocate.js @@ -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; diff --git a/tests/Control/Geolocate.html b/tests/Control/Geolocate.html index aa12c0452d..4e43f39945 100644 --- a/tests/Control/Geolocate.html +++ b/tests/Control/Geolocate.html @@ -101,18 +101,6 @@ map.removeControl(control); 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) { t.plan(1); var control = new OpenLayers.Control.Geolocate({