1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <title>Vector Features Performance Test</title>
4 <style type="text/css">
14 border: 1px solid black;
18 <script src="../../lib/Firebug/firebug.js"></script>
19 <script src="../../lib/OpenLayers.js"></script>
20 <script type="text/javascript">
21 var map, vectorLayer, drawFeature, features
26 window.setTimeout(function() {
28 vectorLayer.removeFeatures(features);
32 window.setTimeout(function(){
37 console.log("First run - feature bboxes will be cached");
38 map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 3);
42 console.log("Test with all features inside extent");
49 console.log("Test with some features outside extent");
50 map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 5);
60 function vectorTestOld(){
61 vectorLayer.renderer.drawFeature = function(feature, style) {
63 style = feature.style;
65 if (feature.geometry) {
66 this.drawGeometry(feature.geometry, style, feature.id);
70 console.time("addFeaturesOld");
71 vectorLayer.addFeatures(features);
72 console.timeEnd("addFeaturesOld");
75 function vectorTestNew() {
76 vectorLayer.renderer.drawFeature = OpenLayers.Renderer[vectorLayer.renderer.CLASS_NAME.split(".")[2]].prototype.drawFeature;
78 console.time("addFeatures");
79 vectorLayer.addFeatures(features);
80 console.timeEnd("addFeatures");
84 map = new OpenLayers.Map('map');
86 vectorLayer = new OpenLayers.Layer.Vector("Vector Layer", {isBaseLayer: true});
88 map.addLayers([vectorLayer]);
89 map.addControl(new OpenLayers.Control.MousePosition());
90 map.setCenter(new OpenLayers.LonLat(-22.5, -22.5), 3);
92 vectorLayer.events.register("featuresadded", this, nextRun);
94 features = new Array(200);
96 for (var i = 0; i < 200; i++) {
97 x = -Math.random()*45;
98 y = -Math.random()*45;
99 features[i] = new OpenLayers.Feature.Vector(
100 new OpenLayers.Geometry.LinearRing([
101 new OpenLayers.Geometry.Point(
102 -Math.random()*5+x, -Math.random()*5+y),
103 new OpenLayers.Geometry.Point(
104 -Math.random()*5+x, -Math.random()*5+y),
105 new OpenLayers.Geometry.Point(
106 -Math.random()*5+x, -Math.random()*5+y),
107 new OpenLayers.Geometry.Point(
108 -Math.random()*5+x, -Math.random()*5+y),
109 new OpenLayers.Geometry.Point(
110 -Math.random()*5+x, -Math.random()*5+y),
111 new OpenLayers.Geometry.Point(
112 -Math.random()*5+x, -Math.random()*5+y),
113 new OpenLayers.Geometry.Point(
114 -Math.random()*5+x, -Math.random()*5+y),
115 new OpenLayers.Geometry.Point(
116 -Math.random()*5+x, -Math.random()*5+y),
117 new OpenLayers.Geometry.Point(
118 -Math.random()*5+x, -Math.random()*5+y),
119 new OpenLayers.Geometry.Point(
120 -Math.random()*5+x, -Math.random()*5+y)
129 <body onload="init()">
130 <h1 id="title">New Rendering - Vector Features Performance Test</h1>
133 This test examines if checking for a feature being inside the visible
134 extent before rendering it has an impact on performance. Open the Firebug
135 console after running this test (hit F12) to see the results.
137 After the performance test, you can drag around the map to see how the new
138 vector rendering feels where features get rendered only when they are visible
139 inside the map extent.