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:
@@ -11,9 +11,11 @@
|
||||
/**
|
||||
* Class: OpenLayers.Handler.Point
|
||||
* Handler to draw a point on the map. Point is displayed on mouse down,
|
||||
* moves on mouse move, and is finished on mouse up. The handler triggers
|
||||
* callbacks for 'done' and 'cancel'. Create a new instance with the
|
||||
* <OpenLayers.Handler.Point> constructor.
|
||||
* moves on mouse move, and is finished on mouse up. The handler triggers
|
||||
* callbacks for 'done', 'cancel', and 'modify'. The modify callback is
|
||||
* called with each change in the sketc and will receive the latest point
|
||||
* drawn. Create a new instance with the <OpenLayers.Handler.Point>
|
||||
* constructor.
|
||||
*
|
||||
* Inherits from:
|
||||
* - <OpenLayers.Handler>
|
||||
@@ -84,19 +86,23 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*
|
||||
* Parameters:
|
||||
* control - {<OpenLayers.Control>} The control that owns this handler
|
||||
* callbacks - {Object} An object with a 'done' property whose value is a
|
||||
* function to be called when the point drawing is finished.
|
||||
* The callback should expect to recieve a single argument,
|
||||
* the point 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.
|
||||
* 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 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) {
|
||||
// TBD: deal with style
|
||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||
if(!(options && options.layerOptions && options.layerOptions.styleMap)) {
|
||||
this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {});
|
||||
}
|
||||
|
||||
OpenLayers.Handler.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
@@ -231,6 +237,21 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: modifyFeature
|
||||
* Modify the existing geometry given a pixel location.
|
||||
*
|
||||
* Parameters:
|
||||
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
|
||||
*/
|
||||
modifyFeature: function(pixel) {
|
||||
var lonlat = this.map.getLonLatFromPixel(pixel);
|
||||
this.point.geometry.x = lonlat.lon;
|
||||
this.point.geometry.y = lonlat.lat;
|
||||
this.callback("modify", [this.point.geometry, this.point]);
|
||||
this.point.geometry.clearBounds();
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: drawFeature
|
||||
* Render features on the temporary layer.
|
||||
@@ -294,10 +315,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
}
|
||||
this.lastDown = evt.xy;
|
||||
this.drawing = true;
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.geometry.x = lonlat.lon;
|
||||
this.point.geometry.y = lonlat.lat;
|
||||
this.point.geometry.clearBounds();
|
||||
this.modifyFeature(evt.xy);
|
||||
this.drawFeature();
|
||||
return false;
|
||||
},
|
||||
@@ -315,10 +333,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.geometry.x = lonlat.lon;
|
||||
this.point.geometry.y = lonlat.lat;
|
||||
this.point.geometry.clearBounds();
|
||||
this.modifyFeature(evt.xy);
|
||||
this.drawFeature();
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user