1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Vector Features Performance Test</title>
<style type="text/css">
body {
font-size: 0.8em;
}
p {
padding-top: 1em;
}
#map {
width: 512px;
height: 512px;
border: 1px solid black;
}
</style>
<script src="../../lib/Firebug/firebug.js"></script>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, vectorLayer, drawFeature, features
var run = 0;
function nextRun() {
window.setTimeout(function() {
if (run < 5) {
vectorLayer.removeFeatures(features);
}
}, 900);
window.setTimeout(function(){
run++;
switch(run) {
case 1:
console.log("First run - feature bboxes will be cached");
map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 3);
vectorTestNew()
break;
case 2:
console.log("Test with all features inside extent");
vectorTestOld();
break;
case 3:
vectorTestNew();
break;
case 4:
console.log("Test with some features outside extent");
map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 5);
vectorTestOld();
break;
case 5:
vectorTestNew();
break;
}
}, 1000);
}
function vectorTestOld(){
vectorLayer.renderer.drawFeature = function(feature, style) {
if(style == null) {
style = feature.style;
}
if (feature.geometry) {
this.drawGeometry(feature.geometry, style, feature.id);
}
};
console.time("addFeaturesOld");
vectorLayer.addFeatures(features);
console.timeEnd("addFeaturesOld");
}
function vectorTestNew() {
vectorLayer.renderer.drawFeature = OpenLayers.Renderer[vectorLayer.renderer.CLASS_NAME.split(".")[2]].prototype.drawFeature;
console.time("addFeatures");
vectorLayer.addFeatures(features);
console.timeEnd("addFeatures");
}
function init(){
// allow testing of specific renderers via "?renderer=Canvas", etc
var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
map = new OpenLayers.Map('map');
vectorLayer = new OpenLayers.Layer.Vector("Vector Layer", {
isBaseLayer: true,
renderers: renderer
});
map.addLayers([vectorLayer]);
map.addControl(new OpenLayers.Control.MousePosition());
map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 3);
vectorLayer.events.register("featuresadded", this, nextRun);
features = new Array(200);
var x, y
for (var i = 0; i < 200; i++) {
x = -Math.random()*45;
y = -Math.random()*45;
features[i] = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LinearRing([
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y),
new OpenLayers.Geometry.Point(
-Math.random()*5+x, -Math.random()*5+y)
]));
}
nextRun();
}
</script>
</head>
<body onload="init()">
<h1 id="title">New Rendering - Vector Features Performance Test</h1>
<div id="map"></div>
<p>
This test examines if checking for a feature being inside the visible
extent before rendering it has an impact on performance. Open the Firebug
console after running this test (hit F12) to see the results.
<br/>
After the performance test, you can drag around the map to see how the new
vector rendering feels where features get rendered only when they are visible
inside the map extent.
</p>
</body>
</html>
|