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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
<html>
<head>
<script src="../../OLLoader.js"></script>
<script type="text/javascript">
function test_write_wmc_StyleList(t) {
t.plan(4);
var layer, layerContext, got, expected;
var format = new OpenLayers.Format.WMC();
var parser = format.getParser("1");
var name = "test";
var url = "http://foo";
// test named style
layer = new OpenLayers.Layer.WMS(name, url, {
styles: "mystyle"
});
layerContext = format.layerToContext(layer);
got = parser.write_wmc_StyleList(layerContext);
expected =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<Name>mystyle</Name><Title>Default</Title>" +
"</Style>" +
"</StyleList>";
t.xml_eq(got, expected, "named style correctly written");
layer.destroy();
// test linked style
layer = new OpenLayers.Layer.WMS(name, url, {
sld: "http://linked.sld"
});
layerContext = format.layerToContext(layer);
got = parser.write_wmc_StyleList(layerContext);
expected =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
"<Title>Default</Title>" +
"<OnlineResource xmlns:xlink='http://www.w3.org/1999/xlink' "+
"xlink:type='simple' " +
"xlink:href='http://linked.sld' />" +
"</SLD>" +
"</Style>" +
"</StyleList>";
t.xml_eq(got, expected, "linked style correctly written");
layer.destroy();
// test inline style
layer = new OpenLayers.Layer.WMS(name, url, {
sld_body:
"<sld:StyledLayerDescriptor version='1.0.0' " +
"xmlns:ogc='http://www.opengis.net/ogc' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<sld:NamedLayer>" +
"<sld:Name>AAA212</sld:Name>" +
"<sld:UserStyle>" +
"<sld:FeatureTypeStyle>" +
"<sld:Rule>" +
"<sld:TextSymbolizer>" +
"<sld:Label>" +
"<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
"</sld:Label>" +
"<sld:Font>" +
"<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
"<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
"</sld:Font>" +
"<sld:Fill>" +
"<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
"</sld:Fill>" +
"</sld:TextSymbolizer>" +
"</sld:Rule>" +
"</sld:FeatureTypeStyle>" +
"</sld:UserStyle>" +
"</sld:NamedLayer>" +
"</sld:StyledLayerDescriptor>"
});
layerContext = format.layerToContext(layer);
got = parser.write_wmc_StyleList(layerContext);
expected =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
"<Title>Default</Title>" +
"<sld:StyledLayerDescriptor version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:ogc='http://www.opengis.net/ogc' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<sld:NamedLayer>" +
"<sld:Name>AAA212</sld:Name>" +
"<sld:UserStyle>" +
"<sld:FeatureTypeStyle>" +
"<sld:Rule>" +
"<sld:TextSymbolizer>" +
"<sld:Label>" +
"<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
"</sld:Label>" +
"<sld:Font>" +
"<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
"<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
"</sld:Font>" +
"<sld:Fill>" +
"<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
"</sld:Fill>" +
"</sld:TextSymbolizer>" +
"</sld:Rule>" +
"</sld:FeatureTypeStyle>" +
"</sld:UserStyle>" +
"</sld:NamedLayer>" +
"</sld:StyledLayerDescriptor>" +
"</SLD>" +
"</Style>" +
"</StyleList>";
t.xml_eq(got, expected, "inline style correctly written");
layer.destroy();
// test inline FeatureTypeStyle
layer = new OpenLayers.Layer.WMS(name, url, {
sld_body:
"<sld:FeatureTypeStyle version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:ogc='http://www.opengis.net/ogc' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<sld:Rule>" +
"<sld:TextSymbolizer>" +
"<sld:Label>" +
"<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
"</sld:Label>" +
"<sld:Font>" +
"<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
"<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
"</sld:Font>" +
"<sld:Fill>" +
"<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
"</sld:Fill>" +
"</sld:TextSymbolizer>" +
"</sld:Rule>" +
"</sld:FeatureTypeStyle>"
});
layerContext = format.layerToContext(layer);
got = parser.write_wmc_StyleList(layerContext);
expected =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
"<Title>Default</Title>" +
"<sld:FeatureTypeStyle version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:ogc='http://www.opengis.net/ogc' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<sld:Rule>" +
"<sld:TextSymbolizer>" +
"<sld:Label>" +
"<ogc:PropertyName>ZONENR</ogc:PropertyName>" +
"</sld:Label>" +
"<sld:Font>" +
"<sld:CssParameter name='font-family'>Arial</sld:CssParameter>" +
"<sld:CssParameter name='font-size'>10</sld:CssParameter>" +
"</sld:Font>" +
"<sld:Fill>" +
"<sld:CssParameter name='fill'>#FF9900</sld:CssParameter>" +
"</sld:Fill>" +
"</sld:TextSymbolizer>" +
"</sld:Rule>" +
"</sld:FeatureTypeStyle>" +
"</SLD>" +
"</Style>" +
"</StyleList>";
t.xml_eq(got, expected, "inline FeatureTypeStyle correctly written");
layer.destroy();
}
function test_read_wmc_StyleList(t) {
t.plan(3);
var xml = new OpenLayers.Format.XML();
var format = new OpenLayers.Format.WMC();
var parser = format.getParser("1");
var node, text, layerContext, layer;
// test named style
text =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<Name>mystyle</Name><Title>Default</Title>" +
"</Style>" +
"</StyleList>";
node = xml.read(text).documentElement;
layerContext = {
styles: []
};
parser.read_wmc_StyleList(layerContext, node);
layer = format.getLayerFromContext(layerContext);
t.eq(layer.params.STYLES, "mystyle", "named style correctly read");
// test linked style
text =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
"<OnlineResource xmlns:xlink='http://www.w3.org/1999/xlink' "+
"xlink:type='simple' " +
"xlink:href='http://linked.sld' />" +
"</SLD>" +
"</Style>" +
"</StyleList>";
node = xml.read(text).documentElement;
layerContext = {
styles: []
};
parser.read_wmc_StyleList(layerContext, node);
layer = format.getLayerFromContext(layerContext);
t.eq(layer.params.SLD, "http://linked.sld", "linked style correctly read");
// test inline style
// any valid xml under the StyledLayerDescriptor node should make the
// round trip from string to node and back
text =
"<StyleList xmlns='http://www.opengis.net/context'>" +
"<Style current='1'>" +
"<SLD>" +
"<sld:StyledLayerDescriptor version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<foo>bar<more/></foo>" +
"</sld:StyledLayerDescriptor>" +
"</SLD>" +
"</Style>" +
"</StyleList>";
node = xml.read(text).documentElement;
layerContext = {
styles: []
};
parser.read_wmc_StyleList(layerContext, node);
layer = format.getLayerFromContext(layerContext);
var expected =
"<sld:StyledLayerDescriptor version='1.0.0' " +
"xmlns:sld='http://www.opengis.net/sld' " +
"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xsi:schemaLocation='http://www.opengis.net/sld http://schemas.opengeospatial.net/sld/1.0.0/StyledLayerDescriptor.xsd'>" +
"<foo xmlns='http://www.opengis.net/context'>bar<more/></foo>" +
"</sld:StyledLayerDescriptor>";
t.xml_eq(layer.params.SLD_BODY, expected, "inline style correctly read");
}
</script>
</head>
<body>
</body>
</html>
|