]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Format/WMSGetFeatureInfo.html
initial commit
[syp.git] / openlayers / tests / Format / WMSGetFeatureInfo.html
1 <html> 
2 <head> 
3     <script src="../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5     
6     function test_read_FeatureInfoResponse(t) {
7         t.plan(5);
8         
9         var parser = new OpenLayers.Format.WMSGetFeatureInfo();
10
11         // read empty response
12         var text = 
13             '<?xml version="1.0" encoding="UTF-8" ?>' +
14             '<FeatureInfoResponse>' +
15             '</FeatureInfoResponse>';
16
17         var features = parser.read(text);
18         t.eq(features.length, 0,
19              "Parsing empty FeatureInfoResponse response succesfull");
20
21         // read 1 feature
22         text = 
23             '<?xml version="1.0" encoding="UTF-8" ?>' +
24             '<FeatureInfoResponse>' +
25             '  <FIELDS OBJECTID="1188" HECTARES="1819.734" ZONENR="5854" NULZONES=" " AREA="18197340.1426" PERIMETER="19177.4073627" SHAPE="NULL" SE_ANNO_CAD_DATA="NULL" SHAPE.AREA="0" SHAPE.LEN="0"/>' +
26             '</FeatureInfoResponse>';
27
28         features = parser.read(text);
29         t.eq(features.length, 1,
30              "Parsed 1 feature in total");
31
32         t.eq(features[0].attributes.OBJECTID, '1188',
33              "Attribute OBJECTID contains the right value");
34
35         // read multiple features
36         text = 
37             '<?xml version="1.0" encoding="UTF-8" ?>' +
38             '<FeatureInfoResponse>' +
39             '  <FIELDS OBJECTID="551" Shape="NULL" NAME="Carbon" STATE_NAME="Wyoming" AREA="7999.91062" POP2000="15639" POP00_SQMI="2" Shape_Length="6.61737274334215" Shape_Area="2.23938983524154"/>' +
40             '  <FIELDS OBJECTID="7" Shape="NULL" AREA="97803.199" STATE_NAME="Wyoming" SUB_REGION="Mtn" STATE_ABBR="WY" POP2000="493782" POP00_SQMI="5" Shape_Length="21.9870297323522" Shape_Area="27.9666881382635"/>' +
41             '  <FIELDS OBJECTID="99" Shape="NULL" LENGTH="378.836" TYPE="Multi-Lane Divided" ADMN_CLASS="Interstate" TOLL_RD="N" RTE_NUM1=" 80" RTE_NUM2=" " ROUTE="Interstate  80" Shape_Length="7.04294883879398"/>' +
42             '</FeatureInfoResponse>';
43
44         features = parser.read(text);
45
46         t.eq(features.length, 3,
47              "Parsed 3 features in total");
48
49         t.eq(features[1].attributes.STATE_NAME, 'Wyoming',
50              "Attribute STATE_NAME contains the right value");
51
52     }
53
54     function test_read_msGMLOutput(t) {
55         t.plan(7);
56         
57         var parser = new OpenLayers.Format.WMSGetFeatureInfo();
58
59         // read empty response
60         var text = 
61             '<?xml version="1.0" encoding="ISO-8859-1"?>' +
62             '<msGMLOutput ' +
63             '    xmlns:gml="http://www.opengis.net/gml"' +
64             '    xmlns:xlink="http://www.w3.org/1999/xlink"' +
65             '    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
66             '</msGMLOutput>';
67
68         var features = parser.read(text);
69         t.eq(features.length, 0,
70              "Parsing empty msGMLOutput response succesfull");
71
72         // read 1 feature from 1 layer
73         text = 
74             '<?xml version="1.0" encoding="ISO-8859-1"?>' +
75             '<msGMLOutput ' +
76             '    xmlns:gml="http://www.opengis.net/gml"' +
77             '    xmlns:xlink="http://www.w3.org/1999/xlink"' +
78             '    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
79             '   <AAA64_layer>' +
80             '           <AAA64_feature>' +
81             '                   <gml:boundedBy>' +
82             '                           <gml:Box srsName="EPSG:28992">' +
83             '                                   <gml:coordinates>107397.266000,460681.063000 116568.188000,480609.250000</gml:coordinates>' +
84             '                           </gml:Box>' +
85             '                   </gml:boundedBy>' +
86             '                   <OBJECTID>109</OBJECTID>' +
87             '                   <ROUTE>N231</ROUTE>' +
88             '                   <ROUTE_CH>#N231</ROUTE_CH>' +
89             '                   <COUNT>2</COUNT>' +
90             '                   <BEHEERDER>P</BEHEERDER>' +
91             '                   <LENGTH>28641.7</LENGTH>' +
92             '                   <SHAPE>&lt;shape&gt;</SHAPE>' +
93             '                   <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
94             '           </AAA64_feature>' +
95             '   </AAA64_layer>' +
96             '</msGMLOutput>';
97
98         features = parser.read(text);
99         t.eq(features.length, 1,
100              "Parsed 1 feature in total");
101
102         t.eq(features[0].attributes.OBJECTID, '109',
103              "Attribute OBJECTID contains the right value");
104
105         t.eq(features[0].type, 'AAA64',
106              "Parsed the layer name correctly");
107
108         // read 2 features from 2 layers
109         text = 
110             '<?xml version="1.0" encoding="ISO-8859-1"?>' +
111             '<msGMLOutput ' +
112             '    xmlns:gml="http://www.opengis.net/gml"' +
113             '    xmlns:xlink="http://www.w3.org/1999/xlink"' +
114             '    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
115             '   <AAA64_layer>' +
116             '           <AAA64_feature>' +
117             '                   <gml:boundedBy>' +
118             '                           <gml:Box srsName="EPSG:28992">' +
119             '                                   <gml:coordinates>129799.109000,467950.250000 133199.906000,468904.063000</gml:coordinates>' +
120             '                           </gml:Box>' +
121             '                   </gml:boundedBy>' +
122             '                   <OBJECTID>287</OBJECTID>' +
123             '                   <ROUTE>N403</ROUTE>' +
124             '                   <ROUTE_CH>#N403</ROUTE_CH>' +
125             '                   <COUNT>1</COUNT>' +
126             '                   <BEHEERDER>P</BEHEERDER>' +
127             '                   <LENGTH>4091.25</LENGTH>' +
128             '                   <SHAPE>&lt;shape&gt;</SHAPE>' +
129             '                   <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
130             '           </AAA64_feature>' +
131             '   </AAA64_layer>' +
132             '   <AAA62_layer>' +
133             '           <AAA62_feature>' +
134             '                   <gml:boundedBy>' +
135             '                           <gml:Box srsName="EPSG:28992">' +
136             '                                   <gml:coordinates>129936.000000,468362.000000 131686.000000,473119.000000</gml:coordinates>' +
137             '                           </gml:Box>' +
138             '                   </gml:boundedBy>' +
139             '                   <OBJECTID>1251</OBJECTID>' +
140             '                   <VWK_ID>1515</VWK_ID>' +
141             '                   <VWK_BEGDTM>00:00:00 01/01/1998</VWK_BEGDTM>' +
142             '                   <VWJ_ID_BEG>1472</VWJ_ID_BEG>' +
143             '                   <VWJ_ID_END>1309</VWJ_ID_END>' +
144             '                   <VAKTYPE>D</VAKTYPE>' +
145             '                   <VRT_CODE>227</VRT_CODE>' +
146             '                   <VRT_NAAM>Vecht</VRT_NAAM>' +
147             '                   <VWG_NR>2</VWG_NR>' +
148             '                   <VWG_NAAM>Vecht</VWG_NAAM>' +
149             '                   <BEGKM>18.25</BEGKM>' +
150             '                   <ENDKM>23.995</ENDKM>' +
151             '                   <LENGTH>5745.09</LENGTH>' +
152             '                   <SHAPE>&lt;shape&gt;</SHAPE>' +
153             '                   <SE_ANNO_CAD_DATA>&lt;null&gt;</SE_ANNO_CAD_DATA>' +
154             '           </AAA62_feature>' +
155             '   </AAA62_layer>' +
156             '</msGMLOutput>';
157
158         features = parser.read(text);
159
160         t.eq(features.length, 2,
161              "Parsed 2 features in total");
162
163         t.eq((features[0].type == features[1].type), false,
164              "The layer name differs for the two features");
165
166         text =
167             '<?xml version="1.0" encoding="ISO-8859-1"?>' +
168             '<msGMLOutput ' +
169             '        xmlns:gml="http://www.opengis.net/gml"' +
170             '        xmlns:xlink="http://www.w3.org/1999/xlink"' +
171             '        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
172             '       <wegbeheerderinfo_layer>' +
173             '               <wegbeheerderinfo_feature>' +
174             '                       <gml:boundedBy>' +
175             '                               <gml:Box srsName="EPSG:28992">' +
176             '                                       <gml:coordinates>105002.943000,490037.863000 105271.523000,490262.208000</gml:coordinates>' +
177             '                               </gml:Box>' +
178             '                       </gml:boundedBy>' +
179             '                       <geometry>' +
180             '                       <gml:MultiLineString srsName="EPSG:28992">' +
181             '                         <gml:lineStringMember>' +
182             '                           <gml:LineString>' +
183             '                             <gml:coordinates>105270.164000,490262.208000 105098.274000,490258.040000 105028.045000,490089.576000 105002.943000,490048.851000 105049.666000,490037.863000 105271.523000,490064.957000 </gml:coordinates>' +
184             '                           </gml:LineString>' +
185             '                         </gml:lineStringMember>' +
186             '                       </gml:MultiLineString>' +
187             '                       </geometry>' +
188             '                       <OGR_FID>203327</OGR_FID>' +
189             '               </wegbeheerderinfo_feature>' +
190             '       </wegbeheerderinfo_layer>' +
191             '</msGMLOutput>';
192
193         features = parser.read(text);
194
195         t.eq((features[0].geometry instanceof OpenLayers.Geometry.MultiLineString), true,
196             "Parsed geometry is of type multi line string");
197
198     }
199
200     function test_read_GMLFeatureInfoResponse(t) {
201         t.plan(4);
202         
203         var parser = new OpenLayers.Format.WMSGetFeatureInfo();
204
205         // read Ionic response, see if parser falls back to GML format
206         // url used:
207         /* http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA?service=WMS&request=GetFeatureInfo&layers=roads&version=1.1.1&bbox=-71.1,42.25,-71.05,42.3&width=500&height=500&format=image/png&SRS=EPSG:4326&styles=&x=174&y=252&query_layers=roads&info_format=application/vnd.ogc.gml */
208         var text = 
209             "<?xml version='1.0' encoding='utf-8' ?>" + 
210             '  <ogcwfs:FeatureCollection xsi:schemaLocation="http://www.ionicsoft.com/wfs http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA?REQUEST=DescribeAllFeatureType&amp;SERVICE=WFS http://www.opengis.net/wfs http://webservices.ionicsoft.com/ionicweb/wfs/BOSTON_ORA/REQUEST/get/DATA/LPR/wfs/1.0.0/WFS-basic.xsd" xmlns:wfs="http://www.ionicsoft.com/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ogcwfs="http://www.opengis.net/wfs">' +
211             '    <gml:boundedBy>' +
212             '      <gml:Box srsName="EPSG:4326">' +
213             '        <gml:coordinates>-71.08301710045646,42.27320863544783 -71.08020014900377,42.27480054530114</gml:coordinates>' +
214             '      </gml:Box>' +
215             '    </gml:boundedBy>' +
216             '  <gml:featureMember>' +
217             '    <wfs:roads fid="roads.9453.0">' +
218             '      <wfs:FNODE_>8943.0</wfs:FNODE_>' +
219             '      <wfs:TNODE_>9070.0</wfs:TNODE_>' +
220             '      <wfs:LPOLY_>0.0</wfs:LPOLY_>' +
221             '      <wfs:RPOLY_>0.0</wfs:RPOLY_>' +
222             '      <wfs:LENGTH>306.875</wfs:LENGTH>' +
223             '      <wfs:MRD_>13109.0</wfs:MRD_>' +
224             '      <wfs:MRD_ID>9453.0</wfs:MRD_ID>' +
225             '      <wfs:TILE_NAME>126</wfs:TILE_NAME>' +
226             '      <wfs:COUNTYCODE>M</wfs:COUNTYCODE>' +
227             '      <wfs:SERIAL_NUM>26000.0</wfs:SERIAL_NUM>' +
228             '      <wfs:CLASS>5.0</wfs:CLASS>' +
229             '      <wfs:ADMIN_TYPE>0.0</wfs:ADMIN_TYPE>' +
230             '      <wfs:ALTRT1TYPE>0.0</wfs:ALTRT1TYPE>' +
231             '      <wfs:STREETNAME>DOCTOR MARY MOORE BEATTY CIRCLE</wfs:STREETNAME>' +
232             '      <wfs:CSN>M  26000</wfs:CSN>' +
233             '      <wfs:GEOMETRY>' +
234             '        <gml:LineString srsName="EPSG:4326">' +
235             '          <gml:coordinates>-71.08300668868151,42.27480054530114 -71.08155305289881,42.27452010256956 -71.08021063085208,42.27320863544783</gml:coordinates>' +
236             '        </gml:LineString>' +
237             '      </wfs:GEOMETRY>' +
238             '    </wfs:roads>' +
239             '  </gml:featureMember>' +
240             '  </ogcwfs:FeatureCollection>';
241
242         var features = parser.read(text);
243
244         t.eq(features.length, 1,
245              "Parsing GML GetFeatureInfo response from Ionic succesfull");
246
247         t.eq(features[0].attributes.TILE_NAME, '126',
248              "Attribute TILE_NAME contains the right value");
249
250         // read Geoserver response
251         // taken from:
252 /* http://demo.opengeo.org/geoserver/wms?service=WMS&request=GetFeatureInfo&layers=opengeo:roads&query_layers=opengeo:roads&format=image/png&version=1.1.1&styles=&bbox=-103.9,44.4,-103.7,44.5&srs=EPSG:4326&width=500&height=500&x=158&y=98&info_format=application/vnd.ogc.gml*/
253
254         text = '<?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:opengeo="http://opengeo.org" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://opengeo.org http://demo.opengeo.org:80/geoserver/wfs?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;typeName=opengeo:roads http://www.opengis.net/wfs http://demo.opengeo.org:80/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd"><gml:boundedBy><gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#26713"><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">591943.9375,4925605 593045.625,4925845</gml:coordinates></gml:Box></gml:boundedBy><gml:featureMember><opengeo:roads fid="roads.90"><opengeo:cat>3</opengeo:cat><opengeo:label>secondary highway, hard surface</opengeo:label><opengeo:the_geom><gml:MultiLineString srsName="http://www.opengis.net/gml/srs/epsg.xml#26713"><gml:lineStringMember><gml:LineString><gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">593045.60746465,4925605.0059156 593024.32382915,4925606.79305411 592907.54863574,4925624.85647524 592687.35111096,4925670.76834012 592430.76279218,4925678.79393165 592285.97636109,4925715.70811767 592173.39165655,4925761.83511156 592071.1753393,4925793.95523514 591985.96972625,4925831.59842486 591943.98769455,4925844.93220071</gml:coordinates></gml:LineString></gml:lineStringMember></gml:MultiLineString></opengeo:the_geom></opengeo:roads></gml:featureMember></wfs:FeatureCollection>';
255
256         features = parser.read(text);
257
258         t.eq(features.length, 1,
259              "Parsing GML GetFeatureInfo response from Geoserver succesfull");
260
261         t.eq(features[0].attributes.cat, '3',
262              "Attribute cat contains the right value");
263
264     }
265     
266
267     </script> 
268 </head> 
269 <body>
270 </body> 
271 </html>