Ticket #666: handler_bounds.2.patch
| File handler_bounds.2.patch, 7.7 kB (added by tschaub, 1 year ago) |
|---|
-
lib/OpenLayers/Handler/Path.js
old new 112 112 var index = this.line.geometry.components.length - 1; 113 113 this.line.geometry.components[index].x = this.point.geometry.x; 114 114 this.line.geometry.components[index].y = this.point.geometry.y; 115 this.line.geometry.components[index].clearBounds(); 115 116 }, 116 117 117 118 /** -
lib/OpenLayers/Handler/Point.js
old new 236 236 var lonlat = this.map.getLonLatFromPixel(evt.xy); 237 237 this.point.geometry.x = lonlat.lon; 238 238 this.point.geometry.y = lonlat.lat; 239 this.point.geometry.clearBounds(); 239 240 this.drawFeature(); 240 241 } 241 242 return true; -
tests/Handler/test_Path.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 function test_Handler_Path_constructor(t) { 6 t.plan(3); 7 var control = new OpenLayers.Control(); 8 control.id = Math.random(); 9 var callbacks = {foo: "bar"}; 10 var options = {bar: "foo"}; 11 12 var oldInit = OpenLayers.Handler.prototype.initialize; 13 14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) { 15 t.eq(con.id, control.id, 16 "constructor calls parent with the correct control"); 17 t.eq(call, callbacks, 18 "constructor calls parent with the correct callbacks"); 19 t.eq(opt, options, 20 "constructor calls parent with the correct options"); 21 } 22 var handler = new OpenLayers.Handler.Path(control, callbacks, options); 23 24 OpenLayers.Handler.prototype.initialize = oldInit; 25 } 26 27 function test_Handler_Path_activation(t) { 28 t.plan(3); 29 var map = new OpenLayers.Map('map'); 30 var control = new OpenLayers.Control(); 31 map.addControl(control); 32 var handler = new OpenLayers.Handler.Path(control); 33 handler.active = true; 34 var activated = handler.activate(); 35 t.ok(!activated, 36 "activate returns false if the handler was already active"); 37 handler.active = false; 38 activated = handler.activate(); 39 t.ok(activated, 40 "activate returns true if the handler was not already active"); 41 activated = handler.deactivate(); 42 t.ok(activated, 43 "deactivate returns true if the handler was active already"); 44 } 45 46 function test_Handler_Path_bounds(t) { 47 t.plan(2); 48 var map = new OpenLayers.Map('map'); 49 map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 50 map.zoomToMaxExtent(); 51 var control = new OpenLayers.Control(); 52 map.addControl(control); 53 var handler = new OpenLayers.Handler.Path(control, {}); 54 var activated = handler.activate(); 55 var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 56 handler.mousedown(evt); 57 handler.mouseup(evt); 58 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 59 handler.mousedown(evt); 60 handler.mouseup(evt); 61 t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds"); 62 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 63 handler.mousedown(evt); 64 var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1}; 65 handler.mousemove(evt); 66 t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)"); 67 } 68 69 70 71 // --> 72 </script> 73 </head> 74 <body> 75 <div id="map" style="width: 300px; height: 150px;"/> 76 </body> 77 </html> -
tests/Handler/test_Point.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 function test_Handler_Point_constructor(t) { 6 t.plan(3); 7 var control = new OpenLayers.Control(); 8 control.id = Math.random(); 9 var callbacks = {foo: "bar"}; 10 var options = {bar: "foo"}; 11 12 var oldInit = OpenLayers.Handler.prototype.initialize; 13 14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) { 15 t.eq(con.id, control.id, 16 "constructor calls parent with the correct control"); 17 t.eq(call, callbacks, 18 "constructor calls parent with the correct callbacks"); 19 t.eq(opt, options, 20 "constructor calls parent with the correct options"); 21 } 22 var handler = new OpenLayers.Handler.Point(control, callbacks, options); 23 24 OpenLayers.Handler.prototype.initialize = oldInit; 25 } 26 27 function test_Handler_Point_activation(t) { 28 t.plan(3); 29 var map = new OpenLayers.Map('map'); 30 var control = new OpenLayers.Control(); 31 map.addControl(control); 32 var handler = new OpenLayers.Handler.Point(control); 33 handler.active = true; 34 var activated = handler.activate(); 35 t.ok(!activated, 36 "activate returns false if the handler was already active"); 37 handler.active = false; 38 activated = handler.activate(); 39 t.ok(activated, 40 "activate returns true if the handler was not already active"); 41 activated = handler.deactivate(); 42 t.ok(activated, 43 "deactivate returns true if the handler was active already"); 44 } 45 46 function test_Handler_Point_bounds(t) { 47 t.plan(4); 48 var map = new OpenLayers.Map('map'); 49 map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 50 map.zoomToMaxExtent(); 51 var control = new OpenLayers.Control(); 52 map.addControl(control); 53 var handler = new OpenLayers.Handler.Point(control); 54 var activated = handler.activate(); 55 var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 56 handler.mousedown(evt); 57 t.eq(handler.point.geometry.x, 0, "X is correct"); 58 t.eq(handler.point.geometry.y, 0, "Y is correct"); 59 t.ok(handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Correct bounds"); 60 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 61 handler.mousemove(evt); 62 t.ok(!handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Bounds changed after moving mouse"); 63 } 64 65 66 67 // --> 68 </script> 69 </head> 70 <body> 71 <div id="map" style="width: 300px; height: 150px;"/> 72 </body> 73 </html> -
tests/list-tests.html
old new 73 73 <li>Control/test_Scale.html</li> 74 74 <li>test_Handler.html</li> 75 75 <li>Handler/test_Drag.html</li> 76 <li>Handler/test_Point.html</li> 77 <li>Handler/test_Path.html</li> 76 78 <li>test_Map.html</li> 77 79 </ul>
