Merge pull request #143 from jorix/stop-freehand
Handler.Path: Stop freehand using "maxVertices"
This commit is contained in:
@@ -30,8 +30,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
* APIProperty: maxVertices
|
* APIProperty: maxVertices
|
||||||
* {Number} The maximum number of vertices which can be drawn by this
|
* {Number} The maximum number of vertices which can be drawn by this
|
||||||
* handler. When the number of vertices reaches maxVertices, the
|
* handler. When the number of vertices reaches maxVertices, the
|
||||||
* geometry is automatically finalized. This property doesn't
|
* geometry is automatically finalized. Default is null.
|
||||||
* apply if freehand is set. Default is null.
|
|
||||||
*/
|
*/
|
||||||
maxVertices: null,
|
maxVertices: null,
|
||||||
|
|
||||||
@@ -446,7 +445,13 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
if(this.persist) {
|
if(this.persist) {
|
||||||
this.destroyPersistedFeature();
|
this.destroyPersistedFeature();
|
||||||
}
|
}
|
||||||
this.addPoint(evt.xy);
|
if(this.maxVertices && this.line &&
|
||||||
|
this.line.geometry.components.length === this.maxVertices) {
|
||||||
|
this.removePoint()
|
||||||
|
this.finalize();
|
||||||
|
} else {
|
||||||
|
this.addPoint(evt.xy);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!this.touch && (!this.mouseDown || this.stoppedDown)) {
|
if (!this.touch && (!this.mouseDown || this.stoppedDown)) {
|
||||||
|
|||||||
@@ -534,6 +534,43 @@
|
|||||||
map.destroy();
|
map.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_freehand_maxVertices(t) {
|
||||||
|
t.plan(1);
|
||||||
|
var map = new OpenLayers.Map("map", {
|
||||||
|
resolutions: [1]
|
||||||
|
});
|
||||||
|
var layer = new OpenLayers.Layer.Vector("foo", {
|
||||||
|
maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
|
||||||
|
isBaseLayer: true
|
||||||
|
});
|
||||||
|
map.addLayer(layer);
|
||||||
|
var control = new OpenLayers.Control({});
|
||||||
|
var log = {};
|
||||||
|
var MAX_VERTICES = 2;
|
||||||
|
var doneCallback = function(geo) {
|
||||||
|
t.eq(geo.components.length, MAX_VERTICES,
|
||||||
|
'When maxVertices is reached, the geometry is finalized automatically');
|
||||||
|
};
|
||||||
|
var handler = new OpenLayers.Handler.Path(control,
|
||||||
|
{'done': doneCallback},
|
||||||
|
{freehand: true,
|
||||||
|
maxVertices: MAX_VERTICES});
|
||||||
|
control.handler = handler;
|
||||||
|
map.addControl(control);
|
||||||
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
|
|
||||||
|
// mock up feature freehand drawing
|
||||||
|
handler.activate();
|
||||||
|
var evt = {xy: new OpenLayers.Pixel(0, 0)};
|
||||||
|
handler.mousemove(evt);
|
||||||
|
handler.mousedown(evt);
|
||||||
|
evt = {xy: new OpenLayers.Pixel(20, 20)};
|
||||||
|
handler.mousemove(evt);
|
||||||
|
evt = {xy: new OpenLayers.Pixel(40, 40)};
|
||||||
|
handler.mousemove(evt);
|
||||||
|
map.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper functions for editing method tests
|
* Helper functions for editing method tests
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user