make it possible to pan the map while drawing geometries, r=tschaub (closes #3052)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11381 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -79,6 +79,9 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* feature.
|
||||
*/
|
||||
createFeature: function(pixel) {
|
||||
if(!pixel) {
|
||||
pixel = new OpenLayers.Pixel(-50, -50);
|
||||
}
|
||||
var lonlat = this.control.map.getLonLatFromPixel(pixel);
|
||||
this.point = new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
|
||||
@@ -100,6 +103,17 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
this.line = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: destroyPersistedFeature
|
||||
* Destroy the persisted feature.
|
||||
*/
|
||||
destroyPersistedFeature: function() {
|
||||
var layer = this.layer;
|
||||
if(layer && layer.features.length > 2) {
|
||||
this.layer.features[0].destroy();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: removePoint
|
||||
* Destroy the temporary point.
|
||||
@@ -151,12 +165,13 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* Parameters:
|
||||
* pixel - {<OpenLayers.Pixel>} The updated pixel location for the latest
|
||||
* point.
|
||||
* drawing - {Boolean} Indicate if we're currently drawing.
|
||||
*/
|
||||
modifyFeature: function(pixel) {
|
||||
modifyFeature: function(pixel, drawing) {
|
||||
var lonlat = this.control.map.getLonLatFromPixel(pixel);
|
||||
this.point.geometry.x = lonlat.lon;
|
||||
this.point.geometry.y = lonlat.lat;
|
||||
this.callback("modify", [this.point.geometry, this.getSketch()]);
|
||||
this.callback("modify", [this.point.geometry, this.getSketch(), drawing]);
|
||||
this.point.geometry.clearBounds();
|
||||
this.drawFeature();
|
||||
},
|
||||
@@ -209,22 +224,17 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* {Boolean} Allow event propagation
|
||||
*/
|
||||
mousedown: function(evt) {
|
||||
// ignore double-clicks
|
||||
if (this.lastDown && this.lastDown.equals(evt.xy)) {
|
||||
return false;
|
||||
var stopDown = this.stopDown;
|
||||
if(this.freehandMode(evt)) {
|
||||
stopDown = true;
|
||||
}
|
||||
if(this.lastDown == null) {
|
||||
if(this.persist) {
|
||||
this.destroyFeature();
|
||||
}
|
||||
this.createFeature(evt.xy);
|
||||
} else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
|
||||
this.addPoint(evt.xy);
|
||||
if(!this.lastDown || !this.lastDown.equals(evt.xy)) {
|
||||
this.modifyFeature(evt.xy, !!this.lastUp);
|
||||
}
|
||||
this.mouseDown = true;
|
||||
this.lastDown = evt.xy;
|
||||
this.drawing = true;
|
||||
return false;
|
||||
this.stoppedDown = stopDown;
|
||||
return !stopDown;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -239,12 +249,15 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* {Boolean} Allow event propagation
|
||||
*/
|
||||
mousemove: function (evt) {
|
||||
if(this.drawing) {
|
||||
if(this.mouseDown && this.freehandMode(evt)) {
|
||||
this.addPoint(evt.xy);
|
||||
} else {
|
||||
this.modifyFeature(evt.xy);
|
||||
if(this.stoppedDown && this.freehandMode(evt)) {
|
||||
if(this.persist) {
|
||||
this.destroyPersistedFeature();
|
||||
}
|
||||
this.addPoint(evt.xy);
|
||||
return false;
|
||||
}
|
||||
if(!this.mouseDown || this.stoppedDown) {
|
||||
this.modifyFeature(evt.xy, !!this.lastUp);
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@@ -261,20 +274,23 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
|
||||
* {Boolean} Allow event propagation
|
||||
*/
|
||||
mouseup: function (evt) {
|
||||
this.mouseDown = false;
|
||||
if(this.drawing) {
|
||||
if(this.freehandMode(evt)) {
|
||||
if(this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) {
|
||||
if(this.stoppedDown && this.freehandMode(evt)) {
|
||||
this.removePoint();
|
||||
this.finalize();
|
||||
} else {
|
||||
if(this.lastUp == null) {
|
||||
this.addPoint(evt.xy);
|
||||
if(this.lastDown.equals(evt.xy)) {
|
||||
if(this.lastUp == null && this.persist) {
|
||||
this.destroyPersistedFeature();
|
||||
}
|
||||
this.addPoint(evt.xy);
|
||||
this.lastUp = evt.xy;
|
||||
}
|
||||
this.lastUp = evt.xy;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
this.stoppedDown = this.stopDown;
|
||||
this.mouseDown = false;
|
||||
return !this.stopUp;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user