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

Revision 76, 11.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/SphericalMercator.js
9 * @requires OpenLayers/Layer/EventPane.js
10 * @requires OpenLayers/Layer/FixedZoomLevels.js
11 */
12
13/**
14 * Class: OpenLayers.Layer.Yahoo
15 *
16 * Inherits from:
17 *  - <OpenLayers.Layer.EventPane>
18 *  - <OpenLayers.Layer.FixedZoomLevels>
19 */
20OpenLayers.Layer.Yahoo = OpenLayers.Class(
21  OpenLayers.Layer.EventPane, OpenLayers.Layer.FixedZoomLevels, {
22   
23    /**
24     * Constant: MIN_ZOOM_LEVEL
25     * {Integer} 0
26     */
27    MIN_ZOOM_LEVEL: 0,
28   
29    /**
30     * Constant: MAX_ZOOM_LEVEL
31     * {Integer} 17
32     */
33    MAX_ZOOM_LEVEL: 17,
34
35    /**
36     * Constant: RESOLUTIONS
37     * {Array(Float)} Hardcode these resolutions so that they are more closely
38     *                tied with the standard wms projection
39     */
40    RESOLUTIONS: [
41        1.40625, 
42        0.703125, 
43        0.3515625, 
44        0.17578125, 
45        0.087890625, 
46        0.0439453125,
47        0.02197265625, 
48        0.010986328125, 
49        0.0054931640625, 
50        0.00274658203125, 
51        0.001373291015625, 
52        0.0006866455078125, 
53        0.00034332275390625, 
54        0.000171661376953125, 
55        0.0000858306884765625, 
56        0.00004291534423828125,
57        0.00002145767211914062,
58        0.00001072883605957031
59    ],
60
61    /**
62     * APIProperty: type
63     * {YahooMapType}
64     */
65    type: null,
66   
67    /**
68     * APIProperty: wrapDateLine
69     * {Boolean} Allow user to pan forever east/west.  Default is true. 
70     *     Setting this to false only restricts panning if
71     *     <sphericalMercator> is true.
72     */
73    wrapDateLine: true,
74
75    /**
76     * APIProperty: sphericalMercator
77     * {Boolean} Should the map act as a mercator-projected map? This will
78     * cause all interactions with the map to be in the actual map projection,
79     * which allows support for vector drawing, overlaying other maps, etc.
80     */
81    sphericalMercator: false, 
82
83    /**
84     * Constructor: OpenLayers.Layer.Yahoo
85     *
86     * Parameters:
87     * name - {String}
88     * options - {Object}
89     */
90    initialize: function(name, options) {
91        OpenLayers.Layer.EventPane.prototype.initialize.apply(this, arguments);
92        OpenLayers.Layer.FixedZoomLevels.prototype.initialize.apply(this, 
93                                                                    arguments);
94        if(this.sphericalMercator) {
95            OpenLayers.Util.extend(this, OpenLayers.Layer.SphericalMercator);
96            this.initMercatorParameters();
97        }
98    },
99   
100    /**
101     * Method: loadMapObject
102     */
103    loadMapObject:function() {
104        try { //do not crash!
105            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
106            this.mapObject = new YMap(this.div, this.type, size);
107            this.mapObject.disableKeyControls();
108            this.mapObject.disableDragMap();
109
110            //can we do smooth panning? (moveByXY is not an API function)
111            if ( !this.mapObject.moveByXY || 
112                 (typeof this.mapObject.moveByXY != "function" ) ) {
113
114                this.dragPanMapObject = null;
115            }               
116        } catch(e) {}
117    },
118
119    /**
120     * Method: onMapResize
121     *
122     */
123    onMapResize: function() {
124        try {
125            var size = this.getMapObjectSizeFromOLSize(this.map.getSize());
126            this.mapObject.resizeTo(size);
127        } catch(e) {}     
128    },   
129   
130   
131    /**
132     * APIMethod: setMap
133     * Overridden from EventPane because we need to remove this yahoo event
134     *     pane which prohibits our drag and drop, and we can only do this
135     *     once the map has been loaded and centered.
136     *
137     * Parameters:
138     * map - {<OpenLayers.Map>}
139     */
140    setMap: function(map) {
141        OpenLayers.Layer.EventPane.prototype.setMap.apply(this, arguments);
142
143        this.map.events.register("moveend", this, this.fixYahooEventPane);
144    },
145
146    /**
147     * Method: fixYahooEventPane
148     * The map has been centered, so the mysterious yahoo eventpane has been
149     *     added. we remove it so that it doesnt mess with *our* event pane.
150     */
151    fixYahooEventPane: function() {
152        var yahooEventPane = OpenLayers.Util.getElement("ygddfdiv");
153        if (yahooEventPane != null) {
154            if (yahooEventPane.parentNode != null) {
155                yahooEventPane.parentNode.removeChild(yahooEventPane);
156            }
157            this.map.events.unregister("moveend", this, 
158                                       this.fixYahooEventPane);
159        }
160    },
161
162    /**
163     * APIMethod: getWarningHTML
164     *
165     * Returns:
166     * {String} String with information on why layer is broken, how to get
167     *          it working.
168     */
169    getWarningHTML:function() {
170        return OpenLayers.i18n(
171            "getLayerWarning", {'layerType':'Yahoo', 'layerLib':'Yahoo'}
172        );
173    },
174
175  /********************************************************/
176  /*                                                      */
177  /*             Translation Functions                    */
178  /*                                                      */
179  /*    The following functions translate GMaps and OL    */ 
180  /*     formats for Pixel, LonLat, Bounds, and Zoom      */
181  /*                                                      */
182  /********************************************************/
183
184
185  //
186  // TRANSLATION: MapObject Zoom <-> OpenLayers Zoom
187  //
188 
189    /**
190     * APIMethod: getOLZoomFromMapObjectZoom
191     *
192     * Parameters:
193     * gZoom - {Integer}
194     *
195     * Returns:
196     * {Integer} An OpenLayers Zoom level, translated from the passed in gZoom
197     *           Returns null if null value is passed in.
198     */
199    getOLZoomFromMapObjectZoom: function(moZoom) {
200        var zoom = null;
201        if (moZoom != null) {
202            zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getOLZoomFromMapObjectZoom.apply(this, [moZoom]);
203            zoom = 18 - zoom;
204        }
205        return zoom;
206    },
207   
208    /**
209     * APIMethod: getMapObjectZoomFromOLZoom
210     *
211     * Parameters:
212     * olZoom - {Integer}
213     *
214     * Returns:
215     * {Integer} A MapObject level, translated from the passed in olZoom
216     *           Returns null if null value is passed in
217     */
218    getMapObjectZoomFromOLZoom: function(olZoom) {
219        var zoom = null; 
220        if (olZoom != null) {
221            zoom = OpenLayers.Layer.FixedZoomLevels.prototype.getMapObjectZoomFromOLZoom.apply(this, [olZoom]);
222            zoom = 18 - zoom;
223        }
224        return zoom;
225    },
226
227    /************************************
228     *                                  *
229     *   MapObject Interface Controls   *
230     *                                  *
231     ************************************/
232
233
234  // Get&Set Center, Zoom
235
236    /**
237     * APIMethod: setMapObjectCenter
238     * Set the mapObject to the specified center and zoom
239     *
240     * Parameters:
241     * center - {Object} MapObject LonLat format
242     * zoom - {int} MapObject zoom format
243     */
244    setMapObjectCenter: function(center, zoom) {
245        this.mapObject.drawZoomAndCenter(center, zoom); 
246    },
247   
248    /**
249     * APIMethod: getMapObjectCenter
250     *
251     * Returns:
252     * {Object} The mapObject's current center in Map Object format
253     */
254    getMapObjectCenter: function() {
255        return this.mapObject.getCenterLatLon();
256    },
257
258    /**
259     * APIMethod: dragPanMapObject
260     *
261     * Parameters:
262     * dX - {Integer}
263     * dY - {Integer}
264     */
265    dragPanMapObject: function(dX, dY) {
266        this.mapObject.moveByXY({
267            'x': -dX,
268            'y': dY
269        });
270    },
271   
272    /**
273     * APIMethod: getMapObjectZoom
274     *
275     * Returns:
276     * {Integer} The mapObject's current zoom, in Map Object format
277     */
278    getMapObjectZoom: function() {
279        return this.mapObject.getZoomLevel();
280    },
281
282
283  // LonLat - Pixel Translation
284 
285    /**
286     * APIMethod: getMapObjectLonLatFromMapObjectPixel
287     *
288     * Parameters:
289     * moPixel - {Object} MapObject Pixel format
290     *
291     * Returns:
292     * {Object} MapObject LonLat translated from MapObject Pixel
293     */
294    getMapObjectLonLatFromMapObjectPixel: function(moPixel) {
295        return this.mapObject.convertXYLatLon(moPixel);
296    },
297
298    /**
299     * APIMethod: getMapObjectPixelFromMapObjectLonLat
300     *
301     * Parameters:
302     * moLonLat - {Object} MapObject LonLat format
303     *
304     * Returns:
305     * {Object} MapObject Pixel transtlated from MapObject LonLat
306     */
307    getMapObjectPixelFromMapObjectLonLat: function(moLonLat) {
308        return this.mapObject.convertLatLonXY(moLonLat);
309    },
310
311
312    /************************************
313     *                                  *
314     *       MapObject Primitives       *
315     *                                  *
316     ************************************/
317
318
319  // LonLat
320   
321    /**
322     * APIMethod: getLongitudeFromMapObjectLonLat
323     *
324     * Parameters:
325     * moLonLat - {Object} MapObject LonLat format
326     *
327     * Returns:
328     * {Float} Longitude of the given MapObject LonLat
329     */
330    getLongitudeFromMapObjectLonLat: function(moLonLat) {
331        return this.sphericalMercator ? 
332            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lon :
333            moLonLat.Lon;
334    },
335
336    /**
337     * APIMethod: getLatitudeFromMapObjectLonLat
338     *
339     * Parameters:
340     * moLonLat - {Object} MapObject LonLat format
341     *
342     * Returns:
343     * {Float} Latitude of the given MapObject LonLat
344     */
345    getLatitudeFromMapObjectLonLat: function(moLonLat) {
346        return this.sphericalMercator ? 
347            this.forwardMercator(moLonLat.Lon, moLonLat.Lat).lat :
348            moLonLat.Lat;
349    },
350
351    /**
352     * APIMethod: getMapObjectLonLatFromLonLat
353     *
354     * Parameters:
355     * lon - {Float}
356     * lat - {Float}
357     *
358     * Returns:
359     * {Object} MapObject LonLat built from lon and lat params
360     */
361    getMapObjectLonLatFromLonLat: function(lon, lat) {
362        var yLatLong;
363        if(this.sphericalMercator) {
364            var lonlat = this.inverseMercator(lon, lat);
365            yLatLong = new YGeoPoint(lonlat.lat, lonlat.lon);
366        } else {
367            yLatLong = new YGeoPoint(lat, lon);
368        }
369        return yLatLong;
370    },
371
372  // Pixel
373   
374    /**
375     * APIMethod: getXFromMapObjectPixel
376     *
377     * Parameters:
378     * moPixel - {Object} MapObject Pixel format
379     *
380     * Returns:
381     * {Integer} X value of the MapObject Pixel
382     */
383    getXFromMapObjectPixel: function(moPixel) {
384        return moPixel.x;
385    },
386
387    /**
388     * APIMethod: getYFromMapObjectPixel
389     *
390     * Parameters:
391     * moPixel - {Object} MapObject Pixel format
392     *
393     * Returns:
394     * {Integer} Y value of the MapObject Pixel
395     */
396    getYFromMapObjectPixel: function(moPixel) {
397        return moPixel.y;
398    },
399
400    /**
401     * APIMethod: getMapObjectPixelFromXY
402     *
403     * Parameters:
404     * x - {Integer}
405     * y - {Integer}
406     *
407     * Returns:
408     * {Object} MapObject Pixel from x and y parameters
409     */
410    getMapObjectPixelFromXY: function(x, y) {
411        return new YCoordPoint(x, y);
412    },
413   
414  // Size
415 
416    /**
417     * APIMethod: getMapObjectSizeFromOLSize
418     *
419     * Parameters:
420     * olSize - {<OpenLayers.Size>}
421     *
422     * Returns:
423     * {Object} MapObject Size from olSize parameter
424     */
425    getMapObjectSizeFromOLSize: function(olSize) {
426        return new YSize(olSize.w, olSize.h);
427    },
428   
429    CLASS_NAME: "OpenLayers.Layer.Yahoo"
430});
Note: See TracBrowser for help on using the repository browser.