handlers have to check if layer exists before destroying it. Thanks pgiraud. (closes #1107)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@5085 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2007-11-01 13:37:16 +00:00
parent 7ab5d456a8
commit 756f6ca24d
4 changed files with 51 additions and 7 deletions
+8 -2
View File
@@ -114,8 +114,14 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
if(this.drawing) { if(this.drawing) {
this.cancel(); this.cancel();
} }
this.map.removeLayer(this.layer, false); // If a layer's map property is set to null, it means that that layer
this.layer.destroy(); // isn't added to the map. Since we ourself added the layer to the map
// in activate(), we can assume that if this.layer.map is null it means
// that the layer has been destroyed (as a result of map.destroy() for
// example.
if (this.layer.map != null) {
this.layer.destroy(false);
}
this.layer = null; this.layer = null;
return true; return true;
}, },
+13 -5
View File
@@ -164,11 +164,19 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
if(this.dragging) { if(this.dragging) {
this.cancel(); this.cancel();
} }
this.map.removeLayer(this.layer, false); // If a layer's map property is set to null, it means that that
this.layer.destroy(); // layer isn't added to the map. Since we ourself added the layer
if (this.feature) { // to the map in activate(), we can assume that if this.layer.map
this.feature.destroy(); // is null it means that the layer has been destroyed (as a result
} // of map.destroy() for example.
if (this.layer.map != null) {
this.layer.destroy(false);
if (this.feature) {
this.feature.destroy();
}
}
this.layer = null;
this.feature = null;
deactivated = true; deactivated = true;
} }
return deactivated; return deactivated;
+15
View File
@@ -43,6 +43,21 @@
"deactivate returns true if the handler was active already"); "deactivate returns true if the handler was active already");
} }
function test_Handler_Point_deactivation(t) {
t.plan(1);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
handler.activate();
handler.layer.destroy();
handler.deactivate();
t.eq(handler.layer, null,
"deactivate doesn't throw an error if layer was" +
" previously destroyed");
}
function test_Handler_Point_bounds(t) { function test_Handler_Point_bounds(t) {
t.plan(4); t.plan(4);
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
+15
View File
@@ -43,6 +43,21 @@
"deactivate returns true if the handler was active already"); "deactivate returns true if the handler was active already");
} }
function test_Handler_RegularPolygon_deactivation(t) {
t.plan(1);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.RegularPolygon(control, {foo: 'bar'});
handler.activate();
handler.layer.destroy();
handler.deactivate();
t.eq(handler.layer, null,
"deactivate doesn't throw an error if layer was" +
" previously destroyed");
}
function test_Handler_RegularPolygon_four_corners(t) { function test_Handler_RegularPolygon_four_corners(t) {
t.plan(7); t.plan(7);
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');