Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Format/OWSContext/v0_3_1.js @ 76

Revision 76, 23.0 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

  • Property svn:executable set to *
Line 
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/XML.js
8 * @requires OpenLayers/Format/KML.js
9 * @requires OpenLayers/Format/GML.js
10 * @requires OpenLayers/Format/GML/v2.js
11 * @requires OpenLayers/Format/SLD/v1_0_0.js
12 * @requires OpenLayers/Format/OWSContext.js
13 * @requires OpenLayers/Format/OWSCommon/v1_0_0.js
14 */
15
16/**
17 * Class: OpenLayers.Format.OWSContext.v0_3_1
18 * Read and write OWSContext version 0.3.1.
19 *
20 * Inherits from:
21 *  - <OpenLayers.Format.XML>
22 */
23OpenLayers.Format.OWSContext.v0_3_1 = OpenLayers.Class(OpenLayers.Format.XML, {
24   
25    /**
26     * Property: namespaces
27     * {Object} Mapping of namespace aliases to namespace URIs.
28     */
29    namespaces: {
30        owc: "http://www.opengis.net/ows-context",
31        gml: "http://www.opengis.net/gml",
32        kml: "http://www.opengis.net/kml/2.2",
33        ogc: "http://www.opengis.net/ogc",
34        ows: "http://www.opengis.net/ows",
35        sld: "http://www.opengis.net/sld",
36        xlink: "http://www.w3.org/1999/xlink",
37        xsi: "http://www.w3.org/2001/XMLSchema-instance"
38    },
39
40    /**
41     * Constant: VERSION
42     * {String} 0.3.1
43     */
44    VERSION: "0.3.1", 
45
46    /**
47     * Property: schemaLocation
48     * {String} Schema location
49     */
50    schemaLocation: "http://www.opengis.net/ows-context http://www.ogcnetwork.net/schemas/owc/0.3.1/owsContext.xsd",
51
52    /**
53     * Property: defaultPrefix
54     * {String} Default namespace prefix to use.
55     */
56    defaultPrefix: "owc",
57
58    /**
59     * APIProperty: extractAttributes
60     * {Boolean} Extract attributes from GML.  Default is true.
61     */
62    extractAttributes: true,
63   
64    /**
65     * APIProperty: xy
66     * {Boolean} Order of the GML coordinate true:(x,y) or false:(y,x)
67     * Changing is not recommended, a new Format should be instantiated.
68     */ 
69    xy: true, 
70
71    /**
72     * Property: regExes
73     * Compiled regular expressions for manipulating strings.
74     */
75    regExes: {
76        trimSpace: (/^\s*|\s*$/g),
77        removeSpace: (/\s*/g),
78        splitSpace: (/\s+/),
79        trimComma: (/\s*,\s*/g)
80    },
81
82    /**
83     * Property: featureNS
84     * {String} The namespace uri to use for writing InlineGeometry
85     */
86    featureNS: "http://mapserver.gis.umn.edu/mapserver",
87
88    /**
89     * Property: featureType
90     * {String} The name to use as the feature type when writing out
91     *     InlineGeometry
92     */
93    featureType: 'vector',
94             
95    /**
96     * Property: geometryName
97     * {String} The name to use for the geometry attribute when writing out
98     *     InlineGeometry
99     */
100    geometryName: 'geometry',
101
102    /**
103     * Property: nestingLayerLookup
104     * {Object} Hashtable lookup for nesting layer nodes. Used while writing
105     *     the OWS context document. It is necessary to keep track of the
106     *     nestingPaths for which nesting layer nodes have already been
107     *     created, so (nesting) layer nodes are added to those nodes.
108     *
109     * For example:
110     *
111     *     If there are three layers with nestingPaths:
112     *         layer1.metadata.nestingPath = "a/b/"
113     *         layer2.metadata.nestingPath = "a/b/"
114     *         layer2.metadata.nestingPath = "a/c"
115     *
116     *     then a nesting layer node "a" should be created once and added
117     *     to the resource list, a nesting layer node "b" should be created
118     *     once and added under "a", and a nesting layer node "c" should be
119     *     created and added under "a". The lookup paths for these nodes
120     *     will be "a", "a/b", and "a/c" respectively.
121     */
122    nestingLayerLookup: null,
123
124    /**
125     * Constructor: OpenLayers.Format.OWSContext.v0_3_1
126     * Instances of this class are not created directly.  Use the
127     *     <OpenLayers.Format.OWSContext> constructor instead.
128     *
129     * Parameters:
130     * options - {Object} An optional object whose properties will be set on
131     *     this instance.
132     */
133    initialize: function(options) {
134        OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
135        OpenLayers.Format.GML.v2.prototype.setGeometryTypes.call(this);
136    },
137
138    /**
139     * Method: setNestingPath
140     * Set the nestingPath property of the layer depending on the position
141     *     of the layer in hierarchy of layers.
142     *
143     * Parameters:
144     * l - {Object} An object that may have a layersContext array property.
145     *
146     */
147    setNestingPath : function(l){
148        if(l.layersContext){
149            for (var i = 0, len = l.layersContext.length; i < len; i++) {
150                var layerContext = l.layersContext[i];
151                var nPath = [];
152                var nTitle = l.title || "";
153                if(l.metadata && l.metadata.nestingPath){
154                    nPath = l.metadata.nestingPath.slice();
155                }
156                if (nTitle != "") {
157                    nPath.push(nTitle);
158                }
159                layerContext.metadata.nestingPath = nPath;
160                if(layerContext.layersContext){
161                    this.setNestingPath(layerContext);
162                }
163            }
164        }
165    },
166
167    /**
168     * Function: decomposeNestingPath
169     * Takes a nestingPath like "a/b/c" and decomposes it into subpaths:
170     * "a", "a/b", "a/b/c"
171     *
172     * Parameters:
173     * nPath  - {Array} the nesting path
174     *
175     * Returns:
176     * Array({String}) Array with subpaths, or empty array if there is nothing
177     *     to decompose
178     */
179    decomposeNestingPath: function(nPath){
180        var a = [];
181        if (nPath instanceof Array) {
182            while (nPath.length > 0) {
183                a.push(nPath.slice());
184                nPath.pop();
185            }
186            a.reverse();
187        }
188        return a;
189    },
190
191    /**
192     * APIMethod: read
193     * Read OWS context data from a string or DOMElement, and return a list
194     *     of layers.
195     *
196     * Parameters:
197     * data - {String} or {DOMElement} data to read/parse.
198     *
199     * Returns:
200     * {Object} The context object with a flat layer list as a property named
201     *     layersContext.
202     */
203    read: function(data) {
204        if(typeof data == "string") {
205            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
206        }
207        if(data && data.nodeType == 9) {
208            data = data.documentElement;
209        }
210        var context = {};
211        this.readNode(data, context);
212        // since an OWSContext can be nested we need to go through this
213        // structure recursively     
214        this.setNestingPath({layersContext : context.layersContext});
215        // after nesting path has been set, create a flat list of layers
216        var layers = [];
217        this.processLayer(layers, context);
218        delete context.layersContext;
219        context.layersContext = layers;
220        return context;
221    },
222
223    /**
224     * Method: processLayer
225     * Recursive function to get back a flat list of layers from the hierarchic
226     *     layer structure.
227     *
228     * Parameters:
229     * layerArray - {Array({Object})} Array of layerContext objects
230     * layerContext - {Object} layerContext object
231     */
232    processLayer: function(layerArray, layer) {
233        if (layer.layersContext) {
234            for (var i=0, len = layer.layersContext.length; i<len; i++) {
235                var l = layer.layersContext[i];
236                layerArray.push(l);
237                if (l.layersContext) {
238                    this.processLayer(layerArray, l);
239                }
240            }
241        }
242    },
243
244    /**
245     * APIMethod: write
246     *
247     * Parameters:
248     * context - {Object} An object representing the map context.
249     * options - {Object} Optional object.
250     *
251     * Returns:
252     * {String} An OWS Context document string.
253     */
254    write: function(context, options) {
255        var name = "OWSContext";
256        this.nestingLayerLookup = {}; //start with empty lookup
257        options = options || {};
258        OpenLayers.Util.applyDefaults(options, context);
259        var root = this.writeNode(name, options);
260        this.nestingLayerLookup = null; //clear lookup
261        this.setAttributeNS(
262            root, this.namespaces["xsi"],
263            "xsi:schemaLocation", this.schemaLocation
264        );
265        return OpenLayers.Format.XML.prototype.write.apply(this, [root]);
266    }, 
267
268    /**
269     * Property: readers
270     * Contains public functions, grouped by namespace prefix, that will
271     *     be applied when a namespaced node is found matching the function
272     *     name.  The function will be applied in the scope of this parser
273     *     with two arguments: the node being read and a context object passed
274     *     from the parent.
275     */
276    readers: {
277        "kml": {
278            "Document": function(node, obj) {
279                obj.features = new OpenLayers.Format.KML(
280                    {kmlns: this.namespaces.kml, 
281                        extractStyles: true}).read(node);
282            }
283        },
284        "owc": { 
285            "OWSContext": function(node, obj) {
286                this.readChildNodes(node, obj);
287            }, 
288            "General": function(node, obj) {
289                this.readChildNodes(node, obj);
290            },
291            "ResourceList": function(node, obj) {
292                this.readChildNodes(node, obj);
293            },
294            "Layer": function(node, obj) {
295                var layerContext = {
296                    metadata: {},
297                    visibility: (node.getAttribute("hidden") != "1"),
298                    queryable: (node.getAttribute("queryable") == "1"),
299                    opacity: ((node.getAttribute("opacity") != null) ? 
300                        parseFloat(node.getAttribute("opacity")) : null),
301                    name: node.getAttribute("name"),
302                    /* A category layer is a dummy layer meant for creating
303                       hierarchies. It is not a physical layer in the
304                       OpenLayers sense. The assumption we make here is that
305                       category layers do not have a name attribute */
306                    categoryLayer: (node.getAttribute("name") == null),
307                    formats: [],
308                    styles: []
309                };
310                if (!obj.layersContext) {
311                    obj.layersContext = [];
312                }
313                obj.layersContext.push(layerContext);
314                this.readChildNodes(node, layerContext);
315            },
316            "InlineGeometry": function(node, obj) {
317                obj.features = [];
318                var elements = this.getElementsByTagNameNS(node, 
319                    this.namespaces.gml, "featureMember");
320                var el;
321                if (elements.length >= 1) {
322                    el = elements[0];
323                }
324                if (el && el.firstChild) {
325                    var featurenode = (el.firstChild.nextSibling) ? 
326                        el.firstChild.nextSibling : el.firstChild;
327                    this.setNamespace("feature", featurenode.namespaceURI);
328                    this.featureType = featurenode.localName || 
329                        featurenode.nodeName.split(":").pop();
330                    this.readChildNodes(node, obj);
331                }
332            },
333            "Server": function(node, obj) {
334                // when having multiple Server types, we prefer WMS
335                if ((!obj.service && !obj.version) || 
336                    (obj.service != 
337                        OpenLayers.Format.Context.serviceTypes.WMS)) {
338                            obj.service = node.getAttribute("service");
339                            obj.version = node.getAttribute("version");
340                            this.readChildNodes(node, obj);
341                }
342            },
343            "Name": function(node, obj) {
344                obj.name = this.getChildValue(node);
345                this.readChildNodes(node, obj);
346            },
347            "Title": function(node, obj) {
348                obj.title = this.getChildValue(node);
349                this.readChildNodes(node, obj);
350            },
351            "StyleList": function(node, obj) {
352                this.readChildNodes(node, obj.styles);
353            },
354            "Style": function(node, obj) {
355                var style = {};
356                obj.push(style);
357                this.readChildNodes(node, style);
358            },
359            "LegendURL": function(node, obj) {
360                var legend = {};
361                obj.legend = legend;
362                this.readChildNodes(node, legend);
363            },
364            "OnlineResource": function(node, obj) {
365                obj.url = this.getAttributeNS(node, this.namespaces.xlink, 
366                    "href");
367                this.readChildNodes(node, obj);
368            }
369        },
370        "ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers.ows,
371        "gml": OpenLayers.Format.GML.v2.prototype.readers.gml,
372        "sld": OpenLayers.Format.SLD.v1_0_0.prototype.readers.sld,
373        "feature": OpenLayers.Format.GML.v2.prototype.readers.feature
374    },
375
376    /**
377     * Property: writers
378     * As a compliment to the readers property, this structure contains public
379     *     writing functions grouped by namespace alias and named like the
380     *     node names they produce.
381     */
382    writers: {
383        "owc": {
384            "OWSContext": function(options) {
385                var node = this.createElementNSPlus("OWSContext", {
386                    attributes: {
387                        version: this.VERSION,
388                        id: options.id || OpenLayers.Util.createUniqueID("OpenLayers_OWSContext_")
389                    } 
390                }); 
391                this.writeNode("General", options, node);
392                this.writeNode("ResourceList", options, node);
393                return node; 
394            },
395            "General": function(options) {
396                var node = this.createElementNSPlus("General");
397                this.writeNode("ows:BoundingBox", options, node);
398                this.writeNode("ows:Title", options.title || 'OpenLayers OWSContext', node);
399                return node;
400            },
401            "ResourceList": function(options) {
402                var node = this.createElementNSPlus("ResourceList");
403                for (var i=0, len=options.layers.length; i<len; i++) {
404                    var layer = options.layers[i];
405                    var decomposedPath = this.decomposeNestingPath(layer.metadata.nestingPath);
406                    this.writeNode("_Layer", {layer: layer, subPaths: decomposedPath}, node);
407                }
408                return node;
409            },
410            "Server": function(options) {
411                var node = this.createElementNSPlus("Server", {attributes: {
412                    version: options.version,
413                    service: options.service }
414                });
415                this.writeNode("OnlineResource", options, node);
416                return node;
417            },
418            "OnlineResource": function(options) {
419                var node = this.createElementNSPlus("OnlineResource", {attributes: {
420                    "xlink:href": options.url }
421                });
422                return node;
423            },
424            "InlineGeometry": function(layer) {
425                var node = this.createElementNSPlus("InlineGeometry");
426                this.writeNode("gml:boundedBy", layer.getDataExtent(), node);
427                for (var i=0, len=layer.features.length; i<len; i++) {
428                    this.writeNode("gml:featureMember", layer.features[i], node);
429                }
430                return node;
431            },
432            "StyleList": function(styles) {
433                var node = this.createElementNSPlus("StyleList");
434                for (var i=0, len=styles.length; i<len; i++) {
435                    this.writeNode("Style", styles[i], node);
436                }
437                return node;
438            },
439            "Style": function(style) {
440                var node = this.createElementNSPlus("Style");
441                this.writeNode("Name", style, node);
442                this.writeNode("Title", style, node);
443                this.writeNode("LegendURL", style, node);
444                return node;
445            },
446            "Name": function(obj) {
447                var node = this.createElementNSPlus("Name", {
448                    value: obj.name });
449                return node;
450            },
451            "Title": function(obj) {
452                var node = this.createElementNSPlus("Title", {
453                    value: obj.title });
454                return node;
455            },
456            "LegendURL": function(style) {
457                var node = this.createElementNSPlus("LegendURL");
458                this.writeNode("OnlineResource", style.legend, node);
459                return node;
460            },
461            "_WMS": function(layer) {
462                var node = this.createElementNSPlus("Layer", {attributes: {
463                    name: layer.params.LAYERS,
464                    queryable: layer.queryable ? "1" : "0",
465                    hidden: layer.visibility ? "0" : "1",
466                    opacity: layer.opacity ? layer.opacity: null}
467                });
468                this.writeNode("ows:Title", layer.name, node);
469                this.writeNode("ows:OutputFormat", layer.params.FORMAT, node);
470                this.writeNode("Server", {service: 
471                    OpenLayers.Format.Context.serviceTypes.WMS,
472                    version: layer.params.VERSION, url: layer.url}, node);
473                if (layer.metadata.styles && layer.metadata.styles.length > 0) {
474                    this.writeNode("StyleList", layer.metadata.styles, node);
475                }
476                return node;
477            },
478            "_Layer": function(options) {
479                var layer, subPaths, node, title;
480                layer = options.layer;
481                subPaths = options.subPaths;
482                node = null;
483                title = null;
484                // subPaths is an array of an array
485                // recursively calling _Layer writer eats up subPaths, until a
486                // real writer is called and nodes are returned.
487                if(subPaths.length > 0){
488                    var path = subPaths[0].join("/");
489                    var index = path.lastIndexOf("/");
490                    node = this.nestingLayerLookup[path];
491                    title = (index > 0)?path.substring(index + 1, path.length):path;
492                    if(!node){
493                        // category layer
494                        node = this.createElementNSPlus("Layer");
495                        this.writeNode("ows:Title", title, node);
496                        this.nestingLayerLookup[path] = node;
497                    }
498                    options.subPaths.shift();//remove a path after each call
499                    this.writeNode("_Layer", options, node);
500                    return node;
501                } else {
502                    // write out the actual layer
503                    if (layer instanceof OpenLayers.Layer.WMS) {
504                        node = this.writeNode("_WMS", layer);
505                    } else if (layer instanceof OpenLayers.Layer.Vector) {
506                        if (layer.protocol instanceof OpenLayers.Protocol.WFS.v1) {
507                            node = this.writeNode("_WFS", layer);
508                        } else if (layer.protocol instanceof OpenLayers.Protocol.HTTP) {
509                            if (layer.protocol.format instanceof OpenLayers.Format.GML) {
510                                layer.protocol.format.version = "2.1.2";
511                                node = this.writeNode("_GML", layer);
512                            } else if (layer.protocol.format instanceof OpenLayers.Format.KML) {
513                                layer.protocol.format.version = "2.2";
514                                node = this.writeNode("_KML", layer);
515                            }
516                        } else {
517                            // write out as inline GML since we have no idea
518                            // about the original Format
519                            this.setNamespace("feature", this.featureNS);
520                            node = this.writeNode("_InlineGeometry", layer);
521                        }
522                    }
523                    if (layer.options.maxScale) {
524                        this.writeNode("sld:MinScaleDenominator", 
525                            layer.options.maxScale, node);
526                    }
527                    if (layer.options.minScale) {
528                        this.writeNode("sld:MaxScaleDenominator", 
529                            layer.options.minScale, node);
530                    }
531                    this.nestingLayerLookup[layer.name] = node;
532                    return node;
533                }
534            },
535            "_WFS": function(layer) {
536                var node = this.createElementNSPlus("Layer", {attributes: {
537                    name: layer.protocol.featurePrefix + ":" + layer.protocol.featureType,
538                    hidden: layer.visibility ? "0" : "1" }
539                });
540                this.writeNode("ows:Title", layer.name, node);
541                this.writeNode("Server", {service: 
542                    OpenLayers.Format.Context.serviceTypes.WFS, 
543                    version: layer.protocol.version, 
544                    url: layer.protocol.url}, node);
545                return node;
546            },
547            "_InlineGeometry": function(layer) {
548                var node = this.createElementNSPlus("Layer", {attributes: {
549                    name: this.featureType,
550                    hidden: layer.visibility ? "0" : "1" }
551                });
552                this.writeNode("ows:Title", layer.name, node);
553                this.writeNode("InlineGeometry", layer, node);
554                return node;
555            },
556            "_GML": function(layer) {
557                var node = this.createElementNSPlus("Layer");
558                this.writeNode("ows:Title", layer.name, node);
559                this.writeNode("Server", {service: 
560                    OpenLayers.Format.Context.serviceTypes.GML, 
561                    url: layer.protocol.url, version: 
562                    layer.protocol.format.version}, node);
563                return node;
564            },
565            "_KML": function(layer) {
566                var node = this.createElementNSPlus("Layer");
567                this.writeNode("ows:Title", layer.name, node);
568                this.writeNode("Server", {service: 
569                    OpenLayers.Format.Context.serviceTypes.KML,
570                    version: layer.protocol.format.version, url: 
571                    layer.protocol.url}, node);
572                return node;
573            }
574        },
575        "gml": OpenLayers.Util.applyDefaults({
576            "boundedBy": function(bounds) {
577                var node = this.createElementNSPlus("gml:boundedBy");
578                this.writeNode("gml:Box", bounds, node);
579                return node;
580            }
581        }, OpenLayers.Format.GML.v2.prototype.writers.gml),
582        "ows": OpenLayers.Format.OWSCommon.v1_0_0.prototype.writers.ows,
583        "sld": OpenLayers.Format.SLD.v1_0_0.prototype.writers.sld,
584        "feature": OpenLayers.Format.GML.v2.prototype.writers.feature
585    },
586   
587    CLASS_NAME: "OpenLayers.Format.OWSContext.v0_3_1" 
588
589});
Note: See TracBrowser for help on using the repository browser.