Talking to OGC Web Services in JSON
Or How I Learned to Stop Worrying and Love XML Processing in JavaScript
1
Talking to OGC Web Services in JSON Or How I Learned to Stop - - PowerPoint PPT Presentation
Talking to OGC Web Services in JSON Or How I Learned to Stop Worrying and Love XML Processing in JavaScript 1 Hi, my name is Alexey Valikov http://xing.to/va https://github.com/highsource @orless 2 and Im (also) into GIS and
1
2
3
4
{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [125.6, 10.1] }, "properties": { "name": "Dinagat Islands" } }
5
6
7
GetCapabilities <wfs:WFS_Capabilities … /> GetFeature <wfs:FeatureCollection … /> Client WFS Server
8
JS App WFS Server {”JS”:”ON”} ??? XSD
9
<x:ml/>
Mapping
10
WFS Server {”JS”:”ON”}
XSD <x:ml/> JS App
11
12
13
var getCapabilitiesUrl = …; // First we create a context for XLink and WMS mappings var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0], …); // Then we create an unmarshaller (parser) var unmarshaller = context.createUnmarshaller(); // And finally use this unmarshaller // to parse an XML document from the given URL unmarshaller.unmarshalURL(getCapabilitiesUrl, function(result) { // We’ll get results in a callback function $('#json').html(JSON.stringify(result, null, 2)); });
14
<WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1">…</Layer> <Layer queryable="1" opaque="0">…</Layer> … </Layer> </Capability> </WMS_Capabilities> { "WMS_Capabilities": { "version": "1.3.0", "updateSequence": "163", "service": { … }, "capability": { "request": { … }, "exception": { … }, "layer": { … , "layer": [ … ] } } } }
15
16
17
18
19
20
<WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <!-- Just one Layer element --> <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities>
21
22
<WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities>
23
24
<WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities>
25
26
<WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities>
27
28
29
30
Jsonix Runtime XSD Mapping Jsonix Schema Compiler {“JS”:”ON”} <x:ml/>
31
32
Jsonix Runtime XSD Mapping Jsonix Schema Compiler {“JS”:”ON”} <x:ml/>
33
JSON Schema
Experimental
java -jar jsonix-schema-compiler.jar
// Load JSON Schemas var ajv = new Ajv(); ajv.addSchema(XMLSchemaJsonSchema, … ); ajv.addSchema(JsonixJsonSchema, … ); ajv.addSchema(XLink_1_0JsonSchema, 'http://www.w3.org/1999/xlink'); // Compile the validation function and validate var validate = ajv.compile(WMS_1_3_0JsonSchema); if (!validate(capabilitiesElement)) { console.log(validate.errors); }
34
[{ keyword: 'required', dataPath: '.value.capability.request.getCapabilities.dcpType[\'0\'].http', message: 'property .http is required' }, … ]
35
By Alex E. Proimos (http://www.flickr. com/photos/proimos/4199675334/) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
36
37
38
var mappings = [XLink_1_0, SMIL_2_0, SMIL_2_0_Language, GML_3_1_1, OWS_1_0_0, Filter_1_1_0, DC_1_1, DCT, CSW_2_0_2]; // Create a Jsonix context var context = new Jsonix.Context(mappings, { namespacePrefixes: { "http://www.opengis.net/cat/csw/2.0.2": "csw", "http://www.opengis.net/ogc": "ogc", "http://www.opengis.net/gml": "gml" } });
JSFiddle: http://bit.do/jsonix-007
39
40
41