1 | <!DOCTYPE html> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
---|
5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> |
---|
6 | <meta name="apple-mobile-web-app-capable" content="yes"> |
---|
7 | <title>OpenLayers SLD Parser</title> |
---|
8 | <link rel="stylesheet" href="../theme/default/style.css" type="text/css"> |
---|
9 | <link rel="stylesheet" href="style.css" type="text/css"> |
---|
10 | <script src="../lib/OpenLayers.js"></script> |
---|
11 | <style> |
---|
12 | #input { |
---|
13 | width: 90%; |
---|
14 | height: 300px; |
---|
15 | } |
---|
16 | #output { |
---|
17 | width: 90%; |
---|
18 | height: 300px; |
---|
19 | } |
---|
20 | </style> |
---|
21 | </head> |
---|
22 | <body> |
---|
23 | <h1 id="title">SLD Parser</h1> |
---|
24 | <div id="tags"> |
---|
25 | sld, sldselect, styling, style, parser, cleanup |
---|
26 | </div> |
---|
27 | <div id="shortdesc">Parsing Styled Layer Descriptor (SLD) documents with the SLD format.</div> |
---|
28 | |
---|
29 | <textarea id="input">paste SLD here</textarea><br> |
---|
30 | <input type="checkbox" id="symbolizers" checked="checked"><label for="symbolizers">Maintain multiple symbolizers and FeatureTypeStyle elements</label><br> |
---|
31 | <input type="checkbox" id="array"><label for="array">Compile an array of named styles instead of an object.</label><br> |
---|
32 | <input type="button" id="button" value="Parse SLD"> |
---|
33 | |
---|
34 | <div id="docs"> |
---|
35 | This example uses the SLD format to parse SLD documents pasted into the textarea above. |
---|
36 | A rough representation of the parsed style is shown in the textarea below. |
---|
37 | </div> |
---|
38 | |
---|
39 | <textarea id="output"></textarea> |
---|
40 | |
---|
41 | <script> |
---|
42 | |
---|
43 | var button = document.getElementById("button"); |
---|
44 | var input = document.getElementById("input"); |
---|
45 | var output = document.getElementById("output"); |
---|
46 | var symbolizers = document.getElementById("symbolizers"); |
---|
47 | var array = document.getElementById("array"); |
---|
48 | |
---|
49 | var json = new OpenLayers.Format.JSON(); |
---|
50 | |
---|
51 | var format, obj; |
---|
52 | |
---|
53 | button.onclick = function() { |
---|
54 | var str = input.value; |
---|
55 | format = new OpenLayers.Format.SLD({ |
---|
56 | multipleSymbolizers: !!symbolizers.checked, |
---|
57 | namedLayersAsArray: !!array.checked |
---|
58 | }); |
---|
59 | obj = format.read(str); |
---|
60 | try { |
---|
61 | output.value = json.write(obj, true); |
---|
62 | } catch (err) { |
---|
63 | output.value = "Trouble: " + err; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | </script> |
---|
68 | |
---|
69 | </body> |
---|
70 | </html> |
---|