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

Revision 76, 6.9 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/Control.js
9 */
10
11/**
12 * Class: OpenLayers.Control.PanZoom
13 * The PanZoom is a visible control, composed of a
14 * <OpenLayers.Control.PanPanel> and a <OpenLayers.Control.ZoomPanel>. By
15 * default it is drawn in the upper left corner of the map.
16 *
17 * Inherits from:
18 *  - <OpenLayers.Control>
19 */
20OpenLayers.Control.PanZoom = OpenLayers.Class(OpenLayers.Control, {
21
22    /**
23     * APIProperty: slideFactor
24     * {Integer} Number of pixels by which we'll pan the map in any direction
25     *     on clicking the arrow buttons.  If you want to pan by some ratio
26     *     of the map dimensions, use <slideRatio> instead.
27     */
28    slideFactor: 50,
29
30    /**
31     * APIProperty: slideRatio
32     * {Number} The fraction of map width/height by which we'll pan the map           
33     *     on clicking the arrow buttons.  Default is null.  If set, will
34     *     override <slideFactor>. E.g. if slideRatio is .5, then the Pan Up
35     *     button will pan up half the map height.
36     */
37    slideRatio: null,
38
39    /**
40     * Property: buttons
41     * {Array(DOMElement)} Array of Button Divs
42     */
43    buttons: null,
44
45    /**
46     * Property: position
47     * {<OpenLayers.Pixel>}
48     */
49    position: null,
50
51    /**
52     * Constructor: OpenLayers.Control.PanZoom
53     *
54     * Parameters:
55     * options - {Object}
56     */
57    initialize: function(options) {
58        this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoom.X,
59                                             OpenLayers.Control.PanZoom.Y);
60        OpenLayers.Control.prototype.initialize.apply(this, arguments);
61    },
62
63    /**
64     * APIMethod: destroy
65     */
66    destroy: function() {
67        OpenLayers.Control.prototype.destroy.apply(this, arguments);
68        this.removeButtons();
69        this.buttons = null;
70        this.position = null;
71    },
72
73    /**
74     * Method: draw
75     *
76     * Parameters:
77     * px - {<OpenLayers.Pixel>}
78     *
79     * Returns:
80     * {DOMElement} A reference to the container div for the PanZoom control.
81     */
82    draw: function(px) {
83        // initialize our internal div
84        OpenLayers.Control.prototype.draw.apply(this, arguments);
85        px = this.position;
86
87        // place the controls
88        this.buttons = [];
89
90        var sz = new OpenLayers.Size(18,18);
91        var centered = new OpenLayers.Pixel(px.x+sz.w/2, px.y);
92
93        this._addButton("panup", "north-mini.png", centered, sz);
94        px.y = centered.y+sz.h;
95        this._addButton("panleft", "west-mini.png", px, sz);
96        this._addButton("panright", "east-mini.png", px.add(sz.w, 0), sz);
97        this._addButton("pandown", "south-mini.png", 
98                        centered.add(0, sz.h*2), sz);
99        this._addButton("zoomin", "zoom-plus-mini.png", 
100                        centered.add(0, sz.h*3+5), sz);
101        this._addButton("zoomworld", "zoom-world-mini.png", 
102                        centered.add(0, sz.h*4+5), sz);
103        this._addButton("zoomout", "zoom-minus-mini.png", 
104                        centered.add(0, sz.h*5+5), sz);
105        return this.div;
106    },
107   
108    /**
109     * Method: _addButton
110     *
111     * Parameters:
112     * id - {String}
113     * img - {String}
114     * xy - {<OpenLayers.Pixel>}
115     * sz - {<OpenLayers.Size>}
116     *
117     * Returns:
118     * {DOMElement} A Div (an alphaImageDiv, to be precise) that contains the
119     *     image of the button, and has all the proper event handlers set.
120     */
121    _addButton:function(id, img, xy, sz) {
122        var imgLocation = OpenLayers.Util.getImagesLocation() + img;
123        var btn = OpenLayers.Util.createAlphaImageDiv(
124                                    this.id + "_" + id, 
125                                    xy, sz, imgLocation, "absolute");
126
127        //we want to add the outer div
128        this.div.appendChild(btn);
129
130        OpenLayers.Event.observe(btn, "mousedown", 
131            OpenLayers.Function.bindAsEventListener(this.buttonDown, btn));
132        OpenLayers.Event.observe(btn, "dblclick", 
133            OpenLayers.Function.bindAsEventListener(this.doubleClick, btn));
134        OpenLayers.Event.observe(btn, "click", 
135            OpenLayers.Function.bindAsEventListener(this.doubleClick, btn));
136        btn.action = id;
137        btn.map = this.map;
138   
139        if(!this.slideRatio){
140            var slideFactorPixels = this.slideFactor;
141            var getSlideFactor = function() {
142                return slideFactorPixels;
143            };
144        } else {
145            var slideRatio = this.slideRatio;
146            var getSlideFactor = function(dim) {
147                return this.map.getSize()[dim] * slideRatio;
148            };
149        }
150
151        btn.getSlideFactor = getSlideFactor;
152
153        //we want to remember/reference the outer div
154        this.buttons.push(btn);
155        return btn;
156    },
157   
158    /**
159     * Method: _removeButton
160     *
161     * Parameters:
162     * btn - {Object}
163     */
164    _removeButton: function(btn) {
165        OpenLayers.Event.stopObservingElement(btn);
166        btn.map = null;
167        btn.getSlideFactor = null;
168        this.div.removeChild(btn);
169        OpenLayers.Util.removeItem(this.buttons, btn);
170    },
171   
172    /**
173     * Method: removeButtons
174     */
175    removeButtons: function() {
176        for(var i=this.buttons.length-1; i>=0; --i) {
177            this._removeButton(this.buttons[i]);
178        }
179    },
180   
181    /**
182     * Method: doubleClick
183     *
184     * Parameters:
185     * evt - {Event}
186     *
187     * Returns:
188     * {Boolean}
189     */
190    doubleClick: function (evt) {
191        OpenLayers.Event.stop(evt);
192        return false;
193    },
194   
195    /**
196     * Method: buttonDown
197     *
198     * Parameters:
199     * evt - {Event}
200     */
201    buttonDown: function (evt) {
202        if (!OpenLayers.Event.isLeftClick(evt)) {
203            return;
204        }
205
206        switch (this.action) {
207            case "panup": 
208                this.map.pan(0, -this.getSlideFactor("h"));
209                break;
210            case "pandown": 
211                this.map.pan(0, this.getSlideFactor("h"));
212                break;
213            case "panleft": 
214                this.map.pan(-this.getSlideFactor("w"), 0);
215                break;
216            case "panright": 
217                this.map.pan(this.getSlideFactor("w"), 0);
218                break;
219            case "zoomin": 
220                this.map.zoomIn(); 
221                break;
222            case "zoomout": 
223                this.map.zoomOut(); 
224                break;
225            case "zoomworld": 
226                this.map.zoomToMaxExtent(); 
227                break;
228        }
229
230        OpenLayers.Event.stop(evt);
231    },
232
233    CLASS_NAME: "OpenLayers.Control.PanZoom"
234});
235
236/**
237 * Constant: X
238 * {Integer}
239 */
240OpenLayers.Control.PanZoom.X = 4;
241
242/**
243 * Constant: Y
244 * {Integer}
245 */
246OpenLayers.Control.PanZoom.Y = 4;
Note: See TracBrowser for help on using the repository browser.