git-svn-id: http://svn.openlayers.org/trunk/openlayers@4205 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
136 lines
5.8 KiB
HTML
136 lines
5.8 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../../lib/OpenLayers.js"></script>
|
|
<script type="text/javascript">
|
|
function test_Handler_RegularPolygon_constructor(t) {
|
|
t.plan(3);
|
|
var control = new OpenLayers.Control();
|
|
control.id = Math.random();
|
|
var callbacks = {foo: "bar"};
|
|
var options = {bar: "foo"};
|
|
|
|
var oldInit = OpenLayers.Handler.prototype.initialize;
|
|
|
|
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
|
|
t.eq(con.id, control.id,
|
|
"constructor calls parent with the correct control");
|
|
t.eq(call, callbacks,
|
|
"constructor calls parent with the correct callbacks");
|
|
t.eq(opt, options,
|
|
"regular polygon constructor calls parent with the correct options");
|
|
}
|
|
var handler = new OpenLayers.Handler.RegularPolygon(control, callbacks, options);
|
|
|
|
OpenLayers.Handler.prototype.initialize = oldInit;
|
|
}
|
|
|
|
function test_Handler_RegularPolygon_activation(t) {
|
|
t.plan(3);
|
|
var map = new OpenLayers.Map('map');
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.RegularPolygon(control);
|
|
handler.active = true;
|
|
var activated = handler.activate();
|
|
t.ok(!activated,
|
|
"activate returns false if the handler was already active");
|
|
handler.active = false;
|
|
activated = handler.activate();
|
|
t.ok(activated,
|
|
"activate returns true if the handler was not already active");
|
|
activated = handler.deactivate();
|
|
t.ok(activated,
|
|
"deactivate returns true if the handler was active already");
|
|
}
|
|
|
|
function test_Handler_RegularPolygon_four_corners(t) {
|
|
t.plan(7);
|
|
var map = new OpenLayers.Map('map');
|
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
|
map.zoomToMaxExtent();
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.RegularPolygon(control, {});
|
|
var activated = handler.activate();
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.down(evt);
|
|
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-35.15625,-35.15625,35.15625,35.15625",
|
|
"correct bounds after move");
|
|
t.eq(handler.feature.geometry.components[0].components.length, 5,
|
|
"geometry has 5 components");
|
|
t.eq(handler.feature.geometry.CLASS_NAME,
|
|
"OpenLayers.Geometry.Polygon",
|
|
"geometry is a polygon");
|
|
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
|
|
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-35.15625,-35.15625,35.15625,35.15625",
|
|
"correct bounds after move with a fixed radius");
|
|
handler.cancel();
|
|
handler.setOptions({radius:2 / Math.sqrt(2)});
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.down(evt);
|
|
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-1,-1,1,1",
|
|
"bounds with manual radius setting");
|
|
var evt = {xy: new OpenLayers.Pixel(175, 90), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"34.15625,-22.09375,36.15625,-20.09375",
|
|
"bounds with manual radius setting and mousemove");
|
|
}
|
|
|
|
function test_Handler_RegularPolygon_circle(t) {
|
|
t.plan(7);
|
|
var map = new OpenLayers.Map('map');
|
|
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
|
|
map.zoomToMaxExtent();
|
|
var control = new OpenLayers.Control();
|
|
map.addControl(control);
|
|
var handler = new OpenLayers.Handler.RegularPolygon(control, {}, {'sides':40});
|
|
var activated = handler.activate();
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.down(evt);
|
|
var evt = {xy: new OpenLayers.Pixel(175, 75), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-35.15625,-35.15625,35.15625,35.15625",
|
|
"correct bounds after move");
|
|
t.eq(handler.feature.geometry.components[0].components.length, 41,
|
|
"geometry has correct numbre of components");
|
|
t.eq(handler.feature.geometry.CLASS_NAME,
|
|
"OpenLayers.Geometry.Polygon",
|
|
"geometry is a polygon");
|
|
t.eq(handler.radius, 25*1.40625, "feature radius as set on handler");
|
|
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-35.823348,-35.823348,35.823348,35.823348",
|
|
"correct bounds after move with fixed radius");
|
|
handler.cancel();
|
|
handler.setOptions({radius:1});
|
|
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
|
|
handler.down(evt);
|
|
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"-0.996917,-0.996917,0.996917,0.996917",
|
|
"bounds with manual radius setting");
|
|
var evt = {xy: new OpenLayers.Pixel(175, 80), which: 1};
|
|
handler.move(evt);
|
|
t.eq(handler.feature.geometry.getBounds().toBBOX(),
|
|
"34.159333,-8.028167,36.153167,-6.034333",
|
|
"bounds with manual radius setting and mousemove");
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width: 300px; height: 150px;"/>
|
|
</body>
|
|
</html>
|