summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Control/SLDSelect.html
blob: 03b871c5afa2b9a8f24596ab16cb4172a2e99277 (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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<html>
<head>
  <script src="../OLLoader.js"></script>
  <script type="text/javascript">

    function test_initialize(t) {
        t.plan(11);
        var control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.Click);
        t.eq(control.handler instanceof OpenLayers.Handler.Click, true, "Click handler created");
        t.ok(control.handler.callbacks["click"] === control.select, "Click callback correctly set");
        control.destroy();
        control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.RegularPolygon, {handlerOptions: {irregular: true}});
        t.eq(control.handler instanceof OpenLayers.Handler.RegularPolygon, true, "RegularPolygon handler created");
        t.eq(control.handler.irregular, true, "RegularPolygon handler is irregular");
        t.eq(control.handler.persist, false, "RegularPolygon handler is not persistant");
        t.ok(control.handler.callbacks["done"] === control.select, "Done callback correctly set");
        control.destroy();
        control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.Polygon);
        t.eq(control.handler instanceof OpenLayers.Handler.Polygon, true, "Polygon handler created");
        t.ok(control.handler.callbacks["done"] === control.select, "Done callback correctly set");
        control.destroy();
        control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.Path);
        t.eq(control.handler instanceof OpenLayers.Handler.Path, true, "Path handler created");
        t.ok(control.handler.callbacks["done"] === control.select, "Done callback correctly set");
        control.destroy();
        var layer = new OpenLayers.Layer.WMS('Foo', 'http://foo', {LAYERS: 'A'});
        control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.RegularPolygon, {layers: [layer]});
        t.eq(control.layers.length, 1, "Layers property correctly set");
        control.destroy();
        layer.destroy();
    }

    function test_select(t) {
        t.plan(9);
        var parser = new OpenLayers.Format.WFSDescribeFeatureType();
        var map = new OpenLayers.Map('map');
        var layer = new OpenLayers.Layer.WMS('Foo', 'http://foo', {LAYERS: 'AAA64'});
        map.addLayer(layer);

        var text =
            '<?xml version="1.0" encoding="ISO-8859-1" ?>' +
            '<schema' +
            '   targetNamespace="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:rws="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:ogc="http://www.opengis.net/ogc"' +
            '   xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns:gml="http://www.opengis.net/gml"' +
            '   elementFormDefault="qualified" version="0.1" >' +
            '  <import namespace="http://www.opengis.net/gml"' +
            '          schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd" />' +
            '  <element name="AAA64" ' +
            '           type="rws:AAA64Type" ' +
            '           substitutionGroup="gml:_Feature" />' +
            '  <complexType name="AAA64Type">' +
            '    <complexContent>' +
            '      <extension base="gml:AbstractFeatureType">' +
            '        <sequence>' +
            '          <element name="geometry" type="gml:MultiLineStringPropertyType" minOccurs="0" maxOccurs="1"/>' +
            '          <element name="OBJECTID" type="string"/>' +
            '        </sequence>' +
            '      </extension>' +
            '    </complexContent>' +
            '  </complexType>' +
            '</schema>';

        OpenLayers.Control.SLDSelect.prototype.wfsCache[layer.id] = parser.read(text);
        var control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.RegularPolygon,
            {layers: [layer], clearOnDeactivate: true, handlerOptions: {irregular: true} });

        var testEvent = function(evt) {
            t.eq(evt.filters.length, 1, "Event has a filters array set");
            t.eq(evt.filters[0] instanceof OpenLayers.Filter.Spatial, true, "Spatial filter has been created");
        };

        control.events.register("selected", this, testEvent);
        map.addControl(control);
        var geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
            new OpenLayers.Geometry.Point(0, 0), 5, 4);
        control.select(geometry);
        control.events.unregister("selected", this, testEvent);
        t.eq(map.layers.length, 2, "Selection layer has been created and added to the map");
        t.eq(map.layers[1] instanceof OpenLayers.Layer.WMS, true, "A WMS layer has been created as the selection layer");
        t.eq(map.layers[1].tileOptions.maxGetUrlLength, 2048, "Selection layer will automatically switch to HTTP Post if content gets longer than 2048");
        var expected_sld = '<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><sld:NamedLayer><sld:Name>AAA64</sld:Name><sld:UserStyle><sld:Name>default</sld:Name><sld:FeatureTypeStyle><sld:Rule><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:BBOX><ogc:PropertyName>geometry</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">-3.5355339059327,-3.5355339059327 3.5355339059327,3.5355339059327</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter><sld:LineSymbolizer><sld:Stroke><sld:CssParameter name="stroke">#FF0000</sld:CssParameter><sld:CssParameter name="stroke-width">2</sld:CssParameter></sld:Stroke></sld:LineSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor>';

        t.xml_eq(map.layers[1].params.SLD_BODY, expected_sld, "SLD generated correctly");

        var geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
            new OpenLayers.Geometry.Point(0, 0), 7, 4);
        control.select(geometry);
        t.eq(map.layers.length, 2, "Selection layer is reused when new selection is performed");

        map.layers[0].setVisibility(false);
        t.eq(map.layers[1].getVisibility(), false, "Visibility of selection layer is synchronized with source layer");
        // activate would issue a SLD WMS DescribeLayer request and we are bypassing this here
        control.active = true;
        control.deactivate();
        t.eq(map.layers.length, 1, "Selection layer is removed on deactive if clearOnDeactivate is set to true");
        map.destroy();
    }

    function test_filterModificationOnSelected(t) {
        t.plan(1);
        var parser = new OpenLayers.Format.WFSDescribeFeatureType();
        var map = new OpenLayers.Map('map');
        var layer = new OpenLayers.Layer.WMS('Foo', 'http://foo', {LAYERS: 'AAA64'});
        map.addLayer(layer);

        var text =
            '<?xml version="1.0" encoding="ISO-8859-1" ?>' +
            '<schema' +
            '   targetNamespace="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:rws="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:ogc="http://www.opengis.net/ogc"' +
            '   xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns:gml="http://www.opengis.net/gml"' +
            '   elementFormDefault="qualified" version="0.1" >' +
            '  <import namespace="http://www.opengis.net/gml"' +
            '          schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd" />' +
            '  <element name="AAA64" ' +
            '           type="rws:AAA64Type" ' +
            '           substitutionGroup="gml:_Feature" />' +
            '  <complexType name="AAA64Type">' +
            '    <complexContent>' +
            '      <extension base="gml:AbstractFeatureType">' +
            '        <sequence>' +
            '          <element name="geometry" type="gml:MultiLineStringPropertyType" minOccurs="0" maxOccurs="1"/>' +
            '          <element name="OBJECTID" type="string"/>' +
            '        </sequence>' +
            '      </extension>' +
            '    </complexContent>' +
            '  </complexType>' +
            '</schema>';

        OpenLayers.Control.SLDSelect.prototype.wfsCache[layer.id] = parser.read(text);
        var control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.RegularPolygon,
            {layers: [layer], clearOnDeactivate: true, handlerOptions: {irregular: true} });

        var testEvent = function(evt) {
            // manipulate filter
            var bbox = OpenLayers.Bounds.fromString('1,2,3,4');
            evt.filters[0].value = bbox;
        };
        control.events.register("selected", this, testEvent);
        map.addControl(control);
        var geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
            new OpenLayers.Geometry.Point(0, 0), 5, 4);
        control.select(geometry);
        control.events.unregister("selected", this, testEvent);

        var expected_sld = '<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><sld:NamedLayer><sld:Name>AAA64</sld:Name><sld:UserStyle><sld:Name>default</sld:Name><sld:FeatureTypeStyle><sld:Rule><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:BBOX><ogc:PropertyName>geometry</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">1,2 3,4</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter><sld:LineSymbolizer><sld:Stroke><sld:CssParameter name="stroke">#FF0000</sld:CssParameter><sld:CssParameter name="stroke-width">2</sld:CssParameter></sld:Stroke></sld:LineSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor>';

        t.xml_eq(map.layers[1].params.SLD_BODY, expected_sld, "Filter / SLD manipulated in select-callback correctly");

    }

    function test_multiselect(t) {
        t.plan(2);

        var parser = new OpenLayers.Format.WFSDescribeFeatureType();
        var map = new OpenLayers.Map('map');
        var layer = new OpenLayers.Layer.WMS('Multi', 'http://foo', {LAYERS: 'KGNAT.VKUNSTWERK,KGNAT.LKUNSTWERK,KGNAT.PKUNSTWERK'});
        map.addLayer(layer);

        var text =
            '<?xml version="1.0" encoding="ISO-8859-1" ?>' +
            '<schema' +
            '   targetNamespace="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:rws="http://mapserver.gis.umn.edu/mapserver" ' +
            '   xmlns:ogc="http://www.opengis.net/ogc"' +
            '   xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns="http://www.w3.org/2001/XMLSchema"' +
            '   xmlns:gml="http://www.opengis.net/gml"' +
            '   elementFormDefault="qualified" version="0.1" >' +
            '  <import namespace="http://www.opengis.net/gml"' +
            '          schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd" />' +
            '  <element name="KGNAT.VKUNSTWERK" ' +
            '           type="rws:KGNAT.VKUNSTWERKType" ' +
            '           substitutionGroup="gml:_Feature" />' +
            '  <complexType name="KGNAT.VKUNSTWERKType">' +
            '    <complexContent>' +
            '      <extension base="gml:AbstractFeatureType">' +
            '        <sequence>' +
            '          <element name="geometry" type="gml:MultiPolygonPropertyType" minOccurs="0" maxOccurs="1"/>' +
            '        </sequence>' +
            '      </extension>' +
            '    </complexContent>' +
            '  </complexType>' +
            '  <element name="KGNAT.LKUNSTWERK" ' +
            '           type="rws:KGNAT.LKUNSTWERKType" ' +
            '           substitutionGroup="gml:_Feature" />' +
            '  <complexType name="KGNAT.LKUNSTWERKType">' +
            '    <complexContent>' +
            '      <extension base="gml:AbstractFeatureType">' +
            '        <sequence>' +
            '          <element name="geometry" type="gml:MultiLineStringPropertyType" minOccurs="0" maxOccurs="1"/>' +
            '        </sequence>' +
            '      </extension>' +
            '    </complexContent>' +
            '  </complexType>' +
            '  <element name="KGNAT.PKUNSTWERK" ' +
            '           type="rws:KGNAT.PKUNSTWERKType" ' +
            '           substitutionGroup="gml:_Feature" />' +
            '  <complexType name="KGNAT.PKUNSTWERKType">' +
            '    <complexContent>' +
            '      <extension base="gml:AbstractFeatureType">' +
            '        <sequence>' +
            '          <element name="geometry" type="gml:MultiPointPropertyType" minOccurs="0" maxOccurs="1"/>' +
            '        </sequence>' +
            '      </extension>' +
            '    </complexContent>' +
            '  </complexType>' +
            '</schema>';

        OpenLayers.Control.SLDSelect.prototype.wfsCache[layer.id] = parser.read(text);
        var control = new OpenLayers.Control.SLDSelect(OpenLayers.Handler.RegularPolygon, {handlerOptions: {irregular: true}, layers: [layer]});
        var testEvent = function(evt) {
            t.eq(evt.filters.length, 3, "Event has a filters array set with length tree");
        };
        control.events.register("selected", this, testEvent);

        map.addControl(control);
        var geometry = OpenLayers.Geometry.Polygon.createRegularPolygon(
            new OpenLayers.Geometry.Point(0, 0), 5, 4);
        control.select(geometry);
        var expected_sld = '<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml"><sld:NamedLayer><sld:Name>KGNAT.VKUNSTWERK</sld:Name><sld:UserStyle><sld:Name>default</sld:Name><sld:FeatureTypeStyle><sld:Rule><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:BBOX><ogc:PropertyName>geometry</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">-3.5355339059327,-3.5355339059327 3.5355339059327,3.5355339059327</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter><sld:PolygonSymbolizer><sld:Fill><sld:CssParameter name="fill">#FF0000</sld:CssParameter></sld:Fill></sld:PolygonSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer><sld:NamedLayer><sld:Name>KGNAT.LKUNSTWERK</sld:Name><sld:UserStyle><sld:Name>default</sld:Name><sld:FeatureTypeStyle><sld:Rule><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:BBOX><ogc:PropertyName>geometry</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">-3.5355339059327,-3.5355339059327 3.5355339059327,3.5355339059327</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter><sld:LineSymbolizer><sld:Stroke><sld:CssParameter name="stroke">#FF0000</sld:CssParameter><sld:CssParameter name="stroke-width">2</sld:CssParameter></sld:Stroke></sld:LineSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer><sld:NamedLayer><sld:Name>KGNAT.PKUNSTWERK</sld:Name><sld:UserStyle><sld:Name>default</sld:Name><sld:FeatureTypeStyle><sld:Rule><ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:BBOX><ogc:PropertyName>geometry</ogc:PropertyName><gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:coordinates decimal="." cs="," ts=" ">-3.5355339059327,-3.5355339059327 3.5355339059327,3.5355339059327</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter><sld:PointSymbolizer><sld:Graphic><sld:Mark><sld:WellKnownName>square</sld:WellKnownName><sld:Fill><sld:CssParameter name="fill">#FF0000</sld:CssParameter></sld:Fill><sld:Stroke/></sld:Mark><sld:Size>10</sld:Size></sld:Graphic></sld:PointSymbolizer></sld:Rule></sld:FeatureTypeStyle></sld:UserStyle></sld:NamedLayer></sld:StyledLayerDescriptor>';

        t.xml_eq(map.layers[1].params.SLD_BODY, expected_sld, "SLD generated correctly");
        map.destroy();
    }
    
  </script>
</head>
<body>
    <div id="map" style="width: 100px; height: 100px;"></div>
</body>
</html>