Sketch handler updates. Patch by tschaub, review elemoine (Closes #1698)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@7964 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -32,6 +32,13 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
layer: null,
|
||||
|
||||
/**
|
||||
* Property: multi
|
||||
* {Boolean} Cast features to multi-part geometries before passing to the
|
||||
* layer. Default is false.
|
||||
*/
|
||||
multi: false,
|
||||
|
||||
/**
|
||||
* Property: drawing
|
||||
* {Boolean} A point is being drawn
|
||||
@@ -56,6 +63,21 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
lastUp: null,
|
||||
|
||||
/**
|
||||
* APIProperty: persist
|
||||
* {Boolean} Leave the feature rendered until destroyFeature is called.
|
||||
* Default is false. If set to true, the feature remains rendered until
|
||||
* destroyFeature is called, typically by deactivating the handler or
|
||||
* starting another drawing.
|
||||
*/
|
||||
persist: false,
|
||||
|
||||
/**
|
||||
* Property: layerOptions
|
||||
* {Object} Any optional properties to be set on the sketch layer.
|
||||
*/
|
||||
layerOptions: null,
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Handler.Point
|
||||
* Create a new point handler.
|
||||
@@ -89,14 +111,14 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
}
|
||||
// create temporary vector layer for rendering geometry sketch
|
||||
// TBD: this could be moved to initialize/destroy - setting visibility here
|
||||
var options = {
|
||||
var options = OpenLayers.Util.extend({
|
||||
displayInLayerSwitcher: false,
|
||||
// indicate that the temp vector layer will never be out of range
|
||||
// without this, resolution properties must be specified at the
|
||||
// map-level for this temporary layer to init its resolutions
|
||||
// correctly
|
||||
calculateInRange: function() { return true; }
|
||||
};
|
||||
}, this.layerOptions);
|
||||
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
|
||||
this.map.addLayer(this.layer);
|
||||
return true;
|
||||
@@ -108,7 +130,9 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
*/
|
||||
createFeature: function() {
|
||||
this.point = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point());
|
||||
new OpenLayers.Geometry.Point()
|
||||
);
|
||||
this.layer.addFeatures([this.point], {silent: true});
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -123,6 +147,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
if(this.drawing) {
|
||||
this.cancel();
|
||||
}
|
||||
this.destroyFeature();
|
||||
// If a layer's map property is set to null, it means that that layer
|
||||
// isn't added to the map. Since we ourself added the layer to the map
|
||||
// in activate(), we can assume that if this.layer.map is null it means
|
||||
@@ -140,8 +165,8 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* Destroy the temporary geometries
|
||||
*/
|
||||
destroyFeature: function() {
|
||||
if(this.point) {
|
||||
this.point.destroy();
|
||||
if(this.layer) {
|
||||
this.layer.destroyFeatures();
|
||||
}
|
||||
this.point = null;
|
||||
},
|
||||
@@ -149,15 +174,21 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
/**
|
||||
* Method: finalize
|
||||
* Finish the geometry and call the "done" callback.
|
||||
*
|
||||
* Parameters:
|
||||
* cancel - {Boolean} Call cancel instead of done callback. Default is
|
||||
* false.
|
||||
*/
|
||||
finalize: function() {
|
||||
this.layer.renderer.clear();
|
||||
finalize: function(cancel) {
|
||||
var key = cancel ? "cancel" : "done";
|
||||
this.drawing = false;
|
||||
this.mouseDown = false;
|
||||
this.lastDown = null;
|
||||
this.lastUp = null;
|
||||
this.callback("done", [this.geometryClone()]);
|
||||
this.destroyFeature();
|
||||
this.callback(key, [this.geometryClone()]);
|
||||
if(cancel || !this.persist) {
|
||||
this.destroyFeature();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -165,13 +196,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
* Finish the geometry and call the "cancel" callback.
|
||||
*/
|
||||
cancel: function() {
|
||||
this.layer.renderer.clear();
|
||||
this.drawing = false;
|
||||
this.mouseDown = false;
|
||||
this.lastDown = null;
|
||||
this.lastUp = null;
|
||||
this.callback("cancel", [this.geometryClone()]);
|
||||
this.destroyFeature();
|
||||
this.finalize(true);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -215,14 +240,30 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: geometryClone
|
||||
* Return a clone of the relevant geometry.
|
||||
* Method: getGeometry
|
||||
* Return the sketch geometry. If <multi> is true, this will return
|
||||
* a multi-part geometry.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Geometry.Point>}
|
||||
*/
|
||||
getGeometry: function() {
|
||||
var geometry = this.point.geometry;
|
||||
if(this.multi) {
|
||||
geometry = new OpenLayers.Geometry.MultiPoint([geometry]);
|
||||
}
|
||||
return geometry;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: geometryClone
|
||||
* Return a clone of the relevant geometry.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Geometry>}
|
||||
*/
|
||||
geometryClone: function() {
|
||||
return this.point.geometry.clone();
|
||||
return this.getGeometry().clone();
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -246,6 +287,9 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
return true;
|
||||
}
|
||||
if(this.lastDown == null) {
|
||||
if(this.persist) {
|
||||
this.destroyFeature();
|
||||
}
|
||||
this.createFeature();
|
||||
}
|
||||
this.lastDown = evt.xy;
|
||||
@@ -253,6 +297,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, {
|
||||
var lonlat = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.point.geometry.x = lonlat.lon;
|
||||
this.point.geometry.y = lonlat.lat;
|
||||
this.point.geometry.clearBounds();
|
||||
this.drawFeature();
|
||||
return false;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user