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

Revision 76, 8.4 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 * @requires OpenLayers/Control/ZoomBox.js
8 * @requires OpenLayers/Control/DragPan.js
9 * @requires OpenLayers/Handler/MouseWheel.js
10 * @requires OpenLayers/Handler/Click.js
11 */
12
13/**
14 * Class: OpenLayers.Control.Navigation
15 * The navigation control handles map browsing with mouse events (dragging,
16 *     double-clicking, and scrolling the wheel).  Create a new navigation
17 *     control with the <OpenLayers.Control.Navigation> control. 
18 *
19 *     Note that this control is added to the map by default (if no controls
20 *     array is sent in the options object to the <OpenLayers.Map>
21 *     constructor).
22 *
23 * Inherits:
24 *  - <OpenLayers.Control>
25 */
26OpenLayers.Control.Navigation = OpenLayers.Class(OpenLayers.Control, {
27
28    /**
29     * Property: dragPan
30     * {<OpenLayers.Control.DragPan>}
31     */
32    dragPan: null,
33
34    /**
35     * APIProprety: dragPanOptions
36     * {Object} Options passed to the DragPan control.
37     */
38    dragPanOptions: null,
39
40    /**
41     * APIProperty: documentDrag
42     * {Boolean} Allow panning of the map by dragging outside map viewport.
43     *     Default is false.
44     */
45    documentDrag: false,
46
47    /**
48     * Property: zoomBox
49     * {<OpenLayers.Control.ZoomBox>}
50     */
51    zoomBox: null,
52
53    /**
54     * APIProperty: zoomBoxEnabled
55     * {Boolean} Whether the user can draw a box to zoom
56     */
57    zoomBoxEnabled: true, 
58
59    /**
60     * APIProperty: zoomWheelEnabled
61     * {Boolean} Whether the mousewheel should zoom the map
62     */
63    zoomWheelEnabled: true,
64   
65    /**
66     * Property: mouseWheelOptions
67     * {Object} Options passed to the MouseWheel control (only useful if
68     *     <zoomWheelEnabled> is set to true)
69     */
70    mouseWheelOptions: null,
71
72    /**
73     * APIProperty: handleRightClicks
74     * {Boolean} Whether or not to handle right clicks. Default is false.
75     */
76    handleRightClicks: false,
77
78    /**
79     * APIProperty: zoomBoxKeyMask
80     * {Integer} <OpenLayers.Handler> key code of the key, which has to be
81     *    pressed, while drawing the zoom box with the mouse on the screen.
82     *    You should probably set handleRightClicks to true if you use this
83     *    with MOD_CTRL, to disable the context menu for machines which use
84     *    CTRL-Click as a right click.
85     * Default: <OpenLayers.Handler.MOD_SHIFT
86     */
87    zoomBoxKeyMask: OpenLayers.Handler.MOD_SHIFT,
88   
89    /**
90     * APIProperty: autoActivate
91     * {Boolean} Activate the control when it is added to a map.  Default is
92     *     true.
93     */
94    autoActivate: true,
95
96    /**
97     * Constructor: OpenLayers.Control.Navigation
98     * Create a new navigation control
99     *
100     * Parameters:
101     * options - {Object} An optional object whose properties will be set on
102     *                    the control
103     */
104    initialize: function(options) {
105        this.handlers = {};
106        OpenLayers.Control.prototype.initialize.apply(this, arguments);
107    },
108
109    /**
110     * Method: destroy
111     * The destroy method is used to perform any clean up before the control
112     * is dereferenced.  Typically this is where event listeners are removed
113     * to prevent memory leaks.
114     */
115    destroy: function() {
116        this.deactivate();
117
118        if (this.dragPan) {
119            this.dragPan.destroy();
120        }
121        this.dragPan = null;
122
123        if (this.zoomBox) {
124            this.zoomBox.destroy();
125        }
126        this.zoomBox = null;
127        OpenLayers.Control.prototype.destroy.apply(this,arguments);
128    },
129   
130    /**
131     * Method: activate
132     */
133    activate: function() {
134        this.dragPan.activate();
135        if (this.zoomWheelEnabled) {
136            this.handlers.wheel.activate();
137        }   
138        this.handlers.click.activate();
139        if (this.zoomBoxEnabled) {
140            this.zoomBox.activate();
141        }
142        return OpenLayers.Control.prototype.activate.apply(this,arguments);
143    },
144
145    /**
146     * Method: deactivate
147     */
148    deactivate: function() {
149        this.zoomBox.deactivate();
150        this.dragPan.deactivate();
151        this.handlers.click.deactivate();
152        this.handlers.wheel.deactivate();
153        return OpenLayers.Control.prototype.deactivate.apply(this,arguments);
154    },
155   
156    /**
157     * Method: draw
158     */
159    draw: function() {
160        // disable right mouse context menu for support of right click events
161        if (this.handleRightClicks) {
162            this.map.viewPortDiv.oncontextmenu = OpenLayers.Function.False;
163        }
164
165        var clickCallbacks = { 
166            'dblclick': this.defaultDblClick, 
167            'dblrightclick': this.defaultDblRightClick 
168        };
169        var clickOptions = {
170            'double': true, 
171            'stopDouble': true
172        };
173        this.handlers.click = new OpenLayers.Handler.Click(
174            this, clickCallbacks, clickOptions
175        );
176        this.dragPan = new OpenLayers.Control.DragPan(
177            OpenLayers.Util.extend({
178                map: this.map,
179                documentDrag: this.documentDrag
180            }, this.dragPanOptions)
181        );
182        this.zoomBox = new OpenLayers.Control.ZoomBox(
183                    {map: this.map, keyMask: this.zoomBoxKeyMask});
184        this.dragPan.draw();
185        this.zoomBox.draw();
186        this.handlers.wheel = new OpenLayers.Handler.MouseWheel(
187                                    this, {"up"  : this.wheelUp,
188                                           "down": this.wheelDown},
189                                    this.mouseWheelOptions );
190    },
191
192    /**
193     * Method: defaultDblClick
194     *
195     * Parameters:
196     * evt - {Event}
197     */
198    defaultDblClick: function (evt) {
199        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); 
200        this.map.setCenter(newCenter, this.map.zoom + 1);
201    },
202
203    /**
204     * Method: defaultDblRightClick
205     *
206     * Parameters:
207     * evt - {Event}
208     */
209    defaultDblRightClick: function (evt) {
210        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); 
211        this.map.setCenter(newCenter, this.map.zoom - 1);
212    },
213   
214    /**
215     * Method: wheelChange 
216     *
217     * Parameters:
218     * evt - {Event}
219     * deltaZ - {Integer}
220     */
221    wheelChange: function(evt, deltaZ) {
222        var currentZoom = this.map.getZoom();
223        var newZoom = this.map.getZoom() + Math.round(deltaZ);
224        newZoom = Math.max(newZoom, 0);
225        newZoom = Math.min(newZoom, this.map.getNumZoomLevels());
226        if (newZoom === currentZoom) {
227            return;
228        }
229        var size    = this.map.getSize();
230        var deltaX  = size.w/2 - evt.xy.x;
231        var deltaY  = evt.xy.y - size.h/2;
232        var newRes  = this.map.baseLayer.getResolutionForZoom(newZoom);
233        var zoomPoint = this.map.getLonLatFromPixel(evt.xy);
234        var newCenter = new OpenLayers.LonLat(
235                            zoomPoint.lon + deltaX * newRes,
236                            zoomPoint.lat + deltaY * newRes );
237        this.map.setCenter( newCenter, newZoom );
238    },
239
240    /**
241     * Method: wheelUp
242     * User spun scroll wheel up
243     *
244     * Parameters:
245     * evt - {Event}
246     * delta - {Integer}
247     */
248    wheelUp: function(evt, delta) {
249        this.wheelChange(evt, delta || 1);
250    },
251
252    /**
253     * Method: wheelDown
254     * User spun scroll wheel down
255     *
256     * Parameters:
257     * evt - {Event}
258     * delta - {Integer}
259     */
260    wheelDown: function(evt, delta) {
261        this.wheelChange(evt, delta || -1);
262    },
263   
264    /**
265     * Method: disableZoomBox
266     */
267    disableZoomBox : function() {
268        this.zoomBoxEnabled = false;
269        this.zoomBox.deactivate();       
270    },
271   
272    /**
273     * Method: enableZoomBox
274     */
275    enableZoomBox : function() {
276        this.zoomBoxEnabled = true;
277        if (this.active) {
278            this.zoomBox.activate();
279        }   
280    },
281   
282    /**
283     * Method: disableZoomWheel
284     */
285   
286    disableZoomWheel : function() {
287        this.zoomWheelEnabled = false;
288        this.handlers.wheel.deactivate();       
289    },
290   
291    /**
292     * Method: enableZoomWheel
293     */
294   
295    enableZoomWheel : function() {
296        this.zoomWheelEnabled = true;
297        if (this.active) {
298            this.handlers.wheel.activate();
299        }   
300    },
301
302    CLASS_NAME: "OpenLayers.Control.Navigation"
303});
Note: See TracBrowser for help on using the repository browser.