adding irregular option to regular polygon control - now, go draw rectangles, and more - thanks for the review elem (closes #1098).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5200 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -62,6 +62,18 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
*/
|
||||
persist: false,
|
||||
|
||||
/**
|
||||
* APIProperty: irregular
|
||||
* {Boolean} Draw an irregular polygon instead of a regular polygon.
|
||||
* Default is false. If true, the initial mouse down will represent
|
||||
* one corner of the polygon bounds and with each mouse movement, the
|
||||
* polygon will be stretched so the opposite corner of its bounds
|
||||
* follows the mouse position. This property takes precedence over
|
||||
* the radius property. If set to true, the radius property will
|
||||
* be ignored.
|
||||
*/
|
||||
irregular: false,
|
||||
|
||||
/**
|
||||
* Property: angle
|
||||
* {Float} The angle from the origin (mouse down) to the current mouse
|
||||
@@ -194,7 +206,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
this.origin = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
// create the new polygon
|
||||
if(!this.fixedRadius) {
|
||||
if(!this.fixedRadius || this.irregular) {
|
||||
// smallest radius should not be less one pixel in map units
|
||||
// VML doesn't behave well with smaller
|
||||
this.radius = this.map.getResolution();
|
||||
@@ -218,7 +230,10 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
move: function(evt) {
|
||||
var maploc = this.map.getLonLatFromPixel(evt.xy);
|
||||
var point = new OpenLayers.Geometry.Point(maploc.lon, maploc.lat);
|
||||
if(this.fixedRadius) {
|
||||
if(this.irregular) {
|
||||
var ry = Math.sqrt(2) * Math.abs(point.y - this.origin.y) / 2;
|
||||
this.radius = Math.max(this.map.getResolution() / 2, ry);
|
||||
} else if(this.fixedRadius) {
|
||||
this.origin = point;
|
||||
} else {
|
||||
this.calculateAngle(point, evt);
|
||||
@@ -226,6 +241,18 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
point.distanceTo(this.origin));
|
||||
}
|
||||
this.modifyGeometry();
|
||||
if(this.irregular) {
|
||||
var dx = point.x - this.origin.x;
|
||||
var dy = point.y - this.origin.y;
|
||||
var ratio;
|
||||
if(dy == 0) {
|
||||
ratio = dx / (this.radius * Math.sqrt(2));
|
||||
} else {
|
||||
ratio = dx / dy;
|
||||
}
|
||||
this.feature.geometry.resize(1, this.origin, ratio);
|
||||
this.feature.geometry.move(dx / 2, dy / 2);
|
||||
}
|
||||
this.layer.drawFeature(this.feature, this.style);
|
||||
},
|
||||
|
||||
@@ -277,6 +304,7 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, {
|
||||
// if the number of sides ever changes, create a new geometry
|
||||
if(ring.components.length != (this.sides + 1)) {
|
||||
this.createGeometry();
|
||||
ring = this.feature.geometry.components[0];
|
||||
}
|
||||
for(var i=0; i<this.sides; ++i) {
|
||||
point = ring.components[i];
|
||||
|
||||
Reference in New Issue
Block a user