diff --git a/lib/OpenLayers/Control/Measure.js b/lib/OpenLayers/Control/Measure.js index ced97b917d..3c092fa36f 100644 --- a/lib/OpenLayers/Control/Measure.js +++ b/lib/OpenLayers/Control/Measure.js @@ -180,6 +180,7 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, { */ measurePartial: function(point, geometry) { if (geometry.getLength() > 0) { + geometry = geometry.clone(); this.delayedTrigger = window.setTimeout( OpenLayers.Function.bind(function() { this.measure(geometry, "measurepartial"); diff --git a/tests/Control/Measure.html b/tests/Control/Measure.html index 279269ae72..29fefe500d 100644 --- a/tests/Control/Measure.html +++ b/tests/Control/Measure.html @@ -19,6 +19,7 @@ } + // test for function test_cancel(t) { t.plan(4); @@ -67,6 +68,52 @@ } + function test_partial(t) { + t.plan(1); + + // set up + + var map, layer, control, geometry, log; + + map = new OpenLayers.Map("map", {units: "m"}); + + layer = new OpenLayers.Layer(null, {isBaseLayer: true}); + map.addLayer(layer); + + map.zoomToMaxExtent(); + + control = new OpenLayers.Control.Measure(OpenLayers.Handler.Path, { + partialDelay: null + }); + + map.addControl(control); + control.activate(); + + control.events.on({ + "measurepartial": function(e) { + log.measure = e.measure; + } + }); + + // test + + geometry = new OpenLayers.Geometry.LineString([ + new OpenLayers.Geometry.Point(1, 1), + new OpenLayers.Geometry.Point(2, 1) + ]); + + log = {}; + control.measurePartial(null, geometry); + geometry.components[1].x = 3; + t.delay_call(0.2, function() { + + t.eq(log.measure, 1, "partial measure is correct"); + + // tear down + map.destroy + }); + }; +