Ticket #442: final_animatedZooming_PanZoomBar.patch
| File final_animatedZooming_PanZoomBar.patch, 4.9 kB (added by emanuel, 3 years ago) |
|---|
-
tests/Control/test_PanZoomBar.html
old new 30 30 map.addControl(control2, new OpenLayers.Pixel(100,100)); 31 31 t.eq( control2.div.style.top, "100px", "2nd control div is located correctly"); 32 32 } 33 34 function test_03_Control_PanZoomBar_control_events (t) { 35 t.plan( 3 ); 36 37 var evt = {which: 1}; // control expects left-click 38 map = new OpenLayers.Map('map'); 39 var layer = new OpenLayers.Layer.WMS("Test Layer", 40 "http://octo.metacarta.com/cgi-bin/mapserv?", 41 {map: "/mapdata/vmap_wms.map", layers: "basic"}); 42 map.addLayer(layer); 43 control = new OpenLayers.Control.PanZoomBar(); 44 map.addControl(control); 45 var centerLL = new OpenLayers.LonLat(0,0); 46 map.setCenter(centerLL, 0); 47 48 evt.xy = new OpenLayers.Pixel(10,115); 49 evt.object = control; 50 control.divClick(evt); 51 t.delay_call( 52 1, function() { 53 t.eq(map.zoom, 5, 54 "Clicking on the zoombar has the correct effect on zoomlevel"); 55 56 control.zoomBarDown(evt); 57 evt.xy.y -= 30; 58 control.zoomBarDrag(evt); 59 60 control.zoomBarUp(evt); 61 }, 62 1, function() { 63 t.eq(map.zoom, 8, 64 "Dragging the zoomslider works correctly"); 65 t.eq(control.slider.style.top, "159px", 66 "Zoomslider top position has been set correctly"); 67 } 68 69 ); 70 71 72 73 } 74 33 75 // --> 34 76 </script> 35 77 </head> -
lib/OpenLayers/Control/PanZoomBar.js
old new 152 152 var y = evt.xy.y; 153 153 var top = OpenLayers.Util.pagePosition(evt.object)[1]; 154 154 var levels = Math.floor((y - top)/this.zoomStopHeight); 155 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 155 156 if (!this.map.zoomanimationActive) 157 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 158 156 159 OpenLayers.Event.stop(evt); 157 160 }, 158 161 … … 165 168 this.map.events.register("mousemove", this, this.passEventToSlider); 166 169 this.map.events.register("mouseup", this, this.passEventToSlider); 167 170 this.mouseDragStart = evt.xy.clone(); 168 this. zoomStart = evt.xy.clone();171 this.map.zoomStart = evt.xy.clone(); 169 172 this.div.style.cursor = "move"; 173 174 // get and set some settings for zoom animation 175 this.map.prepareZoomAnimation(); 176 170 177 OpenLayers.Event.stop(evt); 171 178 }, 172 179 … … 186 193 this.slider.style.top = newTop+"px"; 187 194 } 188 195 this.mouseDragStart = evt.xy.clone(); 196 197 // set current slider position 198 var sliderPosition = new OpenLayers.Pixel(evt.xy.x, evt.xy.y); 199 200 // run zoom animation -> scale tile(s) 201 this.map.runZoomAnimation(this.zoomStopHeight, sliderPosition); 202 189 203 OpenLayers.Event.stop(evt); 190 204 } 191 205 }, … … 197 211 */ 198 212 zoomBarUp:function(evt) { 199 213 if (!OpenLayers.Event.isLeftClick(evt)) return; 200 if (this. zoomStart) {214 if (this.map.zoomStart) { 201 215 this.div.style.cursor="default"; 202 216 this.map.events.unregister("mouseup", this, this.passEventToSlider); 203 217 this.map.events.unregister("mousemove", this, this.passEventToSlider); 204 var deltaY = this.zoomStart.y - evt.xy.y 205 this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 218 var deltaY = this.map.zoomStart.y - evt.xy.y; 219 220 // zoom map to new zoomlevel 221 var finalZoomlevel = this.map.zoom + Math.round(deltaY/this.zoomStopHeight); 222 223 // finish zoom animation 224 this.map.finishZoomAnimation(finalZoomlevel); 225 206 226 this.moveZoomBar(); 207 227 this.mouseDragStart = null; 208 228 OpenLayers.Event.stop(evt); … … 211 231 212 232 /* 213 233 * Change the location of the slider to match the current zoom level. 234 * 235 * @param {float} zoomlevel 214 236 */ 215 moveZoomBar:function() { 216 var newTop = 217 ((this.map.getNumZoomLevels()-1) - this.map.getZoom()) * 237 moveZoomBar:function(zoomlevel) { 238 // check if zoomlevel is not a number 239 if (isNaN(zoomlevel)) { 240 zoomlevel = this.map.getZoom(); 241 } 242 243 // set new top position 244 var newTop = ((this.map.getNumZoomLevels()-1) - zoomlevel) * 218 245 this.zoomStopHeight + this.startTop + 1; 219 246 this.slider.style.top = newTop + "px"; 220 247 },
