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

Revision 76, 5.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/**
8 * @requires OpenLayers/Layer/Grid.js
9 * @requires OpenLayers/Layer/KaMap.js
10 */
11
12/**
13 * Class: OpenLayers.Layer.KaMapCache
14 *
15 * This class is designed to talk directly to a web-accessible ka-Map
16 * cache generated by the precache2.php script.
17 *
18 * To create a a new KaMapCache layer, you must indicate also the "i" parameter
19 * (that will be used to calculate the file extension), and another special
20 * parameter, object names "metaTileSize", with "h" (height) and "w" (width)
21 * properties.
22 *
23 *     // Create a new kaMapCache layer.
24 *     var kamap_base = new OpenLayers.Layer.KaMapCache(
25 *         "Satellite",
26 *         "http://www.example.org/web/acessible/cache",
27 *         {g: "satellite", map: "world", i: 'png24', metaTileSize: {w: 5, h: 5} }
28 *       );
29 *   
30 *     // Create an kaMapCache overlay layer (using "isBaseLayer: false").
31 *     // Forces the output to be a "gif", using the "i" parameter.
32 *     var kamap_overlay = new OpenLayers.Layer.KaMapCache(
33 *         "Streets",
34 *         "http://www.example.org/web/acessible/cache",
35 *         {g: "streets", map: "world", i: "gif", metaTileSize: {w: 5, h: 5} },
36 *         {isBaseLayer: false}
37 *       );
38 *
39 * The cache URLs must look like:
40 *   var/cache/World/50000/Group_Name/def/t-440320/l20480
41 *
42 * This means that the cache generated via tile.php will *not* work with
43 *     this class, and should instead use the KaMap layer.
44 *
45 * More information is available in Ticket #1518.
46 *
47 * Inherits from:
48 *  - <OpenLayers.Layer.KaMap>
49 *  - <OpenLayers.Layer.Grid>
50 */
51OpenLayers.Layer.KaMapCache = OpenLayers.Class(OpenLayers.Layer.KaMap, {
52
53    /**
54     * Constant: IMAGE_EXTENSIONS
55     * {Object} Simple hash map to convert format to extension.
56     */
57    IMAGE_EXTENSIONS: {
58        'jpeg': 'jpg',
59        'gif' : 'gif',
60        'png' : 'png',
61        'png8' : 'png',
62        'png24' : 'png',
63        'dithered' : 'png'
64    },
65   
66    /**
67     * Constant: DEFAULT_FORMAT
68     * {Object} Simple hash map to convert format to extension.
69     */
70    DEFAULT_FORMAT: 'jpeg',
71   
72    /**
73     * Constructor: OpenLayers.Layer.KaMapCache
74     *
75     * Parameters:
76     * name - {String}
77     * url - {String}
78     * params - {Object} Parameters to be sent to the HTTP server in the
79     *    query string for the tile. The format can be set via the 'i'
80     *    parameter (defaults to jpg) , and the map should be set via
81     *    the 'map' parameter. It has been reported that ka-Map may behave
82     *    inconsistently if your format parameter does not match the format
83     *    parameter configured in your config.php. (See ticket #327 for more
84     *    information.)
85     * options - {Object} Additional options for the layer. Any of the
86     *     APIProperties listed on this layer, and any layer types it
87     *     extends, can be overridden through the options parameter.
88     */
89    initialize: function(name, url, params, options) {
90        OpenLayers.Layer.KaMap.prototype.initialize.apply(this, arguments);
91        this.extension = this.IMAGE_EXTENSIONS[this.params.i.toLowerCase() || DEFAULT_FORMAT];
92    },
93
94    /**
95     * Method: getURL
96     *
97     * Parameters:
98     * bounds - {<OpenLayers.Bounds>}
99     *
100     * Returns:
101     * {String} A string with the layer's url and parameters and also the
102     *          passed-in bounds and appropriate tile size specified as
103     *          parameters
104     */
105    getURL: function (bounds) {
106        bounds = this.adjustBounds(bounds);
107        var mapRes = this.map.getResolution();
108        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
109        var pX = Math.round(bounds.left / mapRes);
110        var pY = -Math.round(bounds.top / mapRes);
111
112        var metaX = Math.floor(pX / this.tileSize.w / this.params.metaTileSize.w) * this.tileSize.w * this.params.metaTileSize.w;
113        var metaY = Math.floor(pY / this.tileSize.h / this.params.metaTileSize.h) * this.tileSize.h * this.params.metaTileSize.h;
114
115        // if url is not a string, it should be an array of strings,
116        // in which case we will deterministically select one of them in
117        // order to evenly distribute requests to different urls.
118        //
119        var url = this.url;
120        if (url instanceof Array) {
121            url = this.selectUrl(paramsString, url);
122        } 
123   
124        var components = [
125            url,
126            "/",
127            this.params.map,
128            "/",
129            scale,
130            "/",
131            this.params.g.replace(/\s/g, '_'),
132            "/def/t", 
133            metaY,
134            "/l",
135            metaX,
136            "/t",
137            pY,
138            "l",
139            pX,
140            ".",
141            this.extension
142          ];
143         
144        return components.join("");
145    },
146
147    CLASS_NAME: "OpenLayers.Layer.KaMapCache"
148});
Note: See TracBrowser for help on using the repository browser.