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/state/PermalinkProvider.js @ 81

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-2009 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/** api: (define)
10 *  module = GeoExt.state
11 *  class = PermalinkProvider
12 *  base_link = `Ext.state.Provider <http://dev.sencha.com/deploy/dev/docs/?class=Ext.state.Provider>`_
13 */
14Ext.namespace("GeoExt.state");
15
16/** api: example
17 *  Sample code displaying a new permalink each time the map is moved.
18 *
19 *  .. code-block:: javascript
20 *
21 *      // create permalink provider
22 *      var permalinkProvider = new GeoExt.state.PermalinkProvider();
23 *
24 *      // set it in the state manager
25 *      Ext.state.Manager.setProvider(permalinkProvider);
26 *
27 *      // create a map panel, and make it stateful
28 *      var mapPanel = new GeoExt.MapPanel({
29 *          renderTo: "map",
30 *          layers: [
31 *              new OpenLayers.Layer.WMS(
32 *                  "Global Imagery",
33 *                  "http://maps.opengeo.org/geowebcache/service/wms",
34 *                  {layers: "bluemarble"}
35 *              )
36 *          ],
37 *          stateId: "map",
38 *          prettyStateKeys: true // for pretty permalinks
39 *      });
40 *
41 *      // display permalink each time state is changed
42 *      permalinkProvider.on({
43 *          statechanged: function(provider, name, value) {
44 *              alert(provider.getLink());
45 *          }
46 *      });
47 */
48
49/** api: constructor
50 *  .. class:: PermalinkProvider(config)
51 *
52 *      Create a permalink provider.
53 *
54 */
55GeoExt.state.PermalinkProvider = function(config) {
56    GeoExt.state.PermalinkProvider.superclass.constructor.apply(this, arguments);
57
58    config = config || {};
59
60    var url = config.url;
61    delete config.url;
62
63    Ext.apply(this, config);
64
65    this.state = this.readURL(url);
66};
67
68Ext.extend(GeoExt.state.PermalinkProvider, Ext.state.Provider, {
69
70    /** api: config[encodeType]
71     *  ``Boolean`` Specifies whether type of state values should be encoded
72     *  and decoded. Set it to false if you work with components that don't
73     *  require encoding types, and want pretty permalinks. Defaults to true.
74     */
75    /** private: property[encodeType]
76     *  ``Boolean``
77     */
78    encodeType: true,
79
80    /** private: method[readURL]
81     *  :param url: ``String`` The URL to get the state from.
82     *  :return: ``Object`` The state object.
83     *
84     *  Create a state object from a URL.
85     */
86    readURL: function(url) {
87        var state = {};
88        var params = OpenLayers.Util.getParameters(url);
89        var k, split, stateId;
90        for(k in params) {
91            if(params.hasOwnProperty(k)) {
92                split = k.split("_");
93                if(split.length > 1) {
94                    stateId = split[0];
95                    state[stateId] = state[stateId] || {};
96                    state[stateId][split.slice(1).join("_")] = this.encodeType ?
97                        this.decodeValue(params[k]) : params[k];
98                }
99            }
100        }
101        return state;
102    },
103
104    /** api: method[getLink]
105     *  :param base: ``String`` The base URL, optional.
106     *  :return: ``String`` The permalink.
107     *
108     *  Return the permalink corresponding to the current state.
109     */
110    getLink: function(base) {
111        base = base || document.location.href;
112
113        var params = {};
114
115        var id, k, state = this.state;
116        for(id in state) {
117            if(state.hasOwnProperty(id)) {
118                for(k in state[id]) {
119                    params[id + "_" + k] = this.encodeType ?
120                        unescape(this.encodeValue(state[id][k])) : state[id][k];
121                }
122            }
123        }
124
125        // merge params in the URL into the state params
126        OpenLayers.Util.applyDefaults(
127            params, OpenLayers.Util.getParameters(base));
128
129        var paramsStr = OpenLayers.Util.getParameterString(params);
130
131        var qMark = base.indexOf("?");
132        if(qMark > 0) {
133            base = base.substring(0, qMark);
134        }
135
136        return Ext.urlAppend(base, paramsStr);
137    }
138});
Note: See TracBrowser for help on using the repository browser.