git-svn-id: http://svn.openlayers.org/trunk/openlayers@11856 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
241 lines
7.1 KiB
HTML
241 lines
7.1 KiB
HTML
<html>
|
|
<head>
|
|
<script src="../OLLoader.js"></script>
|
|
<script type="text/javascript">
|
|
var supported = OpenLayers.Renderer.Canvas.prototype.supported();
|
|
function test_Renderer_Canvas_constructor(t) {
|
|
if (!supported) { t.plan(0); return; }
|
|
t.plan(2);
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var r = new OpenLayers.Renderer.Canvas(el.id);
|
|
|
|
t.ok(r instanceof OpenLayers.Renderer.Canvas, "new OpenLayers.Renderer.Canvas returns Renderer.Canvas object" );
|
|
t.ok(r.container == el, "renderer container is correctly set");
|
|
r.destroy();
|
|
}
|
|
|
|
function test_Renderer_Canvas_setextent(t) {
|
|
if (!supported) { t.plan(0); return; }
|
|
t.plan(2);
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var r = new OpenLayers.Renderer.Canvas(el.id);
|
|
|
|
var extent = new OpenLayers.Bounds(1,2,3,4);
|
|
r.resolution = 1;
|
|
r.setExtent(extent, true);
|
|
t.ok(r.extent.equals(extent), "extent is correctly set");
|
|
t.eq(r.resolution, null, "resolution nullified");
|
|
r.destroy();
|
|
}
|
|
|
|
function test_Renderer_Canvas_setsize(t) {
|
|
if (!supported) { t.plan(0); return; }
|
|
t.plan(2);
|
|
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var r = new OpenLayers.Renderer.Canvas(el.id);
|
|
var size = new OpenLayers.Size(1,2);
|
|
r.resolution = 1;
|
|
r.setSize(size);
|
|
t.ok(r.size.equals(size), "size is correctly set");
|
|
t.eq(r.resolution, null, "resolution nullified");
|
|
r.destroy();
|
|
}
|
|
|
|
function test_Renderer_Canvas_getresolution(t) {
|
|
if (!supported) { t.plan(0); return; }
|
|
t.plan(2);
|
|
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var r = new OpenLayers.Renderer.Canvas(el.id);
|
|
var map = new OpenLayers.Map("map");
|
|
r.map = map;
|
|
var resolution = r.getResolution();
|
|
t.eq(resolution, map.getResolution(), "resolution matches the map resolution");
|
|
t.eq(r.resolution, resolution, "resolution is correctly set");
|
|
map.destroy();
|
|
}
|
|
|
|
function test_featureIdToRGB(t) {
|
|
if (!supported) {
|
|
t.plan(0);
|
|
return;
|
|
}
|
|
t.plan(2);
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var renderer = new OpenLayers.Renderer.Canvas(el.id);
|
|
|
|
var cases = [{
|
|
id: "foo_0", rgb: [0, 0, 1]
|
|
}, {
|
|
id: "foo_10", rgb: [0, 0, 11]
|
|
}, {
|
|
id: "foo_100", rgb: [0, 0, 101]
|
|
}, {
|
|
id: "foo_1000000", rgb: [15, 66, 65]
|
|
}, {
|
|
id: "foo_16777214", rgb: [255, 255, 255]
|
|
}, {
|
|
id: "foo_16777215", rgb: [0, 0, 1]
|
|
}];
|
|
t.plan(cases.length);
|
|
|
|
var c;
|
|
for (var i=0; i<cases.length; ++i) {
|
|
c = cases[i];
|
|
t.eq(renderer.featureIdToRGB(c.id), c.rgb, c.id);
|
|
}
|
|
|
|
renderer.destroy();
|
|
}
|
|
|
|
function test_featureIdToHex(t) {
|
|
if (!supported) {
|
|
t.plan(0);
|
|
return;
|
|
}
|
|
t.plan(2);
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var renderer = new OpenLayers.Renderer.Canvas(el.id);
|
|
|
|
var cases = [{
|
|
id: "foo_0", hex: "#000001"
|
|
}, {
|
|
id: "foo_10", hex: "#00000b"
|
|
}, {
|
|
id: "foo_100", hex: "#000065"
|
|
}, {
|
|
id: "foo_1000000", hex: "#0f4241"
|
|
}, {
|
|
id: "foo_16777214", hex: "#ffffff"
|
|
}, {
|
|
id: "foo_16777215", hex: "#000001"
|
|
}];
|
|
t.plan(cases.length);
|
|
|
|
var c;
|
|
for (var i=0; i<cases.length; ++i) {
|
|
c = cases[i];
|
|
t.eq(renderer.featureIdToHex(c.id), c.hex, c.id);
|
|
}
|
|
|
|
renderer.destroy();
|
|
}
|
|
|
|
|
|
function test_Renderer_Canvas_destroy(t) {
|
|
if (!supported) { t.plan(0); return; }
|
|
t.plan(5);
|
|
|
|
var el = document.body;
|
|
el.id = "foo";
|
|
var r = new OpenLayers.Renderer.Canvas(el.id);
|
|
r.container = document.createElement("div");
|
|
r.extent = new OpenLayers.Bounds(1,2,3,4);
|
|
r.size = new OpenLayers.Size(1,2);
|
|
r.resolution = 1;
|
|
r.map = {};
|
|
|
|
r.destroy();
|
|
|
|
t.eq(r.container, null, "container nullified");
|
|
t.eq(r.extent, null, "extent nullified");
|
|
t.eq(r.size, null, "size nullified");
|
|
t.eq(r.resolution, null, "resolution nullified");
|
|
t.eq(r.map, null, "map nullified");
|
|
}
|
|
|
|
function test_hitDetection(t) {
|
|
if (!supported) {
|
|
t.plan(0);
|
|
return;
|
|
}
|
|
|
|
var layer = new OpenLayers.Layer.Vector(null, {
|
|
isBaseLayer: true,
|
|
resolutions: [1],
|
|
styleMap: new OpenLayers.StyleMap({
|
|
pointRadius: 5,
|
|
strokeWidth: 3,
|
|
fillColor: "red",
|
|
fillOpacity: 0.5,
|
|
strokeColor: "blue",
|
|
strokeOpacity: 0.75
|
|
}),
|
|
renderers: ["Canvas"]
|
|
});
|
|
|
|
var map = new OpenLayers.Map({
|
|
div: "map",
|
|
controls: [],
|
|
layers: [layer],
|
|
center: new OpenLayers.LonLat(0, 0),
|
|
zoom: 0
|
|
});
|
|
|
|
layer.addFeatures([
|
|
new OpenLayers.Feature.Vector(
|
|
new OpenLayers.Geometry.Point(-100, 0)
|
|
),
|
|
new OpenLayers.Feature.Vector(
|
|
OpenLayers.Geometry.fromWKT("LINESTRING(-50 0, 50 0)")
|
|
),
|
|
new OpenLayers.Feature.Vector(
|
|
OpenLayers.Geometry.fromWKT("POLYGON((100 -25, 150 -25, 150 25, 100 25, 100 -25), (120 -5, 130 -5, 130 5, 120 5, 120 -5))")
|
|
)
|
|
]);
|
|
|
|
var cases = [{
|
|
msg: "center of point", x: -100, y: 0, id: layer.features[0].id
|
|
}, {
|
|
msg: "edge of point", x: -103, y: 3, id: layer.features[0].id
|
|
}, {
|
|
msg: "outside point", x: -110, y: 3, id: null
|
|
}, {
|
|
msg: "center of line", x: 0, y: 0, id: layer.features[1].id
|
|
}, {
|
|
msg: "edge of line", x: 0, y: 1, id: layer.features[1].id
|
|
}, {
|
|
msg: "outside line", x: 0, y: 5, id: null
|
|
}, {
|
|
msg: "inside polygon", x: 110, y: 0, id: layer.features[2].id
|
|
}, {
|
|
msg: "edge of polygon", x: 99, y: 0, id: layer.features[2].id
|
|
}, {
|
|
msg: "inside polygon hole", x: 125, y: 0, id: null
|
|
}, {
|
|
msg: "outside polygon", x: 155, y: 0, id: null
|
|
}];
|
|
|
|
function px(x, y) {
|
|
return map.getPixelFromLonLat(
|
|
new OpenLayers.LonLat(x, y)
|
|
);
|
|
}
|
|
|
|
var num = cases.length;
|
|
t.plan(num);
|
|
var c, feature;
|
|
for (var i=0; i<num; ++i) {
|
|
c = cases[i];
|
|
feature = layer.renderer.getFeatureIdFromEvent({xy: px(c.x, c.y)});
|
|
t.eq(feature && feature.id, c.id, c.msg);
|
|
}
|
|
|
|
map.destroy();
|
|
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width:500px;height:550px"></div>
|
|
</body>
|
|
</html>
|