new "immediate" option to enable live measuring while moving the mouse. p=patzi,me r=me (closes #2935)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10917 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -33,7 +33,8 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
* will receive an event with measure, units, order, and geometry
|
||||
* properties.
|
||||
* measurepartial - Triggered when a new point is added to the
|
||||
* measurement sketch. Listeners receive an event with measure,
|
||||
* measurement sketch or if the <immediate> property is true and the
|
||||
* measurement sketch is modified. Listeners receive an event with measure,
|
||||
* units, order, and geometry.
|
||||
*/
|
||||
EVENT_TYPES: ['measure', 'measurepartial'],
|
||||
@@ -103,6 +104,14 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
*/
|
||||
persist: false,
|
||||
|
||||
/**
|
||||
* APIProperty: immediate
|
||||
* {Boolean} Activates the immediate measurement so that the "measurepartial"
|
||||
* event is also fired once the measurement sketch is modified.
|
||||
* Default is false.
|
||||
*/
|
||||
immediate : false,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.Measure
|
||||
*
|
||||
@@ -117,10 +126,12 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.callbacks = OpenLayers.Util.extend(
|
||||
{done: this.measureComplete, point: this.measurePartial},
|
||||
this.callbacks
|
||||
);
|
||||
var callbacks = {done: this.measureComplete,
|
||||
point: this.measurePartial};
|
||||
if (this.immediate){
|
||||
callbacks.modify = this.measureImmediate;
|
||||
}
|
||||
this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks);
|
||||
|
||||
// let the handler options override, so old code that passes 'persist'
|
||||
// directly to the handler does not need an update
|
||||
@@ -147,6 +158,20 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
this.cancelDelay();
|
||||
this.handler.cancel();
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: setImmediate
|
||||
* Set <persist> is true, the temporary
|
||||
* sketch will be erased.
|
||||
*/
|
||||
setImmediate: function(immediate) {
|
||||
this.immediate = immediate;
|
||||
if (this.immediate){
|
||||
this.callbacks.modify = this.measureImmediate;
|
||||
} else {
|
||||
delete this.callbacks.modify;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: updateHandler
|
||||
@@ -205,6 +230,20 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: measureImmediate
|
||||
* Called each time the measurement sketch is modified.
|
||||
*
|
||||
* Parameters: point - {<OpenLayers.Geometry.Point>} The point at the
|
||||
* mouseposition. feature - {<OpenLayers.Feature.Vector>} The sketch feature.
|
||||
*/
|
||||
measureImmediate : function(point, feature) {
|
||||
if (this.delayedTrigger === null &&
|
||||
!this.handler.freehandMode(this.handler.evt)) {
|
||||
this.measure(feature.geometry, "measurepartial");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: cancelDelay
|
||||
* Cancels the delay measurement that measurePartial began.
|
||||
|
||||
Reference in New Issue
Block a user