Merge pull request #175 from fredj/transform-control

Transform control, r=ahocevar
This commit is contained in:
Frédéric Junod
2012-01-24 23:35:30 -08:00
2 changed files with 16 additions and 26 deletions
+2 -17
View File
@@ -14,29 +14,14 @@
function init(){ function init(){
map = new OpenLayers.Map('map', {allOverlays: true}); map = new OpenLayers.Map('map', {allOverlays: true});
// context for appropriate scale/resize cursors
var cursors = ["sw-resize", "s-resize", "se-resize",
"e-resize", "ne-resize", "n-resize", "nw-resize", "w-resize"];
var context = {
getCursor: function(feature){
var i = OpenLayers.Util.indexOf(control.handles, feature);
var cursor = "inherit";
if(i !== -1) {
i = (i + 8 + Math.round(control.rotation / 90) * 2) % 8;
cursor = cursors[i];
}
return cursor;
}
};
// a nice style for the transformation box // a nice style for the transformation box
var style = new OpenLayers.Style({ var style = new OpenLayers.Style({
cursor: "${getCursor}", cursor: "${role}",
pointRadius: 5, pointRadius: 5,
fillColor: "white", fillColor: "white",
fillOpacity: 1, fillOpacity: 1,
strokeColor: "black" strokeColor: "black"
}, {context: context}); });
// allow testing of specific renderers via "?renderer=Canvas", etc // allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer; var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
+14 -9
View File
@@ -232,9 +232,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
this.dragControl.deactivate(); this.dragControl.deactivate();
deactivated = true; deactivated = true;
} }
if (deactivated) {
this.unsetFeature();
}
return deactivated; return deactivated;
}, },
@@ -335,7 +332,7 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
var control = this; var control = this;
this.center = new OpenLayers.Geometry.Point(0, 0); this.center = new OpenLayers.Geometry.Point(0, 0);
var box = new OpenLayers.Feature.Vector( this.box = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([ new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-1, -1), new OpenLayers.Geometry.Point(-1, -1),
new OpenLayers.Geometry.Point(0, -1), new OpenLayers.Geometry.Point(0, -1),
@@ -351,7 +348,7 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
); );
// Override for box move - make sure that the center gets updated // Override for box move - make sure that the center gets updated
box.geometry.move = function(x, y) { this.box.geometry.move = function(x, y) {
control._moving = true; control._moving = true;
OpenLayers.Geometry.LineString.prototype.move.apply(this, arguments); OpenLayers.Geometry.LineString.prototype.move.apply(this, arguments);
control.center.move(x, y); control.center.move(x, y);
@@ -468,10 +465,13 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
var handles = new Array(8); var handles = new Array(8);
var rotationHandles = new Array(4); var rotationHandles = new Array(4);
var geom, handle, rotationHandle; var geom, handle, rotationHandle;
var resize = ["sw-resize", "s-resize", "se-resize", "e-resize",
"ne-resize", "n-resize", "nw-resize", "w-resize"];
for(var i=0; i<8; ++i) { for(var i=0; i<8; ++i) {
geom = box.geometry.components[i]; geom = this.box.geometry.components[i];
handle = new OpenLayers.Feature.Vector(geom.clone(), null, handle = new OpenLayers.Feature.Vector(geom.clone(), {
typeof this.renderIntent == "string" ? null : role: resize[i]
}, typeof this.renderIntent == "string" ? null :
this.renderIntent); this.renderIntent);
if(i % 2 == 0) { if(i % 2 == 0) {
rotationHandle = new OpenLayers.Feature.Vector(geom.clone(), rotationHandle = new OpenLayers.Feature.Vector(geom.clone(),
@@ -489,7 +489,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
handles[i] = handle; handles[i] = handle;
} }
this.box = box;
this.rotationHandles = rotationHandles; this.rotationHandles = rotationHandles;
this.handles = handles; this.handles = handles;
}, },
@@ -600,10 +599,16 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
geom._rotationHandle && geom._rotationHandle.destroy(); geom._rotationHandle && geom._rotationHandle.destroy();
geom._rotationHandle = null; geom._rotationHandle = null;
} }
this.center = null;
this.feature = null;
this.handles = null;
this.rotationHandleSymbolizer = null;
this.rotationHandles = null;
this.box.destroy(); this.box.destroy();
this.box = null; this.box = null;
this.layer = null; this.layer = null;
this.dragControl.destroy(); this.dragControl.destroy();
this.dragControl = null;
OpenLayers.Control.prototype.destroy.apply(this, arguments); OpenLayers.Control.prototype.destroy.apply(this, arguments);
}, },