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:
Tim Schaub
2007-11-15 23:37:36 +00:00
parent 75163f6635
commit ceecacfe3a
7 changed files with 102 additions and 11 deletions

View File

@@ -109,7 +109,7 @@
}
function test_Point_resize(t) {
t.plan(3);
t.plan(5);
var tolerance = 1e-10;
var x = 100 * Math.random();
@@ -134,6 +134,13 @@
t.ok(point.bounds == null, "bounds is correctly cleared after a resize()");
// resize with non uniform scaling (ratio != 1)
point = new OpenLayers.Geometry.Point(10, 10);
origin = new OpenLayers.Geometry.Point(0, 0);
point.resize(2, origin, 4);
t.eq(point.x, 80, "non-uniform scaling correctly applied in x dim");
t.eq(point.y, 20, "non-uniform scaling correctly applied in y dim");
}
function test_Point_equals(t) {

View File

@@ -140,7 +140,47 @@
t.eq(handler.feature.geometry.getBounds().toBBOX(),
"34.159333,-8.028167,36.153167,-6.034333",
"bounds with manual radius setting and mousemove");
}
}
function test_Handler_RegularPolygon_irregular(t) {
t.plan(4);
var map = {
getLonLatFromPixel: function(px) {
return {lon: px.x, lat: px.y};
},
getResolution: function() {
return 1;
}
};
var layer = {
addFeatures: function() {},
drawFeature: function(feature, style) {
var ring = feature.geometry.components[0];
t.eq(ring.components[0].x, 20, "correct right");
t.eq(ring.components[0].y, 10, "correct bottom");
t.eq(ring.components[2].x, 10, "correct left");
t.eq(ring.components[2].y, 15, "correct top");
}
};
var control = {};
var options = {
sides: 4,
irregular: true,
layer: layer,
map: map
};
var handler = new OpenLayers.Handler.RegularPolygon(
control, null, options
);
handler.origin = new OpenLayers.Geometry.Point(10, 10);
handler.feature = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Polygon(
[new OpenLayers.Geometry.LinearRing()]
)
);
// should result in a 10 x 5 rectangle
handler.move({xy: {x: 20, y: 15}});
}
</script>
</head>