git-svn-id: http://svn.openlayers.org/trunk/openlayers@11162 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
187 lines
7.6 KiB
HTML
187 lines
7.6 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../OLLoader.js"></script>
|
|
<script type="text/javascript">
|
|
function test_Handler_Path_constructor(t) {
|
|
t.plan(3);
|
|
var control = new OpenLayers.Control();
|
|
control.id = Math.random();
|
|
var callbacks = {foo: "bar"};
|
|
var options = {bar: "foo"};
|
|
|
|
var oldInit = OpenLayers.Handler.prototype.initialize;
|
|
|
|
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
|
t.eq(con.id, control.id,
|
|
"constructor calls parent with the correct control");
|
|
t.eq(call, callbacks,
|
|
"constructor calls parent with the correct callbacks");
|
|
t.eq(opt, options,
|
|
"constructor calls parent with the correct options");
|
|
}
|
|
var handler = new OpenLayers.Handler.Path(control, callbacks, options);
|
|
|
|
OpenLayers.Handler.prototype.initialize = oldInit;
|
|
}
|
|
|
|
function test_Handler_Path_activation(t) {
|
|
t.plan(3);
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Path(control);
|
|
handler.active = true;
|
|
var activated = handler.activate();
|
|
t.ok(!activated,
|
|
"activate returns false if the handler was already active");
|
|
handler.active = false;
|
|
activated = handler.activate();
|
|
t.ok(activated,
|
|
"activate returns true if the handler was not already active");
|
|
activated = handler.deactivate();
|
|
t.ok(activated,
|
|
"deactivate returns true if the handler was active already");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_Handler_Path_bounds(t) {
|
|
t.plan(2);
|
|
var map = new OpenLayers.Map('map');
|
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
|
map.zoomToMaxExtent();
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Path(control, {});
|
|
var activated = handler.activate();
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.mousedown(evt);
|
|
handler.mouseup(evt);
|
|
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
|
|
handler.mousemove(evt);
|
|
handler.mousedown(evt);
|
|
handler.mouseup(evt);
|
|
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
|
|
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
|
|
handler.mousedown(evt);
|
|
var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
|
|
handler.mousemove(evt);
|
|
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() + ".)");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_callbacks(t) {
|
|
t.plan(15);
|
|
var map = new OpenLayers.Map("map", {
|
|
resolutions: [1]
|
|
});
|
|
var layer = new OpenLayers.Layer.Vector("foo", {
|
|
maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
|
|
isBaseLayer: true
|
|
});
|
|
map.addLayer(layer);
|
|
var control = new OpenLayers.Control({
|
|
});
|
|
var log = {};
|
|
var handler = new OpenLayers.Handler.Path(control, {
|
|
create: function() {
|
|
log.type = "create",
|
|
log.args = arguments
|
|
},
|
|
modify: function() {
|
|
log.type = "modify",
|
|
log.args = arguments
|
|
},
|
|
done: function() {
|
|
log.type = "done",
|
|
log.args = arguments
|
|
},
|
|
cancel: function() {
|
|
log.type = "cancel",
|
|
log.args = arguments
|
|
}
|
|
});
|
|
control.handler = handler;
|
|
map.addControl(control);
|
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
|
|
|
// mock up feature drawing
|
|
handler.activate();
|
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
|
t.eq(log.type, "create", "[mousedown] create called");
|
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
|
|
t.ok(log.args[1] === handler.line, "[mousedown] correct sketch feature");
|
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
|
t.eq(log.type, "modify", "[mouseup] modify called");
|
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
|
|
t.ok(log.args[1] === handler.line, "[mouseup] correct sketch feature");
|
|
handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
|
|
t.eq(log.type, "modify", "[mousemove] modify called");
|
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 74), "[mousemove] correct vertex");
|
|
t.ok(log.args[1] === handler.line, "[mousemove] correct sketch feature");
|
|
handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
|
|
t.eq(log.type, "modify", "[mousemove] modify called");
|
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65), "[mousemove] correct vertex");
|
|
t.ok(log.args[1] === handler.line, "[mousemove] correct sketch feature");
|
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
|
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
|
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
|
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
|
|
handler.dblclick({type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
|
|
t.eq(log.type, "done", "[dblclick] done called");
|
|
t.geom_eq(
|
|
log.args[0],
|
|
new OpenLayers.Geometry.LineString([
|
|
new OpenLayers.Geometry.Point(-150, 75),
|
|
new OpenLayers.Geometry.Point(-140, 65)
|
|
]),
|
|
"[dblclick] correct linestring"
|
|
);
|
|
|
|
// mock up sketch cancel
|
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
|
handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
|
|
handler.deactivate();
|
|
t.eq(log.type, "cancel", "[deactivate while drawing] cancel called");
|
|
|
|
map.destroy();
|
|
}
|
|
|
|
function test_Handler_Path_destroy(t) {
|
|
t.plan(6);
|
|
var map = new OpenLayers.Map('map');
|
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
|
map.zoomToMaxExtent();
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.Path(control, {foo: 'bar'});
|
|
|
|
handler.activate();
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.mousedown(evt);
|
|
|
|
t.ok(handler.layer,
|
|
"handler has a layer prior to destroy");
|
|
t.ok(handler.point,
|
|
"handler has a point prior to destroy");
|
|
t.ok(handler.line,
|
|
"handler has a line prior to destroy");
|
|
handler.destroy();
|
|
t.eq(handler.layer, null,
|
|
"handler.layer is null after destroy");
|
|
t.eq(handler.point, null,
|
|
"handler.point is null after destroy");
|
|
t.eq(handler.line, null,
|
|
"handler.line is null after destroy");
|
|
map.destroy();
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 300px; height: 150px;"/>
|
|
</body>
|
|
</html>
|