summaryrefslogtreecommitdiff
path: root/misc/openlayers/examples/SLDSelect.html
blob: ff07e319d1b9c867d3390b7fd70d4d0a7e8e983f (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
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
<!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 SLD based selection control</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">
        .olControlSLDSelectBoxActive {
            cursor: crosshair;
        }
        .olControlSLDSelectPolygonActive {
            cursor: crosshair;
        }
        .olControlSLDSelectLineActive {
            cursor: crosshair;
        }
        .olControlSLDSelectPointActive {
            cursor: pointer;
        }
    </style>
    <script src="../lib/OpenLayers.js"></script>
    <script type="text/javascript">
        var map, controls, layers;

        function init(){
            OpenLayers.ProxyHost= "proxy.cgi?url=";
            map = new OpenLayers.Map('map', {allOverlays: true, controls: []});
            var url = "http://demo.opengeo.org/geoserver/wms";
            layers = {
                states: new OpenLayers.Layer.WMS("State boundary", url,
                    {layers: 'topp:tasmania_state_boundaries', format: 'image/gif', transparent: 'TRUE'},
                    {singleTile: true}),
                roads: new OpenLayers.Layer.WMS("Roads", url,
                    {layers: 'topp:tasmania_roads', format: 'image/gif', transparent: 'TRUE'},
                    {singleTile: true}),
                waterbodies: new OpenLayers.Layer.WMS("Water bodies", url,
                    {layers: 'topp:tasmania_water_bodies', format: 'image/gif', transparent: 'TRUE'},
                    {singleTile: true}),
                cities: new OpenLayers.Layer.WMS("Cities", url,
                    {layers: 'topp:tasmania_cities', format: 'image/gif', transparent: 'TRUE'},
                    {singleTile: true})
            };

            for (var key in layers) {
                map.addLayer(layers[key]);
            }

            map.setCenter(new OpenLayers.LonLat(146.65748632815,-42.230763671875), 7);

            map.addControl(new OpenLayers.Control.LayerSwitcher());

            controls = {
                navigation: new OpenLayers.Control.Navigation(),
                box: new OpenLayers.Control.SLDSelect(
                    OpenLayers.Handler.RegularPolygon,
                    {
                        displayClass: 'olControlSLDSelectBox', 
                        layers: [layers['waterbodies']],
                        handlerOptions: {irregular: true}
                    }
                ),
                polygon: new OpenLayers.Control.SLDSelect(
                    OpenLayers.Handler.Polygon,
                    {
                        displayClass: 'olControlSLDSelectPolygon',
                        layers: [layers['waterbodies']]
                    }
                ),
                line: new OpenLayers.Control.SLDSelect(
                    OpenLayers.Handler.Path,
                    {
                        displayClass: 'olControlSLDSelectLine',
                        layers: [layers['waterbodies']]
                    }
                ),
                point: new OpenLayers.Control.SLDSelect(
                    OpenLayers.Handler.Click,
                    {
                        displayClass: 'olControlSLDSelectPoint',
                        layers: [layers['waterbodies']]
                    }
                ),
                circle: new OpenLayers.Control.SLDSelect(
                    OpenLayers.Handler.RegularPolygon,
                    {
                        displayClass: 'olControlSLDSelectBox',
                        layers: [layers['waterbodies']],
                        handlerOptions: {sides: 30}
                    }
                )
            };

            for(var key in controls) {
                map.addControl(controls[key]);
            }
        }

        function toggleControl(element) {
            for(var key in controls) {
                var control = controls[key];
                if(element.value == key && element.checked) {
                    control.activate();
                } else {
                    control.deactivate();
                }
            }
        }

        function toggleSelectionLayer(element) {
            var selectLayers = [];
            var elements = element.value.split("_");
            for (var key in layers) {
                var layer = layers[key];
                for (var i=0, len=elements.length; i<len; i++) {
                    var value = elements[i];
                    if (value == key && element.checked) {
                        selectLayers.push(layer);
                    }
                }
            }
            for (var i=0, len=this.map.controls.length; i<len; i++) {
                var control = this.map.controls[i];
                if (control instanceof OpenLayers.Control.SLDSelect) {
                    control.setLayers(selectLayers);
                }
            }
        }

    </script>
  </head>
  <body onload="init()">
    <h1 id="title">SLD based selection on WMS layers</h1>

    <div id="tags">
        sld, sldselect, styling, style
    </div>

    <div id="shortdesc">Using Styled Layer Descriptors to make a selection on WMS layers</div>

    <div id="map" style="width: 512px; height: 256px; border: 1px solid red;"></div>

    <div id="docs">
        This example uses the OpenLayers.Control.SLDSelect to select features in a WMS
        layer. The features are highlighted using Styled Layer Descriptors (SLD). The
        control supports point, box, line and polygon selection modes by configuring the
        appriopriate handler.
    </div>

    <div id="controls">
        <ul id="controlToggle"><b>Map Controls</b>
            <li>
                <input type="radio" name="control" value="navigation" id="noneToggle" onclick="toggleControl(this);" CHECKED>
                <label for="noneToggle">navigate</label>
            </li>
            <li>
                <input type="radio" name="control" value="box" id="boxToggle" onclick="toggleControl(this);">
                <label for="boxToggle">SLD select with box</label>
            </li>
            <li>
                <input type="radio" name="control" value="polygon" id="polygonToggle" onclick="toggleControl(this);">
                <label for="polygonToggle">SLD select with polygon</label>
            </li>
            <li>
                <input type="radio" name="control" value="line" id="lineToggle" onclick="toggleControl(this);">
                <label for="lineToggle">SLD select with line</label>
            </li>
            <li>
                <input type="radio" name="control" value="point" id="pointToggle" onclick="toggleControl(this);">
                <label for="pointToggle">SLD select with point</label>
            </li>
            <li>
                <input type="radio" name="control" value="circle" id="circleToggle" onclick="toggleControl(this);">
                <label for="circleToggle">SLD select with circle</label>
            </li>
        </ul>
    </div>
    <div id="layers">
        <ul id="layerToggle"><b>Selection layer</b>
            <li>
                <input type="radio" name="layer" value="waterbodies" id="waterbodiesToggle" onclick="toggleSelectionLayer(this);" CHECKED>
                <label for="noneToggle">Water bodies</label>
            </li>
            <li>
                <input type="radio" name="layer" value="cities" id="citiesToggle" onclick="toggleSelectionLayer(this);">
                <label for="citiesToggle">Cities</label>
            </li>
            <li>
                <input type="radio" name="layer" value="roads" id="roadsToggle" onclick="toggleSelectionLayer(this);">
                <label for="roadsToggle">Roads</label>
            </li>
            <li>
                <input type="radio" name="layer" value="roads_cities" id="roadsCitiesToggle" onclick="toggleSelectionLayer(this);">
                <label for="roadsCitiesToggle">Roads and cities</label>
            </li>
        </ul>
    </div>

  </body>
</html>