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

Revision 76, 6.5 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 */
10
11/**
12 * Class: OpenLayers.Layer.KaMap
13 *
14 * Inherits from:
15 *  - <OpenLayers.Layer.Grid>
16 */
17OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
18
19    /**
20     * APIProperty: isBaseLayer
21     * {Boolean} KaMap Layer is always a base layer
22     */   
23    isBaseLayer: true,
24
25    /**
26     * APIProperty: units
27     * {?}
28     */   
29    units: null,
30
31    /**
32     * APIProperty: resolution
33     * {Float}
34     */
35    resolution: OpenLayers.DOTS_PER_INCH,
36   
37    /**
38     * Constant: DEFAULT_PARAMS
39     * {Object} parameters set by default. The default parameters set
40     * the format via the 'i' parameter to 'jpeg'.   
41     */
42    DEFAULT_PARAMS: {
43        i: 'jpeg',
44        map: ''
45    },
46       
47    /**
48     * Constructor: OpenLayers.Layer.KaMap
49     *
50     * Parameters:
51     * name - {String}
52     * url - {String}
53     * params - {Object} Parameters to be sent to the HTTP server in the
54     *    query string for the tile. The format can be set via the 'i'
55     *    parameter (defaults to jpg) , and the map should be set via
56     *    the 'map' parameter. It has been reported that ka-Map may behave
57     *    inconsistently if your format parameter does not match the format
58     *    parameter configured in your config.php. (See ticket #327 for more
59     *    information.)
60     * options - {Object} Additional options for the layer. Any of the
61     *     APIProperties listed on this layer, and any layer types it
62     *     extends, can be overridden through the options parameter.
63     */
64    initialize: function(name, url, params, options) {
65        var newArguments = [];
66        newArguments.push(name, url, params, options);
67        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
68        this.params = OpenLayers.Util.applyDefaults(
69            this.params, this.DEFAULT_PARAMS
70        );
71    },
72
73    /**
74     * Method: getURL
75     *
76     * Parameters:
77     * bounds - {<OpenLayers.Bounds>}
78     *
79     * Returns:
80     * {String} A string with the layer's url and parameters and also the
81     *          passed-in bounds and appropriate tile size specified as
82     *          parameters
83     */
84    getURL: function (bounds) {
85        bounds = this.adjustBounds(bounds);
86        var mapRes = this.map.getResolution();
87        var scale = Math.round((this.map.getScale() * 10000)) / 10000;
88        var pX = Math.round(bounds.left / mapRes);
89        var pY = -Math.round(bounds.top / mapRes);
90        return this.getFullRequestString(
91                      { t: pY, 
92                        l: pX,
93                        s: scale
94                      });
95    },
96
97    /**
98     * Method: addTile
99     *
100     * Parameters:
101     * bounds - {<OpenLayers.Bounds>}
102     * position - {<OpenLayers.Pixel>}
103     *
104     * Returns:
105     * {<OpenLayers.Tile.Image>}
106     */   
107    addTile:function(bounds,position) {
108        var url = this.getURL(bounds);
109        return new OpenLayers.Tile.Image(this, position, bounds, 
110                                             url, this.tileSize);
111    },
112
113    /**
114     * Method: calculateGridLayout
115     * ka-Map uses the center point of the map as an origin for
116     * its tiles. Override calculateGridLayout to center tiles
117     * correctly for this case.
118     *
119     * Parameters:
120     * bounds - {<OpenLayers.Bound>}
121     * extent - {<OpenLayers.Bounds>}
122     * resolution - {Number}
123     *
124     * Returns:
125     * Object containing properties tilelon, tilelat, tileoffsetlat,
126     * tileoffsetlat, tileoffsetx, tileoffsety
127     */
128    calculateGridLayout: function(bounds, extent, resolution) {
129        var tilelon = resolution*this.tileSize.w;
130        var tilelat = resolution*this.tileSize.h;
131       
132        var offsetlon = bounds.left;
133        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
134        var tilecolremain = offsetlon/tilelon - tilecol;
135        var tileoffsetx = -tilecolremain * this.tileSize.w;
136        var tileoffsetlon = tilecol * tilelon;
137       
138        var offsetlat = bounds.top; 
139        var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
140        var tilerowremain = tilerow - offsetlat/tilelat;
141        var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
142        var tileoffsetlat = tilerow * tilelat;
143       
144        return { 
145          tilelon: tilelon, tilelat: tilelat,
146          tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
147          tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
148        };
149    },   
150
151    /**
152     * APIMethod: clone
153     *
154     * Parameters:
155     * obj - {Object}
156     *
157     * Returns:
158     * {<OpenLayers.Layer.Kamap>} An exact clone of this OpenLayers.Layer.KaMap
159     */
160    clone: function (obj) {
161       
162        if (obj == null) {
163            obj = new OpenLayers.Layer.KaMap(this.name,
164                                            this.url,
165                                            this.params,
166                                            this.getOptions());
167        }
168
169        //get all additions from superclasses
170        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
171
172        // copy/set any non-init, non-simple values here
173        if (this.tileSize != null) {
174            obj.tileSize = this.tileSize.clone();
175        }
176       
177        // we do not want to copy reference to grid, so we make a new array
178        obj.grid = [];
179
180        return obj;
181    },   
182   
183    /**
184     * APIMethod: getTileBounds
185     * Returns The tile bounds for a layer given a pixel location.
186     *
187     * Parameters:
188     * viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
189     *
190     * Returns:
191     * {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
192     */
193    getTileBounds: function(viewPortPx) {
194        var resolution = this.getResolution();
195        var tileMapWidth = resolution * this.tileSize.w;
196        var tileMapHeight = resolution * this.tileSize.h;
197        var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
198        var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
199        var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
200        return new OpenLayers.Bounds(tileLeft, tileBottom,
201                                     tileLeft + tileMapWidth,
202                                     tileBottom + tileMapHeight);
203    },
204
205    CLASS_NAME: "OpenLayers.Layer.KaMap"
206});
Note: See TracBrowser for help on using the repository browser.