| 77 | | // test that point is deleted for all delete codes |
|---|
| | 78 | //// test that point is deleted for all delete codes |
|---|
| | 79 | //var point = new OpenLayers.Feature.Vector( |
|---|
| | 80 | // new OpenLayers.Geometry.Point() |
|---|
| | 81 | //); |
|---|
| | 82 | //// mock up deletion before dragging (but after selection) |
|---|
| | 83 | //control.dragControl.feature = null; |
|---|
| | 84 | //control.feature = point; |
|---|
| | 85 | //var oldUnselect = control.unselectFeature; |
|---|
| | 86 | //control.unselectFeature = function(feature) { |
|---|
| | 87 | // t.eq(feature.id, point.id, |
|---|
| | 88 | // "point deletion before drag: unselectFeature called with the correct feature"); |
|---|
| | 89 | //}; |
|---|
| | 90 | //control.layer = { |
|---|
| | 91 | // removeFeatures: function(features) { |
|---|
| | 92 | // t.ok(features.length == 1, |
|---|
| | 93 | // "point deletion before drag: removeFeatures called with a single feature"); |
|---|
| | 94 | // t.eq(features[0].id, point.id, |
|---|
| | 95 | // "point deletion before drag: removeFeatures called with the correct feature"); |
|---|
| | 96 | // } |
|---|
| | 97 | //}; |
|---|
| | 98 | //control.onDelete = function(feature) { |
|---|
| | 99 | // t.eq(feature.id, point.id, |
|---|
| | 100 | // "point deletion before drag: onDelete called with the correct feature"); |
|---|
| | 101 | //}; |
|---|
| | 102 | //// run the above four tests twice |
|---|
| | 103 | //control.handleKeypress(delKey); |
|---|
| | 104 | //control.handleKeypress(dKey); |
|---|
| | 105 | //// reset modified methods |
|---|
| | 106 | //control.unselectFeatures = oldUnselect; |
|---|
| | 107 | //control.onDelete = function() {}; |
|---|
| | 108 | // |
|---|
| | 109 | //// mock up deletion during dragging - these repeat the above tests |
|---|
| | 110 | //control.dragControl.feature = point; |
|---|
| | 111 | //control.feature = point; |
|---|
| | 112 | //var oldUnselect = control.unselectFeature; |
|---|
| | 113 | //control.unselectFeature = function(feature) { |
|---|
| | 114 | // t.eq(feature.id, point.id, |
|---|
| | 115 | // "point deletion during drag: unselectFeature called with the correct feature"); |
|---|
| | 116 | //}; |
|---|
| | 117 | //control.layer = { |
|---|
| | 118 | // removeFeatures: function(features) { |
|---|
| | 119 | // t.ok(features.length == 1, |
|---|
| | 120 | // "point deletion during drag: removeFeatures called with a single feature"); |
|---|
| | 121 | // t.eq(features[0].id, point.id, |
|---|
| | 122 | // "point deletion during drag: removeFeatures called with the correct feature"); |
|---|
| | 123 | // } |
|---|
| | 124 | //}; |
|---|
| | 125 | //control.onDelete = function(feature) { |
|---|
| | 126 | // t.eq(feature.id, point.id, |
|---|
| | 127 | // "point deletion during drag: onDelete called with the correct feature"); |
|---|
| | 128 | //}; |
|---|
| | 129 | //// run the above four tests twice |
|---|
| | 130 | //control.handleKeypress(delKey); |
|---|
| | 131 | //control.handleKeypress(dKey); |
|---|
| | 132 | //// reset modified methods |
|---|
| | 133 | //control.unselectFeatures = oldUnselect; |
|---|
| | 134 | //control.onDelete = function() {}; |
|---|
| | 135 | |
|---|
| | 136 | // test that a polygon vertex is deleted for all delete codes |
|---|
| 81 | | // mock up deletion before dragging (but after selection) |
|---|
| 82 | | control.dragControl.feature = null; |
|---|
| 83 | | control.feature = point; |
|---|
| 84 | | var oldUnselect = control.unselectFeature; |
|---|
| 85 | | control.unselectFeature = function(feature) { |
|---|
| 86 | | t.eq(feature.id, point.id, |
|---|
| 87 | | "point deletion before drag: unselectFeature called with the correct feature"); |
|---|
| 88 | | }; |
|---|
| 89 | | control.layer = { |
|---|
| 90 | | removeFeatures: function(features) { |
|---|
| 91 | | t.ok(features.length == 1, |
|---|
| 92 | | "point deletion before drag: removeFeatures called with a single feature"); |
|---|
| 93 | | t.eq(features[0].id, point.id, |
|---|
| 94 | | "point deletion before drag: removeFeatures called with the correct feature"); |
|---|
| 95 | | } |
|---|
| 96 | | }; |
|---|
| 97 | | control.onDelete = function(feature) { |
|---|
| 98 | | t.eq(feature.id, point.id, |
|---|
| 99 | | "point deletion before drag: onDelete called with the correct feature"); |
|---|
| 100 | | }; |
|---|
| 101 | | // run the above four tests twice |
|---|
| 102 | | control.handleKeypress(delKey); |
|---|
| 103 | | control.handleKeypress(dKey); |
|---|
| 104 | | // reset modified methods |
|---|
| 105 | | control.unselectFeatures = oldUnselect; |
|---|
| 106 | | control.onDelete = function() {}; |
|---|
| 107 | | |
|---|
| 108 | | // mock up deletion during dragging - these repeat the above tests |
|---|
| 109 | | control.dragControl.feature = point; |
|---|
| 110 | | control.feature = point; |
|---|
| 111 | | var oldUnselect = control.unselectFeature; |
|---|
| 112 | | control.unselectFeature = function(feature) { |
|---|
| 113 | | t.eq(feature.id, point.id, |
|---|
| 114 | | "point deletion during drag: unselectFeature called with the correct feature"); |
|---|
| 115 | | }; |
|---|
| 116 | | control.layer = { |
|---|
| 117 | | removeFeatures: function(features) { |
|---|
| 118 | | t.ok(features.length == 1, |
|---|
| 119 | | "point deletion during drag: removeFeatures called with a single feature"); |
|---|
| 120 | | t.eq(features[0].id, point.id, |
|---|
| 121 | | "point deletion during drag: removeFeatures called with the correct feature"); |
|---|
| 122 | | } |
|---|
| 123 | | }; |
|---|
| 124 | | control.onDelete = function(feature) { |
|---|
| 125 | | t.eq(feature.id, point.id, |
|---|
| 126 | | "point deletion during drag: onDelete called with the correct feature"); |
|---|
| 127 | | }; |
|---|
| 128 | | // run the above four tests twice |
|---|
| 129 | | control.handleKeypress(delKey); |
|---|
| 130 | | control.handleKeypress(dKey); |
|---|
| 131 | | // reset modified methods |
|---|
| 132 | | control.unselectFeatures = oldUnselect; |
|---|
| 133 | | control.onDelete = function() {}; |
|---|
| 134 | | |
|---|
| 135 | | // test that a polygon vertex is deleted for all delete codes |
|---|
| 404 | | function test_ModifyFeature_onDelete(t) { |
|---|
| 405 | | t.plan(2); |
|---|
| 406 | | var map = new OpenLayers.Map("map"); |
|---|
| 407 | | var layer = new OpenLayers.Layer.Vector(); |
|---|
| 408 | | map.addLayer(layer); |
|---|
| 409 | | var control = new OpenLayers.Control.ModifyFeature(layer); |
|---|
| 410 | | map.addControl(control); |
|---|
| 411 | | control.activate(); |
|---|
| 412 | | |
|---|
| 413 | | // make sure onDelete is called on point deletion (before dragging) |
|---|
| 414 | | var point = new OpenLayers.Feature.Vector( |
|---|
| 415 | | new OpenLayers.Geometry.Point(Math.random(), Math.random()) |
|---|
| 416 | | ); |
|---|
| 417 | | control.feature = point; |
|---|
| 418 | | control.onDelete = function(feature) { |
|---|
| 419 | | t.eq(feature.id, point.id, |
|---|
| 420 | | "onDelete called with the right feature before drag"); |
|---|
| 421 | | }; |
|---|
| 422 | | control.handleKeypress(46); |
|---|
| 423 | | |
|---|
| 424 | | // make sure onDelete is called on point deletion (during dragging) |
|---|
| 425 | | var point = new OpenLayers.Feature.Vector( |
|---|
| 426 | | new OpenLayers.Geometry.Point(Math.random(), Math.random()) |
|---|
| 427 | | ); |
|---|
| 428 | | control.dragControl.feature = point; |
|---|
| 429 | | control.feature = point; |
|---|
| 430 | | control.onDelete = function(feature) { |
|---|
| 431 | | t.eq(feature.id, point.id, |
|---|
| 432 | | "onDelete called with the right feature during drag"); |
|---|
| 433 | | }; |
|---|
| 434 | | control.handleKeypress(46); |
|---|
| 435 | | |
|---|
| 436 | | } |
|---|
| | 408 | |
|---|
| | 409 | //function t//est_ModifyFeature_onDelete(t) { |
|---|
| | 410 | // t.plan(2); |
|---|
| | 411 | // var map = new OpenLayers.Map("map"); |
|---|
| | 412 | // var layer = new OpenLayers.Layer.Vector(); |
|---|
| | 413 | // map.addLayer(layer); |
|---|
| | 414 | // var control = new OpenLayers.Control.ModifyFeature(layer); |
|---|
| | 415 | // map.addControl(control); |
|---|
| | 416 | // control.activate(); |
|---|
| | 417 | // |
|---|
| | 418 | // // make sure onDelete is called on point deletion (before dragging) |
|---|
| | 419 | // var point = new OpenLayers.Feature.Vector( |
|---|
| | 420 | // new OpenLayers.Geometry.Point(Math.random(), Math.random()) |
|---|
| | 421 | // ); |
|---|
| | 422 | // control.feature = point; |
|---|
| | 423 | // control.onDelete = function(feature) { |
|---|
| | 424 | // t.eq(feature.id, point.id, |
|---|
| | 425 | // "onDelete called with the right feature before drag"); |
|---|
| | 426 | // }; |
|---|
| | 427 | // control.handleKeypress(46); |
|---|
| | 428 | // |
|---|
| | 429 | // // make sure onDelete is called on point deletion (during dragging) |
|---|
| | 430 | // var point = new OpenLayers.Feature.Vector( |
|---|
| | 431 | // new OpenLayers.Geometry.Point(Math.random(), Math.random()) |
|---|
| | 432 | // ); |
|---|
| | 433 | // control.dragControl.feature = point; |
|---|
| | 434 | // control.feature = point; |
|---|
| | 435 | // control.onDelete = function(feature) { |
|---|
| | 436 | // t.eq(feature.id, point.id, |
|---|
| | 437 | // "onDelete called with the right feature during drag"); |
|---|
| | 438 | // }; |
|---|
| | 439 | // control.handleKeypress(46); |
|---|
| | 440 | // |
|---|
| | 441 | //} |
|---|