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/GeoExt/lib/GeoExt/data/WMCReader.js @ 76

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

Ajout du répertoire web

  • Property svn:executable set to *
Line 
1/**
2 * Copyright (c) 2008-2010 The Open Source Geospatial Foundation
3 *
4 * Published under the BSD license.
5 * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
6 * of the license.
7 */
8
9/**
10 * @include GeoExt/data/LayerRecord.js
11 */
12
13/** api: (define)
14 *  module = GeoExt.data
15 *  class = WMCReader
16 *  base_link = `Ext.data.DataReader <http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataReader>`_
17 */
18Ext.namespace("GeoExt.data");
19
20/** api: constructor
21 *  .. class:: WMCReader(meta, recordType)
22 * 
23 *      :param meta: ``Object`` Reader configuration.
24 *      :param recordType: ``Array | Ext.data.Record`` An array of field
25 *          configuration objects or a record object.  Default is
26 *          :class:`GeoExt.data.LayerRecord`.
27 *   
28 *      Data reader class to create an array of
29 *      :class:`GeoExt.data.LayerRecord` objects from a WMS GetCapabilities
30 *      response.
31 */
32GeoExt.data.WMCReader = function(meta, recordType) {
33    meta = meta || {};
34    if(!meta.format) {
35        meta.format = new OpenLayers.Format.WMC();
36    }
37    if(!(typeof recordType === "function")) {
38        recordType = GeoExt.data.LayerRecord.create(
39            recordType || meta.fields || [
40                // give only non-OpenLayers fields as default recordType
41                {name: "abstract", type: "string"},
42                {name: "metadataURL", type: "string"},
43                {name: "queryable", type: "boolean"},
44                {name: "formats"}, // array
45                {name: "styles"} // array
46            ]
47        );
48    }
49    GeoExt.data.WMCReader.superclass.constructor.call(
50        this, meta, recordType
51    );
52};
53
54Ext.extend(GeoExt.data.WMCReader, Ext.data.DataReader, {
55
56    /** private: method[read]
57     *  :param request: ``Object`` The XHR object which contains the parsed XML
58     *      document.
59     *  :return: ``Object`` A data block which is used by an ``Ext.data.Store``
60     *      as a cache of ``Ext.data.Record`` objects.
61     */
62    read: function(request) {
63        var data = request.responseXML;
64        if(!data || !data.documentElement) {
65            data = request.responseText;
66        }
67        return this.readRecords(data);
68    },
69
70    /** private: method[readRecords]
71     *  :param data: ``DOMElement | String | Object`` A document element or XHR
72     *      response string.  As an alternative to fetching capabilities data
73     *      from a remote source, an object representing the capabilities can
74     *      be provided given that the structure mirrors that returned from the
75     *      capabilities parser.
76     *  :return: ``Object`` A data block which is used by an ``Ext.data.Store``
77     *      as a cache of ``Ext.data.Record`` objects.
78     * 
79     *  Create a data block containing Ext.data.Records from an XML document.
80     */
81    readRecords: function(data) {
82        var format = this.meta.format;
83        if(typeof data === "string" || data.nodeType) {
84            data = format.read(data);
85        }
86        var layersContext = data ? data.layersContext : undefined;
87        var records = [];       
88
89        if(layersContext) {
90            var recordType = this.recordType, fields = recordType.prototype.fields;
91            var i, lenI, j, lenJ, layerContext, values, field, v;
92            for (i = 0, lenI = layersContext.length; i < lenI; i++) {
93                layerContext = layersContext[i];
94                values = {};
95                for(j = 0, lenJ = fields.length; j < lenJ; j++){
96                    field = fields.items[j];
97                    v = layerContext[field.mapping || field.name] ||
98                        field.defaultValue;
99                    v = field.convert(v);
100                    values[field.name] = v;
101                }
102                values.layer = format.getLayerFromContext(layerContext);
103                records.push(new this.recordType(values, values.layer.id));
104            }
105        }
106       
107        return {
108            totalRecords: records.length,
109            success: true,
110            records: records
111        };
112
113    }
114
115});
116
Note: See TracBrowser for help on using the repository browser.