summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/layerLoadMonitoring.html
blob: f96d49c34ac9fc7205333757d800f0bb5f6855b3 (plain)
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
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers Layer Load Monitoring Example</title>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
    <link rel="stylesheet" href="style.css" type="text/css">
    <style type="text/css">
        #controls {
            float: left;
            text-align: right;
        }
        #eventsLogID {
            text-align: left;
            width: 350px;
            height: 475px;
            overflow: auto;
            border: 1px solid black;
        }
    </style>
    <script src="../lib/Firebug/firebug.js"></script>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var lon = 5;
        var lat = 40;
        var zoom = 5;
        var map, layer;

        function init(){

            eventsLog = OpenLayers.Util.getElement("eventsLogID");

            map = new OpenLayers.Map( 'map' );
            map.addControl(new OpenLayers.Control.LayerSwitcher());

            buffer0 = new OpenLayers.Layer.WMS( "WMS Buffer 0",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} ,
                    { singleTile: false, buffer:0}
            );
            registerEvents(buffer0);

            buffer1 = new OpenLayers.Layer.WMS( "WMS Buffer 1",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} ,
                    { singleTile: false, buffer:1}
            );
            registerEvents(buffer1);

            buffer2 = new OpenLayers.Layer.WMS( "WMS Buffer 2",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} ,
                    { singleTile: false, buffer:2 }
            );
            registerEvents(buffer2);

            singleTileLayer = new OpenLayers.Layer.WMS( "Single Tile Layer",
                    "http://vmap0.tiles.osgeo.org/wms/vmap0",
                    {layers: 'basic'} ,
                    { singleTile: true}
            );
            registerEvents(singleTileLayer);

            map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
        }

        function registerEvents(layer) {

            layer.logEvent = function(event) {
                eventsLog.innerHTML += "<br>(" + getTimeStamp() + ") " +
                                       this.name + ": " + event;
            };

            layer.events.register("loadstart", layer, function() {
                this.logEvent("Load Start");
            });

            layer.events.register("tileloaded", layer, function() {
                this.logEvent("Tile loaded. " + this.numLoadingTiles + " left.");
            });

            layer.events.register("loadend", layer, function() {
                this.logEvent("Load End. Grid:" + this.grid.length + "x" + this.grid[0].length);
            });

            map.addLayer(layer);
        }


        function getTimeStamp() {
            var date = new Date();

            var timeParts = [
                date.getHours(),
                date.getMinutes(),
                date.getSeconds()
            ];

            var timeStamp = timeParts.join(":");

            return timeStamp;
        }

        function clearLog() {
            eventsLog.innerHTML = "<b>Events Log:</b>";
        }
    </script>
  </head>
  <body onload="init()">
      <h1 id="title">Layer Load Monitoring Example</h1>

      <div id="tags">
        monitor, loading, light
      </div>

      <p id="shortdesc">
          Demonstrate a method for monitoring tile loading performance.
      </p>

    <div id="map" class="smallmap" style="float:left;"></div>

    <div id="controls">
        <div id="eventsLogID">
            <b>Events Log:</b>
        </div>

        <input type="button" value="Clear" onclick="clearLog()"/>
    </div>

    <div id="docs">
    </div>
  </body>
</html>