1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
---|
2 | * full list of contributors). Published under the Clear BSD license. |
---|
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the |
---|
4 | * full text of the license. */ |
---|
5 | |
---|
6 | /** |
---|
7 | * @requires OpenLayers/Format/Context.js |
---|
8 | */ |
---|
9 | |
---|
10 | /** |
---|
11 | * Class: OpenLayers.Format.OWSContext |
---|
12 | * Read and write OWS Context documents. OWS Context documents are a |
---|
13 | * preliminary OGC (Open Geospatial Consortium) standard for storing the |
---|
14 | * state of a web mapping application. In a way it is the successor to |
---|
15 | * Web Map Context (WMC), since it is more generic and more types of layers |
---|
16 | * can be stored. Also, nesting of layers is supported since version 0.3.1. |
---|
17 | * For more information see: http://www.ogcnetwork.net/context |
---|
18 | */ |
---|
19 | OpenLayers.Format.OWSContext = OpenLayers.Class(OpenLayers.Format.Context,{ |
---|
20 | |
---|
21 | /** |
---|
22 | * APIProperty: defaultVersion |
---|
23 | * {String} Version number to assume if none found. Default is "0.3.1". |
---|
24 | */ |
---|
25 | defaultVersion: "0.3.1", |
---|
26 | |
---|
27 | /** |
---|
28 | * Method: getParser |
---|
29 | * Get the OWSContext parser given a version. Create a new parser if it does not |
---|
30 | * already exist. |
---|
31 | * |
---|
32 | * Parameters: |
---|
33 | * version - {String} The version of the parser. |
---|
34 | * |
---|
35 | * Returns: |
---|
36 | * {<OpenLayers.Format.OWSContext>} An OWSContext parser. |
---|
37 | */ |
---|
38 | getParser: function(version) { |
---|
39 | var v = version || this.version || this.defaultVersion; |
---|
40 | // 0.3.1 is backwards compatible with 0.3.0 |
---|
41 | if (v === "0.3.0") { |
---|
42 | v = this.defaultVersion; |
---|
43 | } |
---|
44 | if(!this.parser || this.parser.VERSION != v) { |
---|
45 | var format = OpenLayers.Format.OWSContext[ |
---|
46 | "v" + v.replace(/\./g, "_") |
---|
47 | ]; |
---|
48 | if(!format) { |
---|
49 | throw "Can't find a OWSContext parser for version " + v; |
---|
50 | } |
---|
51 | this.parser = new format(this.options); |
---|
52 | } |
---|
53 | return this.parser; |
---|
54 | }, |
---|
55 | |
---|
56 | /** |
---|
57 | * Method: toContext |
---|
58 | * Create a context object free from layer given a map or a |
---|
59 | * context object. |
---|
60 | * |
---|
61 | * Parameters: |
---|
62 | * obj - {<OpenLayers.Map> | Object} The map or context. |
---|
63 | * |
---|
64 | * Returns: |
---|
65 | * {Object} A context object. |
---|
66 | */ |
---|
67 | toContext: function(obj) { |
---|
68 | var context = {}; |
---|
69 | if(obj.CLASS_NAME == "OpenLayers.Map") { |
---|
70 | context.bounds = obj.getExtent(); |
---|
71 | context.maxExtent = obj.maxExtent; |
---|
72 | context.projection = obj.projection; |
---|
73 | context.size = obj.getSize(); |
---|
74 | context.layers = obj.layers; |
---|
75 | } |
---|
76 | return context; |
---|
77 | }, |
---|
78 | |
---|
79 | CLASS_NAME: "OpenLayers.Format.OWSContext" |
---|
80 | |
---|
81 | }); |
---|