Adding a persist option to the measure control. This passes the same to the sketch handler. The cancel method on the control calls the same on the handler. Patch from dwins. Tests from me. r=me (closes #2029)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9225 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
75
tests/Control/Measure.html
Normal file
75
tests/Control/Measure.html
Normal file
@@ -0,0 +1,75 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialze(t) {
|
||||
|
||||
t.plan(1);
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var control = new OpenLayers.Control.Measure(
|
||||
OpenLayers.Handler.Path, {persist: true}
|
||||
);
|
||||
map.addControl(control);
|
||||
|
||||
t.eq(control.persist, true, "passing persist to constructor sets persist on handler");
|
||||
|
||||
map.destroy();
|
||||
|
||||
}
|
||||
|
||||
function test_cancel(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var map = new OpenLayers.Map("map");
|
||||
var layer = new OpenLayers.Layer(null, {
|
||||
isBaseLayer: true
|
||||
});
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
var control = new OpenLayers.Control.Measure(
|
||||
OpenLayers.Handler.Path, {persist: true}
|
||||
);
|
||||
map.addControl(control);
|
||||
|
||||
control.activate();
|
||||
|
||||
try {
|
||||
control.cancel();
|
||||
t.ok(true, "calling cancel before drawing works");
|
||||
} catch(err) {
|
||||
t.fail("calling cancel before drawing causes trouble: " + err);
|
||||
}
|
||||
t.eq(control.active, true, "control remains active after cancel");
|
||||
|
||||
// create a simple measurement
|
||||
function trigger(type, x, y) {
|
||||
map.events.triggerEvent(type, {
|
||||
xy: new OpenLayers.Pixel(x, y)
|
||||
})
|
||||
};
|
||||
trigger("mousedown", 0, 0);
|
||||
trigger("mouseup", 0, 0);
|
||||
trigger("mousemove", 10, 10);
|
||||
trigger("mousedown", 10, 10);
|
||||
trigger("mouseup", 10, 10);
|
||||
|
||||
// confirm that the sketch persists
|
||||
t.eq(control.handler.layer.features.length, 1, "feature persists");
|
||||
// cancel and see that sketch is gone
|
||||
control.cancel();
|
||||
t.eq(control.handler.layer.features.length, 0, "feature is gone after cancel");
|
||||
|
||||
map.destroy();
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width: 512px; height: 256px;"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user