Adding support for a modify callback in the sketch handlers. This lets controls know about each sketch modification as a sketch is being drawn. Also a bit of a refactor of the sketch handlers to share sketch geometry parts. r=ahocevar (closes #1903)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8831 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -30,18 +30,20 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
||||
* Create a Polygon Handler.
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>}
|
||||
* callbacks - {Object} An object with a 'done' property whos value is
|
||||
* a function to be called when the path drawing is
|
||||
* finished. The callback should expect to recieve a
|
||||
* single argument, the polygon geometry.
|
||||
* If the callbacks object contains a 'point'
|
||||
* property, this function will be sent each point
|
||||
* as they are added. 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}
|
||||
* control - {<OpenLayers.Control>} The control that owns this handler
|
||||
* callbacks - {Object} An object with a properties whose values are
|
||||
* functions. Various callbacks described below.
|
||||
* options - {Object} An optional object with properties to be set on the
|
||||
* handler
|
||||
*
|
||||
* Named callbacks:
|
||||
* done - Called when the point drawing is finished. The callback will
|
||||
* recieve a single argument, the polygon geometry.
|
||||
* point - Called as each point is added. Receives the new point geometry.
|
||||
* modify - Called with each move of a vertex with the vertex (point)
|
||||
* geometry and the sketch feature.
|
||||
* cancel - Called when the handler is deactivated while drawing. The
|
||||
* cancel callback will receive a geometry.
|
||||
*/
|
||||
initialize: function(control, callbacks, options) {
|
||||
OpenLayers.Handler.Path.prototype.initialize.apply(this, arguments);
|
||||
@@ -50,15 +52,22 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
||||
/**
|
||||
* Method: createFeature
|
||||
* Add temporary geometries
|
||||
*
|
||||
* Parameters:
|
||||
* pixel - {<OpenLayers.Pixel>} The initial pixel location for the new
|
||||
* feature.
|
||||
*/
|
||||
createFeature: function() {
|
||||
this.polygon = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Polygon());
|
||||
this.line = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.LinearRing());
|
||||
this.polygon.geometry.addComponent(this.line.geometry);
|
||||
createFeature: function(pixel) {
|
||||
var lonlat = this.control.map.getLonLatFromPixel(pixel);
|
||||
this.point = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point());
|
||||
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
|
||||
);
|
||||
this.line = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.LinearRing([this.point.geometry])
|
||||
);
|
||||
this.polygon = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Polygon([this.line.geometry])
|
||||
);
|
||||
this.layer.addFeatures([this.polygon, this.point], {silent: true});
|
||||
},
|
||||
|
||||
@@ -71,18 +80,6 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
||||
this.polygon = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: modifyFeature
|
||||
* Modify the existing geometry given the new point
|
||||
*
|
||||
*/
|
||||
modifyFeature: function() {
|
||||
var index = this.line.geometry.components.length - 2;
|
||||
this.line.geometry.components[index].x = this.point.geometry.x;
|
||||
this.line.geometry.components[index].y = this.point.geometry.y;
|
||||
this.line.geometry.components[index].clearBounds();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawFeature
|
||||
* Render geometries on the temporary layer.
|
||||
@@ -92,6 +89,17 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
||||
this.layer.drawFeature(this.point, this.style);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getSketch
|
||||
* Return the sketch feature.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Feature.Vector>}
|
||||
*/
|
||||
getSketch: function() {
|
||||
return this.polygon;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getGeometry
|
||||
* Return the sketch geometry. If <multi> is true, this will return
|
||||
@@ -121,9 +129,7 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, {
|
||||
// remove the penultimate point
|
||||
var index = this.line.geometry.components.length - 2;
|
||||
this.line.geometry.removeComponent(this.line.geometry.components[index]);
|
||||
if(this.persist) {
|
||||
this.destroyPoint();
|
||||
}
|
||||
this.removePoint();
|
||||
this.finalize();
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user