Merge pull request #183 from fredj/transform-control
Transform control. r=ahocevar
This commit is contained in:
@@ -14,15 +14,6 @@
|
|||||||
function init(){
|
function init(){
|
||||||
map = new OpenLayers.Map('map', {allOverlays: true});
|
map = new OpenLayers.Map('map', {allOverlays: true});
|
||||||
|
|
||||||
// a nice style for the transformation box
|
|
||||||
var style = new OpenLayers.Style({
|
|
||||||
cursor: "${role}",
|
|
||||||
pointRadius: 5,
|
|
||||||
fillColor: "white",
|
|
||||||
fillOpacity: 1,
|
|
||||||
strokeColor: "black"
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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;
|
||||||
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
|
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
|
||||||
@@ -30,7 +21,36 @@
|
|||||||
// the layer that we want to transform features on
|
// the layer that we want to transform features on
|
||||||
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
|
var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
|
||||||
styleMap: new OpenLayers.StyleMap({
|
styleMap: new OpenLayers.StyleMap({
|
||||||
"transform": style
|
// a nice style for the transformation box
|
||||||
|
"transform": new OpenLayers.Style({
|
||||||
|
display: "${getDisplay}",
|
||||||
|
cursor: "${role}",
|
||||||
|
pointRadius: 5,
|
||||||
|
fillColor: "white",
|
||||||
|
fillOpacity: 1,
|
||||||
|
strokeColor: "black"
|
||||||
|
}, {
|
||||||
|
context: {
|
||||||
|
getDisplay: function(feature) {
|
||||||
|
// hide the resize handle at the south-east corner
|
||||||
|
return feature.attributes.role === "se-resize" ? "none" : "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
"rotate": new OpenLayers.Style({
|
||||||
|
display: "${getDisplay}",
|
||||||
|
pointRadius: 10,
|
||||||
|
fillColor: "#ddd",
|
||||||
|
fillOpacity: 1,
|
||||||
|
strokeColor: "black"
|
||||||
|
}, {
|
||||||
|
context: {
|
||||||
|
getDisplay: function(feature) {
|
||||||
|
// only display the rotate handle at the south-east corner
|
||||||
|
return feature.attributes.role === "se-rotate" ? "" : "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
renderers: renderer
|
renderers: renderer
|
||||||
});
|
});
|
||||||
@@ -38,7 +58,8 @@
|
|||||||
// create the TransformFeature control, using the renderIntent
|
// create the TransformFeature control, using the renderIntent
|
||||||
// from above
|
// from above
|
||||||
control = new OpenLayers.Control.TransformFeature(vectorLayer, {
|
control = new OpenLayers.Control.TransformFeature(vectorLayer, {
|
||||||
renderIntent: "transform"
|
renderIntent: "transform",
|
||||||
|
rotationHandleSymbolizer: "rotate"
|
||||||
});
|
});
|
||||||
map.addControl(control);
|
map.addControl(control);
|
||||||
|
|
||||||
@@ -86,13 +107,15 @@
|
|||||||
<div id="docs">
|
<div id="docs">
|
||||||
<p>This example shows transformation of vector features with a
|
<p>This example shows transformation of vector features with a
|
||||||
tranformation box. Grab one of the handles to resize the feature.
|
tranformation box. Grab one of the handles to resize the feature.
|
||||||
Holding the SHIFT key will preserve the aspect ratio. Position the
|
Holding the SHIFT key will preserve the aspect ratio. Use the gray
|
||||||
mouse right outside one of the corner handles to rotate the feature,
|
handle to rotate the feature and hold the SHIFT key to only rotate
|
||||||
and hold the SHIFT key to only rotate in 45° increments.</p>
|
in 45° increments.
|
||||||
<p>In this example, the transformation box has been set on the left
|
</p>
|
||||||
|
<p>In this example, the transformation box has been set on the left
|
||||||
feature, with a rotation preset of 45°. Clicking on the right feature
|
feature, with a rotation preset of 45°. Clicking on the right feature
|
||||||
will set it for transformation, starting with an unrotated box.
|
will set it for transformation, starting with an unrotated box.
|
||||||
Dragging a feature or the box edges will move it around.</p>
|
Dragging a feature or the box edges will move it around.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -465,17 +465,17 @@ 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",
|
var positions = ["sw", "s", "se", "e", "ne", "n", "nw", "w"];
|
||||||
"ne-resize", "n-resize", "nw-resize", "w-resize"];
|
|
||||||
for(var i=0; i<8; ++i) {
|
for(var i=0; i<8; ++i) {
|
||||||
geom = this.box.geometry.components[i];
|
geom = this.box.geometry.components[i];
|
||||||
handle = new OpenLayers.Feature.Vector(geom.clone(), {
|
handle = new OpenLayers.Feature.Vector(geom.clone(), {
|
||||||
role: resize[i]
|
role: positions[i] + "-resize"
|
||||||
}, typeof this.renderIntent == "string" ? null :
|
}, 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(), {
|
||||||
null, typeof this.rotationHandleSymbolizer == "string" ?
|
role: positions[i] + "-rotate"
|
||||||
|
}, typeof this.rotationHandleSymbolizer == "string" ?
|
||||||
null : this.rotationHandleSymbolizer);
|
null : this.rotationHandleSymbolizer);
|
||||||
rotationHandle.geometry.move = rotationHandleMoveFn;
|
rotationHandle.geometry.move = rotationHandleMoveFn;
|
||||||
geom._rotationHandle = rotationHandle;
|
geom._rotationHandle = rotationHandle;
|
||||||
@@ -513,7 +513,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
|
|||||||
onDrag: function(feature, pixel) {
|
onDrag: function(feature, pixel) {
|
||||||
if(feature === control.box) {
|
if(feature === control.box) {
|
||||||
control.transformFeature({center: control.center});
|
control.transformFeature({center: control.center});
|
||||||
control.drawHandles();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// set a new feature
|
// set a new feature
|
||||||
|
|||||||
Reference in New Issue
Block a user