fixed box sizing and positioning. r=sbrunner (closes #2910)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11749 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-03-29 13:44:04 +00:00
parent 54b58e3faf
commit c5dfe37bd4
4 changed files with 204 additions and 48 deletions

View File

@@ -2,6 +2,49 @@
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_Handler_Box_constructor(t) {
t.plan(4);
var control = new OpenLayers.Control();
control.id = Math.random();
var callbacks = {done: "bar"};
var options = {bar: "foo"};
var handler = new OpenLayers.Handler.Box(control, callbacks, options);
t.eq(handler.control.id, control.id, "handler created with the correct control");
t.eq(handler.callbacks.done, "bar", "handler created with the correct callback");
t.eq(handler.bar, "foo", "handler created with the correct options");
t.ok(handler.dragHandler instanceof OpenLayers.Handler.Drag, "drag handler created");
}
function test_Handler_Box_draw(t) {
t.plan(12);
var map = new OpenLayers.Map('map');
var control = new OpenLayers.Control();
map.addControl(control);
var handler = new OpenLayers.Handler.Box(control, {done: function(e) {
t.ok(e.equals(new OpenLayers.Bounds(5, 11, 11, 5)), "box result correct");
}});
handler.activate();
handler.dragHandler.start = {x: 5, y: 5};
handler.startBox({x: 5, y: 5});
var offset = handler.getBoxOffsets();
t.eq(parseInt(handler.zoomBox.style.left), 5 - offset.left, "x position of box correct");
t.eq(parseInt(handler.zoomBox.style.top), 5 - offset.top, "y position of box correct");
handler.moveBox({x: 10, y: 10});
t.eq(parseInt(handler.zoomBox.style.left), 5 - offset.left, "x position of box still correct");
t.eq(parseInt(handler.zoomBox.style.top), 5 - offset.top, "y position of box still correct");
t.eq(parseInt(handler.zoomBox.style.width), 5 + offset.width + 1, "x dimension of box correct");
t.eq(parseInt(handler.zoomBox.style.height), 5 + offset.height + 1, "y dimension of box correct");
handler.moveBox({x: 0, y: 0});
t.eq(parseInt(handler.zoomBox.style.left), 0 - offset.left, "new x position of box correct");
t.eq(parseInt(handler.zoomBox.style.top), 0 - offset.top, "new y position of box correct");
t.eq(parseInt(handler.zoomBox.style.width), 5 + offset.width + 1, "x dimension of box still correct");
t.eq(parseInt(handler.zoomBox.style.height), 5 + offset.height + 1, "y dimension of box still correct");
handler.endBox({x: 11, y: 11});
t.eq(handler.zoomBox, null, "box removed after endBox");
}
function test_Handler_Box_destroy(t) {
t.plan(1);
var map = new OpenLayers.Map('map');
@@ -21,6 +64,6 @@
</script>
</head>
<body>
<div id="map" style="width: 300px; height: 150px;"/>
<div id="map" style="width: 300px; height: 150px;"></div>
</body>
</html>