3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
6 function test_initialze(t) {
10 var map = new OpenLayers.Map("map");
11 var control = new OpenLayers.Control.Measure(
12 OpenLayers.Handler.Path, {persist: true}
14 map.addControl(control);
16 t.eq(control.persist, true, "passing persist to constructor sets persist on handler");
22 function test_cancel(t) {
26 var map = new OpenLayers.Map("map");
27 var layer = new OpenLayers.Layer(null, {
31 map.zoomToMaxExtent();
33 var control = new OpenLayers.Control.Measure(
34 OpenLayers.Handler.Path, {persist: true}
36 map.addControl(control);
42 t.ok(true, "calling cancel before drawing works");
44 t.fail("calling cancel before drawing causes trouble: " + err);
46 t.eq(control.active, true, "control remains active after cancel");
48 // create a simple measurement
49 function trigger(type, x, y) {
50 map.events.triggerEvent(type, {
51 xy: new OpenLayers.Pixel(x, y)
54 trigger("mousedown", 0, 0);
55 trigger("mouseup", 0, 0);
56 trigger("mousemove", 10, 10);
57 trigger("mousedown", 10, 10);
58 trigger("mouseup", 10, 10);
60 // confirm that the sketch persists
61 t.eq(control.handler.layer.features.length, 1, "feature persists");
62 // cancel and see that sketch is gone
64 t.eq(control.handler.layer.features.length, 0, "feature is gone after cancel");
73 <div id="map" style="width: 512px; height: 256px;"></div>