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/WMTSCapabilities.js @ 76

Revision 76, 5.1 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 */
9 
10/**
11 * Class: OpenLayers.Format.WMTSCapabilities
12 * Read WMTS Capabilities.
13 *
14 * Inherits from:
15 *  - <OpenLayers.Format.XML>
16 */
17OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML, {
18   
19    /**
20     * APIProperty: defaultVersion
21     * {String} Version number to assume if none found.  Default is "1.0.0".
22     */
23    defaultVersion: "1.0.0",
24   
25    /**
26     * APIProperty: version
27     * {String} Specify a version string if one is known.
28     */
29    version: null,
30
31    /**
32     * Property: parser
33     * {<OpenLayers.Format>} A cached versioned format used for reading.
34     */
35    parser: null,
36   
37    /**
38     * APIProperty: yx
39     * {Object} Members in the yx object are used to determine if a CRS URN
40     *     corresponds to a CRS with y,x axis order.  Member names are CRS URNs
41     *     and values are boolean.  By default, the following CRS URN are
42     *     assumed to correspond to a CRS with y,x axis order:
43     *
44     * * urn:ogc:def:crs:EPSG::4326
45     */
46    yx: {
47        "urn:ogc:def:crs:EPSG::4326": true
48    },
49
50    /**
51     * Constructor: OpenLayers.Format.WMTSCapabilities
52     * Create a new parser for WMTS capabilities.
53     *
54     * Parameters:
55     * options - {Object} An optional object whose properties will be set on
56     *     this instance.
57     */
58    initialize: function(options) {
59        OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
60        this.options = options;
61    },
62
63    /**
64     * APIMethod: read
65     * Read capabilities data from a string, and return information about
66     * the service (offering and observedProperty mostly).
67     *
68     * Parameters:
69     * data - {String} or {DOMElement} data to read/parse.
70     *
71     * Returns:
72     * {Object} Info about the WMTS Capabilities
73     */
74    read: function(data) {
75        if (typeof data == "string") {
76            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
77        }
78        var root = data.documentElement;
79        var version = this.version || root.getAttribute("version") || this.defaultVersion;
80        if (!this.parser || this.parser.version !== version) {
81            var constr = OpenLayers.Format.WMTSCapabilities[
82                "v" + version.replace(/\./g, "_")
83            ];
84            if (!constr) {
85                throw new Error("Can't find a WMTS capabilities parser for version " + version);
86            }
87            this.parser = new constr(this.options);
88        }
89        return this.parser.read(data);
90    },
91
92    /**
93     * APIMethod: createLayer
94     * Create a WMTS layer given a capabilities object.
95     *
96     * Parameters:
97     * capabilities - {Object} The object returned from a <read> call to this
98     *     format.
99     * config - {Object} Configuration properties for the layer.  Defaults for
100     *     the layer will apply if not provided.
101     *
102     * Required config properties:
103     * layer - {String} The layer identifier.
104     * matrixSet - {String} The matrix set identifier.
105     *
106     * Returns:
107     * {<OpenLayers.Layer.WMTS>} A properly configured WMTS layer.  Throws an
108     *     error if an incomplete config is provided.  Returns undefined if no
109     *     layer could be created with the provided config.
110     */ 
111    createLayer: function(capabilities, config) {
112        var layer;
113
114        // confirm required properties are supplied in config
115        var required = {
116            layer: true,
117            matrixSet: true
118        };
119        for (var prop in required) {
120            if (!(prop in config)) {
121                throw new Error("Missing property '" + prop + "' in layer configuration.");
122            }
123        }
124
125        var contents = capabilities.contents;
126        var matrixSet = contents.tileMatrixSets[config.matrixSet];
127
128        // find the layer definition with the given identifier
129        var layers = contents.layers;
130        var layerDef;
131        for (var i=0, ii=contents.layers.length; i<ii; ++i) {
132            if (contents.layers[i].identifier === config.layer) {
133                layerDef = contents.layers[i];
134                break;
135            }
136        }
137       
138        if (layerDef && matrixSet) {
139            // get the default style for the layer
140            var style;
141            for (var i=0, ii=layerDef.styles.length; i<ii; ++i) {
142                style = layerDef.styles[i];
143                if (style.isDefault) {
144                    break;
145                }
146            }
147           
148            layer = new OpenLayers.Layer.WMTS(
149                OpenLayers.Util.applyDefaults(config, {
150                    url: capabilities.operationsMetadata.GetTile.dcp.http.get,
151                    name: layerDef.title,
152                    style: style,
153                    matrixIds: matrixSet.matrixIds
154                })
155            );
156        }
157        return layer;
158    },
159   
160    CLASS_NAME: "OpenLayers.Format.WMTSCapabilities" 
161
162});
Note: See TracBrowser for help on using the repository browser.