Adding a 'sketchstarted' event on the vector layer. This event is triggered at the start of each new sketch. r=ahocevar (closes #1945)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9269 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -37,7 +37,9 @@
|
|||||||
"featuremodified": report,
|
"featuremodified": report,
|
||||||
"afterfeaturemodified": report,
|
"afterfeaturemodified": report,
|
||||||
"vertexmodified": report,
|
"vertexmodified": report,
|
||||||
"sketchmodified": report
|
"sketchmodified": report,
|
||||||
|
"sketchstarted": report,
|
||||||
|
"sketchcomplete": report
|
||||||
});
|
});
|
||||||
controls = {
|
controls = {
|
||||||
point: new OpenLayers.Control.DrawFeature(vectors,
|
point: new OpenLayers.Control.DrawFeature(vectors,
|
||||||
|
|||||||
@@ -74,6 +74,11 @@ OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
this.layer.events.triggerEvent(
|
this.layer.events.triggerEvent(
|
||||||
"sketchmodified", {vertex: vertex, feature: feature}
|
"sketchmodified", {vertex: vertex, feature: feature}
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
create: function(vertex, feature) {
|
||||||
|
this.layer.events.triggerEvent(
|
||||||
|
"sketchstarted", {vertex: vertex, feature: feature}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
this.callbacks
|
this.callbacks
|
||||||
|
|||||||
@@ -55,11 +55,13 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
* handler
|
* handler
|
||||||
*
|
*
|
||||||
* Named callbacks:
|
* Named callbacks:
|
||||||
* done - Called when the point drawing is finished. The callback will
|
* create - Called when a sketch is first created. Callback called with
|
||||||
* recieve a single argument, the linestring geometry.
|
* the creation point geometry and sketch feature.
|
||||||
* point - Called as each point is added. Receives the new point geometry.
|
|
||||||
* modify - Called with each move of a vertex with the vertex (point)
|
* modify - Called with each move of a vertex with the vertex (point)
|
||||||
* geometry and the sketch feature.
|
* geometry and the sketch feature.
|
||||||
|
* point - Called as each point is added. Receives the new point geometry.
|
||||||
|
* done - Called when the point drawing is finished. The callback will
|
||||||
|
* recieve a single argument, the linestring geometry.
|
||||||
* cancel - Called when the handler is deactivated while drawing. The
|
* cancel - Called when the handler is deactivated while drawing. The
|
||||||
* cancel callback will receive a geometry.
|
* cancel callback will receive a geometry.
|
||||||
*/
|
*/
|
||||||
@@ -83,6 +85,8 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
|||||||
this.line = new OpenLayers.Feature.Vector(
|
this.line = new OpenLayers.Feature.Vector(
|
||||||
new OpenLayers.Geometry.LineString([this.point.geometry])
|
new OpenLayers.Geometry.LineString([this.point.geometry])
|
||||||
);
|
);
|
||||||
|
this.callback("create", [this.point.geometry, this.getSketch()]);
|
||||||
|
this.point.geometry.clearBounds();
|
||||||
this.layer.addFeatures([this.line, this.point], {silent: true});
|
this.layer.addFeatures([this.line, this.point], {silent: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -92,10 +92,12 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
* handler
|
* handler
|
||||||
*
|
*
|
||||||
* Named callbacks:
|
* Named callbacks:
|
||||||
* done - Called when the point drawing is finished. The callback will
|
* create - Called when a sketch is first created. Callback called with
|
||||||
* recieve a single argument, the point geometry.
|
* the creation point geometry and sketch feature.
|
||||||
* modify - Called with each move of a vertex with the vertex (point)
|
* modify - Called with each move of a vertex with the vertex (point)
|
||||||
* geometry and the sketch feature.
|
* geometry and the sketch feature.
|
||||||
|
* done - Called when the point drawing is finished. The callback will
|
||||||
|
* recieve a single argument, the point geometry.
|
||||||
* cancel - Called when the handler is deactivated while drawing. The
|
* cancel - Called when the handler is deactivated while drawing. The
|
||||||
* cancel callback will receive a geometry.
|
* cancel callback will receive a geometry.
|
||||||
*/
|
*/
|
||||||
@@ -133,11 +135,17 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
/**
|
/**
|
||||||
* Method: createFeature
|
* Method: createFeature
|
||||||
* Add temporary features
|
* Add temporary features
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
|
||||||
*/
|
*/
|
||||||
createFeature: function() {
|
createFeature: function(pixel) {
|
||||||
|
var lonlat = this.map.getLonLatFromPixel(pixel);
|
||||||
this.point = new OpenLayers.Feature.Vector(
|
this.point = new OpenLayers.Feature.Vector(
|
||||||
new OpenLayers.Geometry.Point()
|
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
|
||||||
);
|
);
|
||||||
|
this.callback("create", [this.point.geometry, this.point]);
|
||||||
|
this.point.geometry.clearBounds();
|
||||||
this.layer.addFeatures([this.point], {silent: true});
|
this.layer.addFeatures([this.point], {silent: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -250,6 +258,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
this.point.geometry.y = lonlat.lat;
|
this.point.geometry.y = lonlat.lat;
|
||||||
this.callback("modify", [this.point.geometry, this.point]);
|
this.callback("modify", [this.point.geometry, this.point]);
|
||||||
this.point.geometry.clearBounds();
|
this.point.geometry.clearBounds();
|
||||||
|
this.drawFeature();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,16 +317,16 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
if(this.lastDown && this.lastDown.equals(evt.xy)) {
|
if(this.lastDown && this.lastDown.equals(evt.xy)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
this.drawing = true;
|
||||||
if(this.lastDown == null) {
|
if(this.lastDown == null) {
|
||||||
if(this.persist) {
|
if(this.persist) {
|
||||||
this.destroyFeature();
|
this.destroyFeature();
|
||||||
}
|
}
|
||||||
this.createFeature();
|
this.createFeature(evt.xy);
|
||||||
|
} else {
|
||||||
|
this.modifyFeature(evt.xy);
|
||||||
}
|
}
|
||||||
this.lastDown = evt.xy;
|
this.lastDown = evt.xy;
|
||||||
this.drawing = true;
|
|
||||||
this.modifyFeature(evt.xy);
|
|
||||||
this.drawFeature();
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -335,7 +344,6 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
|||||||
mousemove: function (evt) {
|
mousemove: function (evt) {
|
||||||
if(this.drawing) {
|
if(this.drawing) {
|
||||||
this.modifyFeature(evt.xy);
|
this.modifyFeature(evt.xy);
|
||||||
this.drawFeature();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -37,11 +37,13 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
|||||||
* handler
|
* handler
|
||||||
*
|
*
|
||||||
* Named callbacks:
|
* Named callbacks:
|
||||||
* done - Called when the point drawing is finished. The callback will
|
* create - Called when a sketch is first created. Callback called with
|
||||||
* recieve a single argument, the polygon geometry.
|
* the creation point geometry and sketch feature.
|
||||||
* point - Called as each point is added. Receives the new point geometry.
|
|
||||||
* modify - Called with each move of a vertex with the vertex (point)
|
* modify - Called with each move of a vertex with the vertex (point)
|
||||||
* geometry and the sketch feature.
|
* geometry and the sketch feature.
|
||||||
|
* point - Called as each point is added. Receives the new point geometry.
|
||||||
|
* done - Called when the point drawing is finished. The callback will
|
||||||
|
* recieve a single argument, the polygon geometry.
|
||||||
* cancel - Called when the handler is deactivated while drawing. The
|
* cancel - Called when the handler is deactivated while drawing. The
|
||||||
* cancel callback will receive a geometry.
|
* cancel callback will receive a geometry.
|
||||||
*/
|
*/
|
||||||
@@ -68,6 +70,8 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
|||||||
this.polygon = new OpenLayers.Feature.Vector(
|
this.polygon = new OpenLayers.Feature.Vector(
|
||||||
new OpenLayers.Geometry.Polygon([this.line.geometry])
|
new OpenLayers.Geometry.Polygon([this.line.geometry])
|
||||||
);
|
);
|
||||||
|
this.callback("create", [this.point.geometry, this.getSketch()]);
|
||||||
|
this.point.geometry.clearBounds();
|
||||||
this.layer.addFeatures([this.polygon, this.point], {silent: true});
|
this.layer.addFeatures([this.polygon, this.point], {silent: true});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -115,16 +115,19 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
|||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* control - {<OpenLayers.Control>} The control that owns this handler
|
* control - {<OpenLayers.Control>} The control that owns this handler
|
||||||
* callbacks - {Array} An object with a 'done' property whos value is a
|
* callbacks - {Object} An object with a properties whose values are
|
||||||
* function to be called when the polygon drawing is finished.
|
* functions. Various callbacks described below.
|
||||||
* The callback should expect to recieve a single argument,
|
|
||||||
* the polygon geometry. If the callbacks object contains a
|
|
||||||
* 'cancel' property, this function will be called when the
|
|
||||||
* handler is deactivated while drawing. The cancel should
|
|
||||||
* expect to receive a geometry.
|
|
||||||
* options - {Object} An object with properties to be set on the handler.
|
* options - {Object} An object with properties to be set on the handler.
|
||||||
* If the options.sides property is not specified, the number of sides
|
* If the options.sides property is not specified, the number of sides
|
||||||
* will default to 4.
|
* will default to 4.
|
||||||
|
*
|
||||||
|
* Named callbacks:
|
||||||
|
* create - Called when a sketch is first created. Callback called with
|
||||||
|
* the creation point geometry and sketch feature.
|
||||||
|
* done - Called when the sketch drawing is finished. The callback will
|
||||||
|
* recieve a single argument, the sketch geometry.
|
||||||
|
* cancel - Called when the handler is deactivated while drawing. The
|
||||||
|
* cancel callback will receive a geometry.
|
||||||
*/
|
*/
|
||||||
initialize: function(control, callbacks, options) {
|
initialize: function(control, callbacks, options) {
|
||||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||||
@@ -225,6 +228,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
|||||||
}
|
}
|
||||||
this.feature = new OpenLayers.Feature.Vector();
|
this.feature = new OpenLayers.Feature.Vector();
|
||||||
this.createGeometry();
|
this.createGeometry();
|
||||||
|
this.callback("create", [this.origin, this.feature]);
|
||||||
this.layer.addFeatures([this.feature], {silent: true});
|
this.layer.addFeatures([this.feature], {silent: true});
|
||||||
this.layer.drawFeature(this.feature, this.style);
|
this.layer.drawFeature(this.feature, this.style);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -81,9 +81,14 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
* property referencing the vertex modified (always a point geometry),
|
* property referencing the vertex modified (always a point geometry),
|
||||||
* and a *pixel* property referencing the pixel location of the
|
* and a *pixel* property referencing the pixel location of the
|
||||||
* modification.
|
* modification.
|
||||||
|
* sketchstarted - Triggered when a feature sketch bound for this layer
|
||||||
|
* is started. Listeners will receive an object with a *feature*
|
||||||
|
* property referencing the new sketch feature and a *vertex* property
|
||||||
|
* referencing the creation point.
|
||||||
* sketchmodified - Triggered when a feature sketch bound for this layer
|
* sketchmodified - Triggered when a feature sketch bound for this layer
|
||||||
* is modified. Listeners will receive an object with a *vertex*
|
* is modified. Listeners will receive an object with a *vertex*
|
||||||
* property referencing the modified vertex.
|
* property referencing the modified vertex and a *feature* property
|
||||||
|
* referencing the sketch feature.
|
||||||
* sketchcomplete - Triggered when a feature sketch bound for this layer
|
* sketchcomplete - Triggered when a feature sketch bound for this layer
|
||||||
* is complete. Listeners will receive an object with a *feature*
|
* is complete. Listeners will receive an object with a *feature*
|
||||||
* property referencing the sketch feature. By returning false, a
|
* property referencing the sketch feature. By returning false, a
|
||||||
@@ -96,8 +101,8 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
|||||||
"beforefeatureremoved", "featureremoved", "featuresremoved",
|
"beforefeatureremoved", "featureremoved", "featuresremoved",
|
||||||
"beforefeatureselected", "featureselected", "featureunselected",
|
"beforefeatureselected", "featureselected", "featureunselected",
|
||||||
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
|
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
|
||||||
"vertexmodified", "sketchmodified", "sketchcomplete",
|
"vertexmodified", "sketchstarted", "sketchmodified",
|
||||||
"refresh"],
|
"sketchcomplete", "refresh"],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: isBaseLayer
|
* APIProperty: isBaseLayer
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_sketch_events(t) {
|
function test_sketch_events(t) {
|
||||||
t.plan(4);
|
t.plan(6);
|
||||||
var map = new OpenLayers.Map("map", {
|
var map = new OpenLayers.Map("map", {
|
||||||
resolutions: [1]
|
resolutions: [1]
|
||||||
});
|
});
|
||||||
@@ -50,6 +50,9 @@
|
|||||||
|
|
||||||
var log = {};
|
var log = {};
|
||||||
layer.events.on({
|
layer.events.on({
|
||||||
|
sketchstarted: function(event) {
|
||||||
|
log.event = event;
|
||||||
|
},
|
||||||
sketchmodified: function(event) {
|
sketchmodified: function(event) {
|
||||||
log.event = event;
|
log.event = event;
|
||||||
},
|
},
|
||||||
@@ -60,6 +63,8 @@
|
|||||||
|
|
||||||
// mock up draw/modify of a point
|
// mock up draw/modify of a point
|
||||||
map.events.triggerEvent("mousedown", {xy: new OpenLayers.Pixel(0, 0)});
|
map.events.triggerEvent("mousedown", {xy: new OpenLayers.Pixel(0, 0)});
|
||||||
|
t.eq(log.event.type, "sketchstarted", "[mousedown] sketchstarted triggered");
|
||||||
|
t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousedown] correct vertex");
|
||||||
map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(10, 10)});
|
map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(10, 10)});
|
||||||
t.eq(log.event.type, "sketchmodified", "[mousemove] sketchmodified triggered");
|
t.eq(log.event.type, "sketchmodified", "[mousemove] sketchmodified triggered");
|
||||||
t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
|
t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_callbacks(t) {
|
function test_callbacks(t) {
|
||||||
t.plan(12);
|
t.plan(15);
|
||||||
var map = new OpenLayers.Map("map", {
|
var map = new OpenLayers.Map("map", {
|
||||||
resolutions: [1]
|
resolutions: [1]
|
||||||
});
|
});
|
||||||
@@ -83,6 +83,10 @@
|
|||||||
});
|
});
|
||||||
var log = {};
|
var log = {};
|
||||||
var handler = new OpenLayers.Handler.Path(control, {
|
var handler = new OpenLayers.Handler.Path(control, {
|
||||||
|
create: function() {
|
||||||
|
log.type = "create",
|
||||||
|
log.args = arguments
|
||||||
|
},
|
||||||
modify: function() {
|
modify: function() {
|
||||||
log.type = "modify",
|
log.type = "modify",
|
||||||
log.args = arguments
|
log.args = arguments
|
||||||
@@ -103,6 +107,9 @@
|
|||||||
// mock up feature drawing
|
// mock up feature drawing
|
||||||
handler.activate();
|
handler.activate();
|
||||||
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
||||||
|
t.eq(log.type, "create", "[mousedown] create called");
|
||||||
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
|
||||||
|
t.ok(log.args[1] === handler.line, "[mousedown] correct sketch feature");
|
||||||
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
||||||
t.eq(log.type, "modify", "[mouseup] modify called");
|
t.eq(log.type, "modify", "[mouseup] modify called");
|
||||||
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
|
||||||
|
|||||||
@@ -112,6 +112,10 @@
|
|||||||
});
|
});
|
||||||
var log = {};
|
var log = {};
|
||||||
var handler = new OpenLayers.Handler.Point(control, {
|
var handler = new OpenLayers.Handler.Point(control, {
|
||||||
|
create: function() {
|
||||||
|
log.type = "create",
|
||||||
|
log.args = arguments
|
||||||
|
},
|
||||||
modify: function() {
|
modify: function() {
|
||||||
log.type = "modify",
|
log.type = "modify",
|
||||||
log.args = arguments
|
log.args = arguments
|
||||||
@@ -132,7 +136,7 @@
|
|||||||
// mock up feature drawing
|
// mock up feature drawing
|
||||||
handler.activate();
|
handler.activate();
|
||||||
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
||||||
t.eq(log.type, "modify", "[mousedown] modify called");
|
t.eq(log.type, "create", "[mousedown] create called");
|
||||||
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct point");
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct point");
|
||||||
t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct sketch feature");
|
t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct sketch feature");
|
||||||
handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 0)});
|
handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 0)});
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_callbacks(t) {
|
function test_callbacks(t) {
|
||||||
t.plan(12);
|
t.plan(15);
|
||||||
var map = new OpenLayers.Map("map", {
|
var map = new OpenLayers.Map("map", {
|
||||||
resolutions: [1]
|
resolutions: [1]
|
||||||
});
|
});
|
||||||
@@ -85,6 +85,10 @@
|
|||||||
});
|
});
|
||||||
var log = {};
|
var log = {};
|
||||||
var handler = new OpenLayers.Handler.Polygon(control, {
|
var handler = new OpenLayers.Handler.Polygon(control, {
|
||||||
|
create: function() {
|
||||||
|
log.type = "create",
|
||||||
|
log.args = arguments
|
||||||
|
},
|
||||||
modify: function() {
|
modify: function() {
|
||||||
log.type = "modify",
|
log.type = "modify",
|
||||||
log.args = arguments
|
log.args = arguments
|
||||||
@@ -106,6 +110,9 @@
|
|||||||
handler.activate();
|
handler.activate();
|
||||||
// click at 0, 0
|
// click at 0, 0
|
||||||
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
|
||||||
|
t.eq(log.type, "create", "[mousedown] create called");
|
||||||
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
|
||||||
|
t.ok(log.args[1] === handler.polygon, "[mousedown] correct sketch feature");
|
||||||
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
|
||||||
t.eq(log.type, "modify", "[mouseup] modify called");
|
t.eq(log.type, "modify", "[mouseup] modify called");
|
||||||
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
|
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
|
||||||
|
|||||||
Reference in New Issue
Block a user