make the drawing handlers create the sketch feature at an appropriate time, when we can actually derive geographic coordinates from a pixel, r=ahocevar (References #3327)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12046 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-06-06 07:12:52 +00:00
parent 9dcdbac238
commit 9b361ef35d
9 changed files with 116 additions and 208 deletions

View File

@@ -102,13 +102,10 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
* feature.
*/
createFeature: function(pixel) {
var geometry;
if(pixel) {
var lonlat = this.map.getLonLatFromPixel(pixel);
geometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
} else {
geometry = new OpenLayers.Geometry.Point();
}
var lonlat = this.map.getLonLatFromPixel(pixel);
var geometry = new OpenLayers.Geometry.Point(
lonlat.lon, lonlat.lat
);
this.point = new OpenLayers.Feature.Vector(geometry);
this.line = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([this.point.geometry])
@@ -121,9 +118,13 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
/**
* Method: destroyFeature
* Destroy temporary geometries
*
* Parameters:
* force - {Boolean} Destroy even if persist is true.
*/
destroyFeature: function() {
OpenLayers.Handler.Point.prototype.destroyFeature.apply(this);
destroyFeature: function(force) {
OpenLayers.Handler.Point.prototype.destroyFeature.call(
this, force);
this.line = null;
},
@@ -193,6 +194,9 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, {
* drawing - {Boolean} Indicate if we're currently drawing.
*/
modifyFeature: function(pixel, drawing) {
if(!this.line) {
this.createFeature(pixel);
}
var lonlat = this.control.map.getLonLatFromPixel(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;