Changeset 6413
- Timestamp:
- 02/29/08 06:50:39 (11 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
r6315 r6413 290 290 this.dragControl.activate(); 291 291 this.onModificationStart(this.feature); 292 this.layer.events.triggerEvent("beforefeaturemodified", 293 {feature: this.feature}); 292 294 }, 293 295 … … 316 318 this.dragControl.deactivate(); 317 319 this.onModificationEnd(object.feature); 320 this.layer.events.triggerEvent("afterfeaturemodified", 321 {feature: object.feature}); 318 322 }, 319 323 … … 429 433 this.resetVertices(); 430 434 this.onModification(this.feature); 435 this.layer.events.triggerEvent("featuremodified", 436 {feature: this.feature}); 431 437 }, 432 438 … … 501 507 this.resetVertices(); 502 508 this.onModification(this.feature); 509 this.layer.events.triggerEvent("featuremodified", 510 {feature: this.feature}); 503 511 } 504 512 } trunk/openlayers/lib/OpenLayers/Layer/Vector.js
r6389 r6413 52 52 * Listeners will receive an object with a *feature* property 53 53 * referencing the unselected feature. 54 * - *beforefeaturemodified* Triggered when a feature is selected to 55 * be modified. Listeners will receive an object with a *feature* 56 * property referencing the selected feature. 57 * - *featuremodified* Triggered when a feature has been modified. 58 * Listeners will receive an object with a *feature* property referencing 59 * the modified feature. 60 * - *afterfeaturemodified* Triggered when a feature is finished being modified. 61 * Listeners will receive an object with a *feature* property referencing 62 * the modified feature. 54 63 */ 55 64 EVENT_TYPES: ["beforefeatureadded", "featureadded", 56 "featuresadded", "featureselected", "featureunselected"], 65 "featuresadded", "featureselected", "featureunselected", 66 "beforefeaturemodified", "featuremodified", "afterfeaturemodified"], 57 67 58 68 /** trunk/openlayers/tests/Control/test_ModifyFeature.html
r6240 r6413 4 4 <script type="text/javascript"> 5 5 6 function test_ ModifyFeature_constructor(t) {6 function test_initalize(t) { 7 7 t.plan(3); 8 8 var layer = { 9 9 styleMap: {createSymbolizer: function(){}}, 10 10 events: { 11 on: function() {} 11 on: function() {}, 12 un: function() {} 12 13 } 13 14 }; … … 23 24 t.eq(control.mode, OpenLayers.Control.ModifyFeature.RESHAPE, 24 25 "constructor initializes modification mode correctly"); 25 } 26 27 function test_ModifyFeature_destroy(t) { 26 control.destroy(); 27 } 28 29 function test_destroy(t) { 28 30 t.plan(2); 29 31 var map = new OpenLayers.Map("map"); … … 40 42 } 41 43 control.destroy(); 42 } 43 44 function test_ModifyFeature_activate(t) { 44 map.destroy(); 45 } 46 47 function test_activate(t) { 45 48 t.plan(2); 46 49 var map = new OpenLayers.Map("map"); … … 54 57 t.ok(control.selectControl.active, 55 58 "select control is active after activating control"); 56 } 57 58 function test_ModifyFeature_initDeleteCodes(t) { 59 60 map.destroy(); 61 } 62 63 function test_initDeleteCodes(t) { 59 64 t.plan(3); 60 65 var layer = new OpenLayers.Layer.Vector(); … … 65 70 t.eq(control.deleteCodes[1], 100, "Default deleteCodes include 'd'"); 66 71 67 } 68 69 function test_ModifyFeature_handleKeypress(t) { 70 t.plan(8); 72 control.destroy(); 73 layer.destroy(); 74 } 75 76 function test_handleKeypress(t) { 77 t.plan(10); 71 78 72 79 /** … … 78 85 */ 79 86 80 var control = new OpenLayers.Control.ModifyFeature({ 81 styleMap: {createSymbolizer: function(){}}, 82 events: { 83 on: function() {} 84 } 85 }); 87 var layer = new OpenLayers.Layer.Vector(); 88 var control = new OpenLayers.Control.ModifyFeature(layer); 86 89 var delKey = 46; 87 90 var dKey = 100; 88 91 control.deleteCodes = [delKey, dKey]; 89 90 //// test that point is deleted for all delete codes91 //var point = new OpenLayers.Feature.Vector(92 // new OpenLayers.Geometry.Point()93 //);94 //// mock up deletion before dragging (but after selection)95 //control.dragControl.feature = null;96 //control.feature = point;97 //var oldUnselect = control.unselectFeature;98 //control.unselectFeature = function(feature) {99 // t.eq(feature.id, point.id,100 // "point deletion before drag: unselectFeature called with the correct feature");101 //};102 //control.layer = {103 // removeFeatures: function(features) {104 // t.ok(features.length == 1,105 // "point deletion before drag: removeFeatures called with a single feature");106 // t.eq(features[0].id, point.id,107 // "point deletion before drag: removeFeatures called with the correct feature");108 // }109 //};110 //control.onDelete = function(feature) {111 // t.eq(feature.id, point.id,112 // "point deletion before drag: onDelete called with the correct feature");113 //};114 //// run the above four tests twice115 //control.handleKeypress(delKey);116 //control.handleKeypress(dKey);117 //// reset modified methods118 //control.unselectFeatures = oldUnselect;119 //control.onDelete = function() {};120 //121 //// mock up deletion during dragging - these repeat the above tests122 //control.dragControl.feature = point;123 //control.feature = point;124 //var oldUnselect = control.unselectFeature;125 //control.unselectFeature = function(feature) {126 // t.eq(feature.id, point.id,127 // "point deletion during drag: unselectFeature called with the correct feature");128 //};129 //control.layer = {130 // removeFeatures: function(features) {131 // t.ok(features.length == 1,132 // "point deletion during drag: removeFeatures called with a single feature");133 // t.eq(features[0].id, point.id,134 // "point deletion during drag: removeFeatures called with the correct feature");135 // }136 //};137 //control.onDelete = function(feature) {138 // t.eq(feature.id, point.id,139 // "point deletion during drag: onDelete called with the correct feature");140 //};141 //// run the above four tests twice142 //control.handleKeypress(delKey);143 //control.handleKeypress(dKey);144 //// reset modified methods145 //control.unselectFeatures = oldUnselect;146 //control.onDelete = function() {};147 92 148 93 // test that a polygon vertex is deleted for all delete codes … … 164 109 } 165 110 }; 166 control.layer ={167 drawFeature: function(feature) {168 t.eq(feature.id, poly.id,169 "vertex deletion: drawFeature called with the proper feature");170 }171 };172 var oldReset = control.resetVertices;111 layer.events.on({"featuremodified": function(event) { 112 t.eq(event.feature.id, poly.id, "vertex deletion: featuremodifed triggered"); 113 }}); 114 layer.drawFeature = function(feature) { 115 t.eq(feature.id, poly.id, 116 "vertex deletion: drawFeature called with the proper feature"); 117 }; 173 118 control.resetVertices = function() { 174 119 t.ok(true, "vertex deletion: resetVertices called"); … … 186 131 control.handleKeypress(delKey); 187 132 188 // reset modified methods189 control. onModification = function() {};190 133 // clean up 134 control.destroy(); 135 layer.destroy(); 191 136 } 192 137 193 138 194 function test_ ModifyFeature_onUnSelect(t) {195 t.plan( 5);139 function test_onUnSelect(t) { 140 t.plan(6); 196 141 var layer = new OpenLayers.Layer.Vector(); 197 142 var control = new OpenLayers.Control.ModifyFeature(layer); … … 200 145 control.virtualVertices = 'b'; 201 146 control.features = true; 147 layer.events.on({"afterfeaturemodified": function(event) { 148 t.eq(event.feature, fakeFeature, "afterfeaturemodified triggered"); 149 }}); 202 150 control.dragControl.deactivate = function() { t.ok(true, "Deactivate called on drag control"); } 203 151 control.onModificationEnd = function (feature) { t.eq(feature.id, fakeFeature.id, "onModificationEnd got feature.") } … … 210 158 control.unselectFeature({feature: fakeFeature}); 211 159 t.eq(control.feature, null, "feature is set to null"); 160 161 layer.destroyFeatures = function() {}; 162 control.destroy(); 163 layer.destroy(); 212 164 } 213 function test_ModifyFeature_selectFeature(t) { 214 t.plan(12); 165 166 function test_selectFeature(t) { 167 t.plan(15); 215 168 var layer = new OpenLayers.Layer.Vector(); 216 169 var control = new OpenLayers.Control.ModifyFeature(layer); 217 170 control.vertices = []; 218 171 control.virtualVertices = []; 172 layer.events.on({"beforefeaturemodified": function(event) { 173 t.eq(event.feature, fakeFeature, "beforefeaturemodified triggered"); 174 }}); 219 175 control.dragControl.activate = function() { t.ok(true, "drag Control activated"); } 220 176 control.onModificationStart = function(feature) { t.eq(feature.id, fakeFeature.id, "On Modification Start called with correct feature."); } … … 257 213 control.selectFeature({feature: fakeFeature}); 258 214 215 control.destroy(); 216 layer.destroy(); 259 217 } 260 218 261 function test_ ModifyFeature_resetVertices(t) {219 function test_resetVertices(t) { 262 220 t.plan(18); 263 221 var layer = new OpenLayers.Layer.Vector(); … … 327 285 } 328 286 329 function test_ ModifyFeature_onDrag(t) {287 function test_onDrag(t) { 330 288 t.plan(1); 331 289 t.ok(true, "onDrag not tested yet."); 332 290 } 333 291 334 function test_ ModifyFeature_dragComplete(t) {335 t.plan( 6);292 function test_dragComplete(t) { 293 t.plan(7); 336 294 var layer = new OpenLayers.Layer.Vector(); 337 295 var control = new OpenLayers.Control.ModifyFeature(layer); … … 347 305 t.ok(verts == 'previous virtual' || verts == 'previous normal', verts + " verts correct"); 348 306 } 307 layer.events.on({"featuremodified": function(event) { 308 t.eq(event.feature, fakeFeature, "featuremodified triggered"); 309 }}); 349 310 control.onModification = function(feat) { 350 311 t.eq(feat.id, fakeFeature.id, "onModification gets correct feat"); … … 361 322 control.virtualVertices = 'previous virtual'; 362 323 control.dragComplete(); 363 } 364 365 function test_ModifyFeature_deactivate(t) { 324 325 control.destroy(); 326 layer.destroy(); 327 } 328 329 function test_deactivate(t) { 366 330 t.plan(2); 367 331 var map = new OpenLayers.Map("map"); … … 381 345 control.active = true; 382 346 control.deactivate(); 383 } 384 385 function test_ModifyFeature_onModificationStart(t) { 386 t.plan(1); 347 348 map.destroy(); 349 } 350 351 function test_onModificationStart(t) { 352 t.plan(2); 387 353 var map = new OpenLayers.Map("map"); 388 354 var layer = new OpenLayers.Layer.Vector(); … … 391 357 map.addControl(control); 392 358 control.activate(); 359 360 // test that beforefeaturemodified is triggered 361 layer.events.on({"beforefeaturemodified": function(event) { 362 t.eq(event.feature.id, testFeature.id, 363 "beforefeaturemodified is triggered with correct feature"); 364 }}); 393 365 394 366 // make sure onModificationStart is called on feature selection … … 401 373 }; 402 374 control.selectFeature({feature: testFeature}); 403 } 404 405 function test_ModifyFeature_onModification(t) { 406 t.plan(2); 375 376 map.destroy(); 377 } 378 379 function test_onModification(t) { 380 t.plan(3); 407 381 var map = new OpenLayers.Map("map"); 408 382 var layer = new OpenLayers.Layer.Vector(); … … 433 407 control.feature = poly; 434 408 control.vertices = [point]; 409 layer.events.on({"featuremodified": function(event) { 410 t.eq(event.feature.id, poly.id, "featuremodified triggered"); 411 }}); 435 412 control.onModification = function(feature) { 436 413 t.eq(feature.id, poly.id, … … 442 419 layer.drawFeature = oldDraw; 443 420 444 } 445 446 function test_ModifyFeature_onModificationEnd(t) { 447 t.plan(1); 421 map.destroy(); 422 } 423 424 function test_onModificationEnd(t) { 425 t.plan(2); 448 426 var map = new OpenLayers.Map("map"); 449 427 var layer = new OpenLayers.Layer.Vector(); … … 457 435 new OpenLayers.Geometry.Point(Math.random(), Math.random()) 458 436 ); 437 layer.events.on({"afterfeaturemodified": function(event) { 438 t.eq(event.feature.id, testFeature.id, "afterfeaturemodified triggered"); 439 }}); 459 440 control.onModificationEnd = function(feature) { 460 441 t.eq(feature.id, testFeature.id, … … 462 443 }; 463 444 control.unselectFeature({feature: testFeature}); 464 } 465 466 467 //function t//est_ModifyFeature_onDelete(t) { 468 // t.plan(2); 469 // var map = new OpenLayers.Map("map"); 470 // var layer = new OpenLayers.Layer.Vector(); 471 // map.addLayer(layer); 472 // var control = new OpenLayers.Control.ModifyFeature(layer); 473 // map.addControl(control); 474 // control.activate(); 475 // 476 // // make sure onDelete is called on point deletion (before dragging) 477 // var point = new OpenLayers.Feature.Vector( 478 // new OpenLayers.Geometry.Point(Math.random(), Math.random()) 479 // ); 480 // control.feature = point; 481 // control.onDelete = function(feature) { 482 // t.eq(feature.id, point.id, 483 // "onDelete called with the right feature before drag"); 484 // }; 485 // control.handleKeypress(46); 486 // 487 // // make sure onDelete is called on point deletion (during dragging) 488 // var point = new OpenLayers.Feature.Vector( 489 // new OpenLayers.Geometry.Point(Math.random(), Math.random()) 490 // ); 491 // control.dragControl.feature = point; 492 // control.feature = point; 493 // control.onDelete = function(feature) { 494 // t.eq(feature.id, point.id, 495 // "onDelete called with the right feature during drag"); 496 // }; 497 // control.handleKeypress(46); 498 // 499 //} 445 446 map.destroy(); 447 } 448 500 449 501 450 </script>
