Date picker and bylines for platforms`
[bus.git] / openlayers / examples / getfeatureinfo-control.html
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<html>
  <head>
    <title>OpenLayers WMS Feature Info Example (GeoServer)</title>
    <script src="../lib/OpenLayers.js"></script>
    <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
    <link rel="stylesheet" href="style.css" type="text/css" />
    <style type="text/css">
        ul, li {
            padding-left: 0px;
            margin-left: 0px;
            list-style: none;
        }
        #info {
            position: absolute;
            top: 6em;
            left: 550px;
        }
        #info table td {
            border:1px solid #ddd;
            border-collapse: collapse;
            margin: 0;
            padding: 0;
            font-size: 90%;
            padding: .2em .1em;
            background:#fff;
        }
        #info table th{
            padding:.2em .2em;
            text-transform: uppercase;
            font-weight: bold;
            background: #eee;
        }
        tr.odd td {
            background:#eee;
        }
        table.featureInfo caption {
            text-align:left;
            font-size:100%;
            font-weight:bold;
            text-transform:uppercase;
            padding:.2em .2em;
        }
 
 
    </style>
  <script defer="defer" type="text/javascript">
    OpenLayers.ProxyHost = "proxy.cgi?url=";
    
    var map, infocontrols, water, highlightlayer;
    
    function load() {
        map = new OpenLayers.Map('map', {
            maxExtent: new OpenLayers.Bounds(143.834,-43.648,148.479,-39.573)
        });
 
        var political = new OpenLayers.Layer.WMS("State Boundaries",
            "http://demo.opengeo.org/geoserver/wms", 
            {'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
            {isBaseLayer: true}
        );
 
        var roads = new OpenLayers.Layer.WMS("Roads",
            "http://demo.opengeo.org/geoserver/wms", 
            {'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );
 
        var cities = new OpenLayers.Layer.WMS("Cities",
            "http://demo.opengeo.org/geoserver/wms", 
            {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );
 
        water = new OpenLayers.Layer.WMS("Bodies of Water",
            "http://demo.opengeo.org/geoserver/wms", 
            {'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );
 
        highlightLayer = new OpenLayers.Layer.Vector("Highlighted Features", {
            displayInLayerSwitcher: false, 
            isBaseLayer: false 
            }
        );
 
        infoControls = {
            click: new OpenLayers.Control.WMSGetFeatureInfo({
                url: 'http://demo.opengeo.org/geoserver/wms', 
                title: 'Identify features by clicking',
                layers: [water],
                queryVisible: true
            }),
            hover: new OpenLayers.Control.WMSGetFeatureInfo({
                url: 'http://demo.opengeo.org/geoserver/wms', 
                title: 'Identify features by clicking',
                layers: [water],
                hover: true,
                // defining a custom format options here
                formatOptions: {
                    typeName: 'water_bodies', 
                    featureNS: 'http://www.openplans.org/topp'
                },
                queryVisible: true
            })
        }
 
        map.addLayers([political, roads, cities, water, highlightLayer]); 
        for (var i in infoControls) { 
            infoControls[i].events.register("getfeatureinfo", this, showInfo);
            map.addControl(infoControls[i]); 
        }
 
        map.addControl(new OpenLayers.Control.LayerSwitcher());
 
        infoControls.click.activate();
        map.zoomToMaxExtent();
    }
 
    function showInfo(evt) {
        if (evt.features && evt.features.length) {
             highlightLayer.destroyFeatures();
             highlightLayer.addFeatures(evt.features);
             highlightLayer.redraw();
        } else {
            $('responseText').innerHTML = evt.text;
        }
    }
 
    function toggleControl(element) {
        for (var key in infoControls) {
            var control = infoControls[key];
            if (element.value == key && element.checked) {
                control.activate();
            } else {
                control.deactivate();
            }
        }
    }
 
    function toggleFormat(element) {
        for (var key in infoControls) {
            var control = infoControls[key];
            control.infoFormat = element.value;
        }
    }
 
    function toggleLayers(element) {
        for (var key in infoControls) {
            var control = infoControls[key];
            if (element.value == 'Specified') {
                control.layers = [water];
            } else {
                control.layers = null;
            }
        }
    }
 
    // function toggle(key
  </script>
  </head>
  <body onload="load()">
      <h1 id="title">Feature Info Example</h1>
 
      <div id="tags"></div>
 
      <p id="shortdesc">
        Demonstrates the WMSGetFeatureInfo control for fetching information about a position from WMS (via GetFeatureInfo request).
      </p>
 
    <div id="info">
        <h1>Tasmania</h1>
        <p>Click on the map to get feature info.</p>
        <div id="responseText">
        </div>
    </div>
      <div id="map" class="smallmap"></div>
 
    <div id="docs">
    </div>
        <ul id="control">
            <li>
                <input type="radio" name="controlType" value="click" id="click"
                       onclick="toggleControl(this);" checked="checked" />
                <label for="click">Click</label>
            </li>
            <li>
                <input type="radio" name="controlType" value="hover" id="hover" 
                       onclick="toggleControl(this);" />
                <label for="hover">Hover</label>
            </li>
        </ul>
        <ul id="format">
            <li>
                <input type="radio" name="formatType" value="text/html" id="html"
                       onclick="toggleFormat(this);" checked="checked" />
                <label for="html">Show HTML Description</label>
            </li>
            <li>
                <input type="radio" name="formatType" value="application/vnd.ogc.gml" id="highlight" 
                       onclick="toggleFormat(this);" />
                <label for="highlight">Highlight Feature on Map</label>
            </li>
        </ul>
        <ul id="layers">
            <li>
                <input type="radio" name="layerSelection" value="Specified" id="Specified"
                       onclick="toggleLayers(this);" checked="checked" />
                <label for="Specified">Get water body info</label>
            </li>
            <li>
                <input type="radio" name="layerSelection" value="Auto" id="Auto" 
                       onclick="toggleLayers(this);" />
                <label for="Auto">Get info for visible layers</label>
            </li>
        </ul>
  </body>
</html>