3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_initialize(t) {
8 var control = new OpenLayers.Control.DrawFeature("foo", function() {});
9 t.ok(control instanceof OpenLayers.Control.DrawFeature,
10 "constructor returns an instance");
11 t.ok(OpenLayers.Util.indexOf(control.EVENT_TYPES, "featureadded") > -1,
12 "featureadded event in EVENT_TYPES");
15 function test_drawFeature(t) {
17 var layer = new OpenLayers.Layer.Vector();
18 var control = new OpenLayers.Control.DrawFeature(layer, function() {});
21 layer.addFeatures = function(features) {
22 t.ok(features[0].geometry == geom, "layer.addFeatures called");
23 t.eq(features[0].state, OpenLayers.State.INSERT, "layer state set");
25 function handlefeatureadded(event) {
26 t.ok(event.feature.geometry == geom, "featureadded triggered");
28 control.events.on({"featureadded": handlefeatureadded});
29 control.drawFeature(geom);
30 control.events.un({"featureadded": handlefeatureadded});
34 function test_sketch_events(t) {
36 var map = new OpenLayers.Map("map", {
39 var layer = new OpenLayers.Layer.Vector("foo", {
40 maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
43 var control = new OpenLayers.Control.DrawFeature(
44 layer, OpenLayers.Handler.Point
47 map.addControl(control);
48 map.zoomToMaxExtent();
53 sketchstarted: function(event) {
56 sketchmodified: function(event) {
59 sketchcomplete: function(event) {
64 // mock up draw/modify of a point
65 map.events.triggerEvent("mousedown", {xy: new OpenLayers.Pixel(0, 0)});
66 t.eq(log.event.type, "sketchstarted", "[mousedown] sketchstarted triggered");
67 t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousedown] correct vertex");
68 map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(10, 10)});
69 t.eq(log.event.type, "sketchmodified", "[mousemove] sketchmodified triggered");
70 t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
71 map.events.triggerEvent("mouseup", {xy: new OpenLayers.Pixel(10, 10)});
72 t.eq(log.event.type, "sketchcomplete", "[mouseup] sketchcomplete triggered");
73 t.geom_eq(log.event.feature.geometry, new OpenLayers.Geometry.Point(-190, 115), "[mouseup] correct geometry");
81 <div id="map" style="width: 400px; height: 250px;"/>