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

Revision 76, 9.7 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 * Development supported by a R&D grant DC08P02OUK006 - Old Maps Online
8 * (www.oldmapsonline.org) from Ministry of Culture of the Czech Republic.
9 */
10
11
12/**
13 * @requires OpenLayers/Layer/Grid.js
14 */
15
16/**
17 * Class: OpenLayers.Layer.Zoomify
18 *
19 * Inherits from:
20 *  - <OpenLayers.Layer.Grid>
21 */
22OpenLayers.Layer.Zoomify = OpenLayers.Class(OpenLayers.Layer.Grid, {
23
24    /**
25     * Property: url
26     * {String} URL for root directory with TileGroupX subdirectories.
27     */
28    url: null,
29
30    /**
31     * Property: size
32     * {<OpenLayers.Size>} The Zoomify image size in pixels.
33     */
34    size: null,
35
36    /**
37     * APIProperty: isBaseLayer
38     * {Boolean}
39     */
40    isBaseLayer: true,
41
42    /**
43     * Property: standardTileSize
44     * {Integer} The size of a standard (non-border) square tile in pixels.
45     */
46    standardTileSize: 256,
47
48    /**
49     * Property: numberOfTiers
50     * {Integer} Depth of the Zoomify pyramid, number of tiers (zoom levels)
51     *                          - filled during Zoomify pyramid initialization.
52     */
53    numberOfTiers: 0,
54
55    /**
56     * Property: tileCountUpToTier
57     * {Array(Integer)} Number of tiles up to the given tier of pyramid.
58     *                          - filled during Zoomify pyramid initialization.
59     */
60    tileCountUpToTier: new Array(),
61
62    /**
63     * Property: tierSizeInTiles
64     * {Array(<OpenLayers.Size>)} Size (in tiles) for each tier of pyramid.
65     *                          - filled during Zoomify pyramid initialization.
66     */
67    tierSizeInTiles: new Array(),
68
69    /**
70     * Property: tierImageSize
71     * {Array(<OpenLayers.Size>)} Image size in pixels for each pyramid tier.
72     *                          - filled during Zoomify pyramid initialization.
73     */
74    tierImageSize: new Array(),
75
76    /**
77     * Constructor: OpenLayers.Layer.Zoomify
78     *
79     * Parameters:
80     * name - {String} A name for the layer.
81     * url - {String} - Relative or absolute path to the image or more
82     *        precisly to the TileGroup[X] directories root.
83     *        Flash plugin use the variable name "zoomifyImagePath" for this.
84     * size - {<OpenLayers.Size>} The size (in pixels) of the image.
85     * options - {Object} Hashtable of extra options to tag onto the layer
86     */
87    initialize: function(name, url, size, options) {
88
89        // initilize the Zoomify pyramid for given size
90        this.initializeZoomify( size );
91
92        var newArguments = [];
93        newArguments.push(name, url, size, {}, options);
94
95        OpenLayers.Layer.Grid.prototype.initialize.apply(this, newArguments);
96    },
97
98    /**
99     * Method: initializeZoomify
100     * It generates constants for all tiers of the Zoomify pyramid
101     *
102     * Parameters:
103     * size - {<OpenLayers.Size>} The size of the image in pixels
104     *
105     */
106    initializeZoomify: function( size ) {
107
108        var imageSize = size.clone()
109        var tiles = new OpenLayers.Size(
110            Math.ceil( imageSize.w / this.standardTileSize ),
111            Math.ceil( imageSize.h / this.standardTileSize )
112            );
113
114        this.tierSizeInTiles.push( tiles );
115        this.tierImageSize.push( imageSize );
116
117        while (imageSize.w > this.standardTileSize ||
118               imageSize.h > this.standardTileSize ) {
119
120            imageSize = new OpenLayers.Size(
121                Math.floor( imageSize.w / 2 ),
122                Math.floor( imageSize.h / 2 )
123                );
124            tiles = new OpenLayers.Size(
125                Math.ceil( imageSize.w / this.standardTileSize ),
126                Math.ceil( imageSize.h / this.standardTileSize )
127                );
128            this.tierSizeInTiles.push( tiles );
129            this.tierImageSize.push( imageSize );
130        }
131
132        this.tierSizeInTiles.reverse();
133        this.tierImageSize.reverse();
134
135        this.numberOfTiers = this.tierSizeInTiles.length;
136
137        this.tileCountUpToTier[0] = 0;
138        for (var i = 1; i < this.numberOfTiers; i++) {
139            this.tileCountUpToTier.push(
140                this.tierSizeInTiles[i-1].w * this.tierSizeInTiles[i-1].h +
141                this.tileCountUpToTier[i-1]
142                );
143        }
144    },
145
146    /**
147     * APIMethod:destroy
148     */
149    destroy: function() {
150        // for now, nothing special to do here.
151        OpenLayers.Layer.Grid.prototype.destroy.apply(this, arguments);
152
153        // Remove from memory the Zoomify pyramid - is that enough?
154        this.tileCountUpToTier.length = 0
155        this.tierSizeInTiles.length = 0
156        this.tierImageSize.length = 0
157
158    },
159
160    /**
161     * APIMethod: clone
162     *
163     * Parameters:
164     * obj - {Object}
165     *
166     * Returns:
167     * {<OpenLayers.Layer.Zoomify>} An exact clone of this <OpenLayers.Layer.Zoomify>
168     */
169    clone: function (obj) {
170
171        if (obj == null) {
172            obj = new OpenLayers.Layer.Zoomify(this.name,
173                                           this.url,
174                                           this.size,
175                                           this.options);
176        }
177
178        //get all additions from superclasses
179        obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
180
181        // copy/set any non-init, non-simple values here
182
183        return obj;
184    },
185
186    /**
187     * Method: getURL
188     *
189     * Parameters:
190     * bounds - {<OpenLayers.Bounds>}
191     *
192     * Returns:
193     * {String} A string with the layer's url and parameters and also the
194     *          passed-in bounds and appropriate tile size specified as
195     *          parameters
196     */
197    getURL: function (bounds) {
198        bounds = this.adjustBounds(bounds);
199        var res = this.map.getResolution();
200        var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
201        var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
202        var z = this.map.getZoom();
203
204        var tileIndex = x + y * this.tierSizeInTiles[z].w + this.tileCountUpToTier[z];
205        var path = "TileGroup" + Math.floor( (tileIndex) / 256 ) +
206            "/" + z + "-" + x + "-" + y + ".jpg";
207        var url = this.url;
208        if (url instanceof Array) {
209            url = this.selectUrl(path, url);
210        }
211        return url + path;
212    },
213
214    /**
215     * Method: getImageSize
216     * getImageSize returns size for a particular tile. If bounds are given as
217     * first argument, size is calculated (bottom-right tiles are non square).
218     *
219     */
220    getImageSize: function() {
221        if (arguments.length > 0) {
222            bounds = this.adjustBounds(arguments[0]);
223            var res = this.map.getResolution();
224            var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
225            var y = Math.round((this.tileOrigin.lat - bounds.top) / (res * this.tileSize.h));
226            var z = this.map.getZoom();
227            var w = this.standardTileSize;
228            var h = this.standardTileSize;
229            if (x == this.tierSizeInTiles[z].w -1 ) {
230                var w = this.tierImageSize[z].w % this.standardTileSize;
231            };
232            if (y == this.tierSizeInTiles[z].h -1 ) {
233                var h = this.tierImageSize[z].h % this.standardTileSize;
234            };
235            return (new OpenLayers.Size(w, h));
236        } else {
237            return this.tileSize;
238        }
239    },
240
241    /**
242     * Method: addTile
243     * addTile creates a tile, initializes it, and adds it to the layer div.
244     *
245     * Parameters:
246     * bounds - {<OpenLayers.Bounds>}
247     * position - {<OpenLayers.Pixel>}
248     *
249     * Returns:
250     * {<OpenLayers.Tile.Image>} The added OpenLayers.Tile.Image
251     */
252    addTile:function(bounds,position) {
253        return new OpenLayers.Tile.Image(this, position, bounds,
254                                         null, this.tileSize);
255    },
256
257    /**
258     * APIMethod: setMap
259     * When the layer is added to a map, then we can fetch our origin
260     *    (if we don't have one.)
261     *
262     * Parameters:
263     * map - {<OpenLayers.Map>}
264     */
265    setMap: function(map) {
266        OpenLayers.Layer.Grid.prototype.setMap.apply(this, arguments);
267        this.tileOrigin = new OpenLayers.LonLat(this.map.maxExtent.left,
268                                                this.map.maxExtent.top);
269    },
270
271    /**
272     * Method: calculateGridLayout
273     * Generate parameters for the grid layout. This
274     *
275     * Parameters:
276     * bounds - {<OpenLayers.Bound>}
277     * extent - {<OpenLayers.Bounds>}
278     * resolution - {Number}
279     *
280     * Returns:
281     * Object containing properties tilelon, tilelat, tileoffsetlat,
282     * tileoffsetlat, tileoffsetx, tileoffsety
283     */
284    calculateGridLayout: function(bounds, extent, resolution) {
285        var tilelon = resolution * this.tileSize.w;
286        var tilelat = resolution * this.tileSize.h;
287
288        var offsetlon = bounds.left - extent.left;
289        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
290        var tilecolremain = offsetlon/tilelon - tilecol;
291        var tileoffsetx = -tilecolremain * this.tileSize.w;
292        var tileoffsetlon = extent.left + tilecol * tilelon;
293
294        var offsetlat = extent.top - bounds.top + tilelat;
295        var tilerow = Math.floor(offsetlat/tilelat) - this.buffer;
296        var tilerowremain = tilerow - offsetlat/tilelat;
297        var tileoffsety = tilerowremain * this.tileSize.h;
298        var tileoffsetlat = extent.top - tilelat*tilerow;
299
300        return {
301          tilelon: tilelon, tilelat: tilelat,
302          tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
303          tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
304        };
305    },
306
307    CLASS_NAME: "OpenLayers.Layer.Zoomify"
308});
Note: See TracBrowser for help on using the repository browser.