Changeset 2292
- Timestamp:
- 03/01/07 11:57:42 (2 years ago)
- Files:
-
- sandbox/emanuel/animatedZooming/demo.html (modified) (4 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/KeyboardDefaults.js (modified) (3 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js (modified) (3 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js (modified) (3 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoom.js (modified) (2 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js (modified) (7 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js (modified) (7 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js (modified) (8 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/emanuel/animatedZooming/demo.html
r2275 r2292 4 4 #map { 5 5 width: 100%; 6 height: 51 2px;6 height: 511px; 7 7 border: 1px solid black; 8 8 } … … 10 10 <title>Animated Zooming Demo</title> 11 11 12 <!-- this gmaps key generated for http://openlayers.org/dev/ -->13 <!-- <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>-->14 15 12 <script src="./lib/OpenLayers.js"></script> 16 13 <script type="text/javascript"> … … 23 20 map.addControl(new OpenLayers.Control.PanZoomBar()); 24 21 map.addControl(new OpenLayers.Control.MouseToolbar()); 22 map.addControl(new OpenLayers.Control.KeyboardDefaults()); 25 23 map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); 26 24 map.addControl(new OpenLayers.Control.MousePosition()); … … 43 41 new OpenLayers.Size(580, 288), 44 42 {maxResolution: 'auto', numZoomLevels: 5}); 45 /* 46 var satellite_google = new OpenLayers.Layer.Google( 47 "Google Satellite", 48 {type: G_SATELLITE_MAP, 'maxZoomLevel':18} );*/ 49 43 50 44 var dm_wms = new OpenLayers.Layer.WMS( "DM Solutions Demo", 51 45 "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", sandbox/emanuel/animatedZooming/lib/OpenLayers/Control.js
r1721 r2292 71 71 } 72 72 this.moveTo(this.position); 73 73 74 return this.div; 74 75 }, sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/KeyboardDefaults.js
r1721 r2292 14 14 15 15 /** @type int */ 16 slideFactor: 50,16 slideFactor: 100, 17 17 18 18 /** … … 27 27 */ 28 28 draw: function() { 29 //keypress 29 30 OpenLayers.Event.observe(document, 30 31 'keypress', 31 this.defaultKeyDown.bind(this)); 32 this.defaultKeyDown.bindAsEventListener(this)); 33 OpenLayers.Event.observe(document, 34 'keyup', 35 this.defaultKeyUp.bindAsEventListener(this)); 32 36 }, 33 37 … … 38 42 switch(evt.keyCode) { 39 43 case OpenLayers.Event.KEY_LEFT: 40 this.map.pan(- 50, 0);44 this.map.pan(-75, 0); 41 45 break; 42 46 case OpenLayers.Event.KEY_RIGHT: 43 this.map.pan( 50, 0);47 this.map.pan(75, 0); 44 48 break; 45 49 case OpenLayers.Event.KEY_UP: 46 this.map.pan(0, - 50);50 this.map.pan(0, -75); 47 51 break; 48 52 case OpenLayers.Event.KEY_DOWN: 49 this.map.pan(0, 50);53 this.map.pan(0, 75); 50 54 break; 55 case 33: // Page Up 56 var size = this.map.getSize(); 57 this.map.pan(0, -0.75*size.h); 58 break; 59 case 34: // Page Down 60 var size = this.map.getSize(); 61 this.map.pan(0, 0.75*size.h); 62 break; 63 case 35: // End 64 var size = this.map.getSize(); 65 this.map.pan(0.75*size.w, 0); 66 break; 67 case 36: // Pos1 68 var size = this.map.getSize(); 69 this.map.pan(-0.75*size.w, 0); 70 break; 51 71 } 72 switch(evt.charCode) { 73 case 43: // + 74 // get and set some settings for zoom animation 75 this.map.prepareZoomAnimation(); 76 this.map.zoomlevel_scale += 0.2; 77 // run zoom animation -> scale tile(s) 78 this.map.runZoomAnimation(); 79 break; 80 case 45: // - 81 // get and set some settings for zoom animation 82 this.map.prepareZoomAnimation(); 83 this.map.zoomlevel_scale -= 0.2; 84 // run zoom animation -> scale tile(s) 85 this.map.runZoomAnimation(); 86 break; 87 } 52 88 }, 53 89 90 defaultKeyUp: function (evt) { 91 switch(evt.keyCode) { 92 case 107: 93 if((this.map.zoomlevel_scale-this.map.zoomlevel_startScale) < 1) 94 { 95 //this.map.zoomlevel_scale = Math.ceil(this.map.zoomlevel_scale); 96 //this.map.runZoomAnimation(); 97 this.map.zoomTo(this.map.zoomlevel_startScale+1); 98 } 99 //this.map.finishZoomAnimation(Math.round(this.map.zoomlevel_scale)); 100 101 case 109: 102 if((this.map.zoomlevel_scale-this.map.zoomlevel_startScale) < 1) 103 { 104 Math.floor(this.map.zoomlevel_scale); 105 this.map.runZoomAnimation(); 106 } 107 // finish zoom animation 108 this.map.finishZoomAnimation(Math.round(this.map.zoomlevel_scale)); 109 break; 110 111 } 112 113 114 115 }, 116 117 54 118 /** @final @type String */ 55 119 CLASS_NAME: "OpenLayers.Control.KeyboardDefaults" sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseDefaults.js
r2102 r2292 69 69 */ 70 70 defaultDblClick: function (evt) { 71 //var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); 72 //this.map.setCenter(newCenter, this.map.zoom + 1); 73 74 // convert the (old) center of the map in pixel 75 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 76 77 // pan to new center 78 var deltaX = evt.xy.x - centerPx.x; 79 var deltaY = evt.xy.y - centerPx.y; 80 // some problems if you pan AND zoom in the same time... TODO 81 this.map.pan(deltaX, deltaY,true); 82 83 // 1. jump to new center (no pan animation!) 71 84 var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); 72 this.map.setCenter(newCenter, this.map.zoom + 1); 85 //this.map.setCenter(newCenter, this.map.zoom); 86 87 // 2. zoom to new level 88 this.map.zoomIn(); 89 73 90 OpenLayers.Event.stop(evt); 74 91 return false; … … 171 188 defaultWheelUp: function(evt) { 172 189 if (this.map.getZoom() <= this.map.getNumZoomLevels()) { 173 this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 174 this.map.getZoom() + 1); 190 if (!this.map.zoomanimationActive) { 191 // convert the current center of the map in pixel 192 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 193 194 // determine lonlat from target (mouse position) 195 var targetLonLat = this.map.getLonLatFromViewPortPx( evt.xy ); 196 197 // determine offset target-center in pixel 198 var offset = new OpenLayers.Pixel(); 199 offset.x = evt.xy.x - centerPx.x; 200 offset.y = evt.xy.y - centerPx.y; 201 202 // convert offset of zoomlevel n to zoomlevel n+1 203 offset.x = offset.x / 2; 204 offset.y = offset.y / 2; 205 206 // pan to new center 207 this.map.pan(offset.x, offset.y, true); 208 209 // zoom to new level 210 this.map.zoomIn(); 211 } 175 212 } 176 213 }, … … 181 218 defaultWheelDown: function(evt) { 182 219 if (this.map.getZoom() > 0) { 183 this.map.setCenter(this.map.getLonLatFromPixel(evt.xy), 184 this.map.getZoom() - 1); 220 if (!this.map.zoomanimationActive) { 221 // convert the current center of the map in pixel 222 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 223 224 // determine lonlat from target (mouse position) 225 var targetLonLat = this.map.getLonLatFromViewPortPx( evt.xy ); 226 227 // determine offset target-center in pixel... 228 var offset = new OpenLayers.Pixel(); 229 offset.x = evt.xy.x - centerPx.x; 230 offset.y = evt.xy.y - centerPx.y; 231 232 // convert offset of zoomlevel n to zoomlevel n-1 233 offset.x = -offset.x; 234 offset.y = -offset.y; 235 236 // pan to new center 237 this.map.pan(offset.x, offset.y, true); 238 239 // zoom to new level 240 this.map.zoomOut(); 241 } 185 242 } 186 243 }, sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/MouseToolbar.js
r2102 r2292 49 49 centered = centered.add((this.direction == "vertical" ? 0 : sz.w), (this.direction == "vertical" ? sz.h : 0)); 50 50 this.switchModeTo("pan"); 51 52 this.registerWheelEvents(); 51 52 // already registered in MouseDefaults 53 //this.registerWheelEvents(); 53 54 54 55 return this.div; … … 111 112 this.switchModeTo("pan"); 112 113 this.performedDrag = false; 114 115 // convert the (old) center of the map in pixel 116 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 117 118 // pan to new center 119 var deltaX = evt.xy.x - centerPx.x; 120 var deltaY = evt.xy.y - centerPx.y; 121 // some problems if you pan AND zoom in the same time... TODO 122 this.map.pan(deltaX, deltaY,true); 123 124 // jump to new center (no pan animation!) 113 125 var newCenter = this.map.getLonLatFromViewPortPx( evt.xy ); 114 this.map.setCenter(newCenter, this.map.zoom + 1); 126 //this.map.setCenter(newCenter, this.map.zoom); 127 128 // get tile below mouseposition 129 var targetTile = evt.target; 130 // 2. zoom to new level 131 this.map.zoomIn(targetTile); 132 115 133 OpenLayers.Event.stop(evt); 116 134 return false; … … 240 258 */ 241 259 defaultMouseMove: function (evt) { 260 // record the mouse position, used in onWheelEvent 261 this.mousePosition = evt.xy.clone(); 262 242 263 if (this.mouseDragStart != null) { 243 264 switch (this.mode) { sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoom.js
r2224 r2292 16 16 17 17 /** @type int */ 18 slideFactor: 50,18 slideFactor: 100, 19 19 20 20 /** @type Array of Button Divs */ … … 115 115 switch (this.action) { 116 116 case "panup": 117 this.map.pan(0, - 50);117 this.map.pan(0, -this.slideFactor); 118 118 break; 119 119 case "pandown": 120 this.map.pan(0, 50);120 this.map.pan(0, this.slideFactor); 121 121 break; 122 122 case "panleft": 123 this.map.pan(- 50, 0);123 this.map.pan(-this.slideFactor, 0); 124 124 break; 125 125 case "panright": 126 this.map.pan( 50, 0);126 this.map.pan(this.slideFactor, 0); 127 127 break; 128 128 case "zoomin": sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js
r2275 r2292 24 24 zoomStopHeight: 11, 25 25 26 /** @type int */27 zoomlevel_startScale: null,28 29 /** @type float */30 zoomlevel_scale: null,31 32 /** @type OpenLayers.Size */33 tileSize_startScale: null,34 35 /** @type OpenLayers.Size */36 tileSize_scale: null,37 38 /** @type OpenLayers.Tile */39 centerTile: null,40 41 /** @type float */42 resolution_scale: null,43 26 44 27 initialize: function() { … … 46 29 this.position = new OpenLayers.Pixel(OpenLayers.Control.PanZoomBar.X, 47 30 OpenLayers.Control.PanZoomBar.Y); 48 this.tileSize_scale = new OpenLayers.Size();49 31 }, 50 32 … … 172 154 var top = OpenLayers.Util.pagePosition(evt.object)[1]; 173 155 var levels = Math.floor((y - top)/this.zoomStopHeight); 174 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 175 OpenLayers.Event.stop(evt); 176 }, 177 178 /* 179 * @param evt 180 * event listener for clicks on the slider 181 */ 182 zoomBarDown:function(evt) { 183 if (!OpenLayers.Event.isLeftClick(evt)) return; 184 this.map.events.register("mousemove", this, this.passEventToSlider); 185 this.map.events.register("mouseup", this, this.passEventToSlider); 186 this.mouseDragStart = evt.xy.clone(); 187 this.zoomStart = evt.xy.clone(); 188 this.div.style.cursor = "move"; 189 156 190 157 // get current zoomlevel 191 this. zoomlevel_startScale = this.map.zoom;158 this.map.zoomlevel_startScale = this.map.zoom; 192 159 193 160 // get current tile size (it's the base for scaling) 194 this. tileSize_startScale = this.map.baseLayer.getTileSize();161 this.map.tileSize_startScale = this.map.baseLayer.getTileSize(); 195 162 196 163 // get tile, which contains the center of the viewport 197 this. centerTile = this.map.baseLayer.getCenterTile();164 this.map.centerTile = this.map.baseLayer.getCenterTile(); 198 165 199 166 //set all active overlays temporarily invisible … … 204 171 } 205 172 } 173 174 175 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 176 //this.moveZoomBar((this.map.getNumZoomLevels() -1) - levels); 177 OpenLayers.Event.stop(evt); 178 }, 179 180 /* 181 * @param evt 182 * event listener for clicks on the slider 183 */ 184 zoomBarDown:function(evt) { 185 if (!OpenLayers.Event.isLeftClick(evt)) return; 186 this.map.events.register("mousemove", this, this.passEventToSlider); 187 this.map.events.register("mouseup", this, this.passEventToSlider); 188 this.mouseDragStart = evt.xy.clone(); 189 this.map.zoomStart = evt.xy.clone(); 190 this.div.style.cursor = "move"; 191 192 // get and set some settings for zoom animation 193 this.map.prepareZoomAnimation(); 206 194 207 195 OpenLayers.Event.stop(evt); … … 224 212 } 225 213 this.mouseDragStart = evt.xy.clone(); 226 227 228 // scale baselayer if tileSize and centerTile is set 229 if ( this.tileSize_startScale && this.centerTile ) { 230 231 // determine zoomlevel 232 this.calculateNewZoomlevel(evt); 233 234 // determine tile size and map resolution 235 this.calculateNewTileSize(); 236 237 // scale (center) tile to new scaled size 238 this.map.baseLayer.scaleTileTo(this.centerTile, 239 this.tileSize_scale); 240 241 // scale all tiles to new scaled size (if there 242 // are more than one tile) 243 this.map.baseLayer.scaleTilesOfGrid(this.centerTile, 244 this.tileSize_scale); 245 246 // scale zoomOut tile (to prevent a white frame during zoomOut) 247 this.map.baseLayer.scaleZoomOutTile(this.tileSize_scale, 248 this.zoomlevel_scale, 249 this.resolution_scale); 250 251 // set new scaled map resolution (important for overviewmap) 252 this.map.setScaleResolution(this.resolution_scale); 253 } 254 214 215 // set current slider position 216 var sliderPosition = new OpenLayers.Pixel(evt.xy.x, evt.xy.y); 217 218 // run zoom animation -> scale tile(s) 219 this.map.runZoomAnimation(this.zoomStopHeight, sliderPosition); 220 255 221 OpenLayers.Event.stop(evt); 256 222 } … … 264 230 zoomBarUp:function(evt) { 265 231 if (!OpenLayers.Event.isLeftClick(evt)) return; 266 if (this. zoomStart) {232 if (this.map.zoomStart) { 267 233 this.div.style.cursor="default"; 268 234 this.map.events.unregister("mouseup", this, this.passEventToSlider); 269 235 this.map.events.unregister("mousemove", this, this.passEventToSlider); 270 var deltaY = this.zoomStart.y - evt.xy.y 271 272 // clone layerContainer for "smooth tile update" without blank map 273 this.map.baseLayer.cloneLayerContainer(); 274 236 var deltaY = this.map.zoomStart.y - evt.xy.y 237 275 238 // zoom map to new zoomlevel 276 this.map.zoomTo(this.map.zoom + Math.round(deltaY/this.zoomStopHeight)); 239 var finalZoomlevel = this.map.zoom + Math.round(deltaY/this.zoomStopHeight); 240 241 // finish zoom animation 242 this.map.finishZoomAnimation(finalZoomlevel); 243 277 244 this.moveZoomBar(); 278 245 this.mouseDragStart = null; … … 282 249 283 250 284 /**285 * Calculates new zoomlevel of current zoomslider position.286 *287 */288 calculateNewZoomlevel:function(evt) {289 // convert current sliderposition to new zoomlevel290 var deltaY_zoomlevel = this.zoomStart.y - evt.xy.y;291 this.zoomlevel_scale = this.zoomlevel_startScale +292 deltaY_zoomlevel/this.zoomStopHeight;293 294 // check zoomlevel validity295 if (this.zoomlevel_scale < 0) {296 this.zoomlevel_scale = 0;297 }298 if (this.zoomlevel_scale > (this.map.getNumZoomLevels()-1)) {299 this.zoomlevel_scale = this.map.getNumZoomLevels() - 1;300 }301 },302 303 304 /**305 * Calculates new tile size and map resolution of current zoomlevel.306 *307 */308 calculateNewTileSize:function() {309 // calculate new tile size for...310 // ...zoomIn311 if (this.zoomlevel_startScale < this.zoomlevel_scale) {312 this.tileSize_scale.w = Math.pow(2,(this.zoomlevel_scale -313 this.zoomlevel_startScale)) * this.tileSize_startScale.w;314 this.tileSize_scale.h = Math.pow(2,(this.zoomlevel_scale -315 this.zoomlevel_startScale)) * this.tileSize_startScale.h;316 317 // set new map resolution318 this.resolution_scale = 1/(Math.pow(2,(this.zoomlevel_scale -319 this.zoomlevel_startScale))) * this.map.getResolution();320 }321 // ...zoomOut / no zoom changes322 if (this.zoomlevel_startScale >= this.zoomlevel_scale) {323 this.tileSize_scale.w = 1/(Math.pow(2,(this.zoomlevel_startScale -324 this.zoomlevel_scale))) * this.tileSize_startScale.w;325 this.tileSize_scale.h = 1/(Math.pow(2,(this.zoomlevel_startScale -326 this.zoomlevel_scale))) * this.tileSize_startScale.h;327 328 // set new map resolution329 this.resolution_scale = Math.pow(2,(this.zoomlevel_startScale -330 this.zoomlevel_scale)) * this.map.getResolution();331 }332 },333 251 334 252 335 253 /* 336 254 * Change the location of the slider to match the current zoom level. 255 * 256 * @param {float} zoomlevel 337 257 */ 338 moveZoomBar:function() { 339 var newTop = 340 ((this.map.getNumZoomLevels()-1) - this.map.getZoom()) * 258 moveZoomBar:function(zoomlevel) { 259 // check if zoomlevel is not a number 260 if (isNaN(zoomlevel)) { 261 zoomlevel = this.map.getZoom(); 262 } 263 264 // set new top position 265 var newTop = ((this.map.getNumZoomLevels()-1) - zoomlevel) * 341 266 this.zoomStopHeight + this.startTop + 1; 342 267 this.slider.style.top = newTop + "px"; 343 268 }, 344 269 270 345 271 CLASS_NAME: "OpenLayers.Control.PanZoomBar" 346 272 }); sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js
r2280 r2292 529 529 var center = this.map.getCenter(); 530 530 var res = this.map.getResolution(); 531 532 var delta_x = viewPortPx.x - (size.w / 2);533 var delta_y = viewPortPx.y - (size.h / 2);531 532 var delta_x = viewPortPx.x - Math.ceil((size.w / 2)); 533 var delta_y = viewPortPx.y - Math.ceil((size.h / 2)); 534 534 535 535 lonlat = new OpenLayers.LonLat(center.lon + delta_x * res , … … 546 546 * @type OpenLayers.Pixel 547 547 */ 548 getViewPortPxFromLonLat: function (lonlat ) {548 getViewPortPxFromLonLat: function (lonlat, resolution) { 549 549 var px = null; 550 550 if (lonlat != null) { 551 var resolution = this.map.getResolution(); 551 if (!resolution) 552 resolution = this.map.getResolution(); 552 553 var extent = this.map.getExtent(); 553 554 px = new OpenLayers.Pixel( … … 700 701 // (now the cloned div is above the original; it hides the original) 701 702 this.map.viewPortDiv.appendChild(this.map.layerContainerDivClone); 703 704 this.map.layerContainerDiv.style.display= "none"; 705 702 706 }, 703 707 … … 713 717 // function for map only; not for overviewmap! 714 718 if (this.map.div.id == "map") { 715 // set cloned layerDiv invisibile -> original div is visible716 if (this.map.layerContainerDivClone){717 this.map.layerContainerDivClone.style.display= "none";718 }719 720 719 // set zoomOutTile invisible 721 720 if (this.map.baseLayer.zoomOutTile){ 722 721 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 723 722 } 723 // set cloned layerDiv invisibile -> original div is visible 724 if (this.map.layerContainerDivClone){ 725 this.map.layerContainerDivClone.style.display= "none"; 726 this.map.layerContainerDiv.style.display= "block"; 727 728 } 729 730 724 731 } 725 732 }, … … 750 757 */ 751 758 scaleTileTo:function(tile, newTileSize) { 752 753 759 //convert the center of the map in pixel 754 760 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); … … 855 861 var centerLonLat = extent.getCenterLonLat(); 856 862 857 if( bounds.containsLonLat(centerLonLat)858 && !(extent.equals(maxExtent))) { 863 /* if( bounds.containsLonLat(centerLonLat) 864 && !(extent.equals(maxExtent))) {*/ 859 865 var offsetlon = bounds.left - centerLonLat.lon; 860 866 var offsetlat = -bounds.top + centerLonLat.lat; … … 869 875 870 876 // set zoomOutTile visible if viewport < map bounds 871 if ( (bounds.left < extent.left) || (bounds.right > extent.right) ) 877 /* if ( (bounds.left < extent.left) || (bounds.right > 878 * extent.right) )*/ 872 879 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "block"; 873 else880 /* else 874 881 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 875 } 882 // }*/ 876 883 877 884 return true; sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js
r2280 r2292 547 547 /** 548 548 * Gets tile, which contains the center of the viewport. 549 * 549 * 550 550 * @returns the tile, which contains the center of the viewport 551 551 * @type OpenLayers.Tile 552 552 */ 553 553 getCenterTile:function() { 554 var center = this.map.getCenter(); 555 554 556 if (this.grid) { 555 557 for (var iRow=0; iRow < this.grid.length; iRow++) { 556 558 for (var iCol=0; iCol < this.grid[iRow].length; iCol++) { 557 559 var tileBounds = this.grid[iRow][iCol].bounds; 558 if (tileBounds.containsLonLat( this.map.getCenter(), true)) {560 if (tileBounds.containsLonLat(center, true)) { 559 561 this.centerRow = iRow; 560 562 this.centerCol = iCol; sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js
r2275 r2292 131 131 theme: null, 132 132 133 134 //ANIMATION 135 136 /** @type Boolean */ 137 animated: true, 138 139 /** steps in the slide 140 * 141 * @type int */ 142 slideSteps: 7, 143 144 /** millisecondss between each step 145 * 146 * @type int */ 147 slideWait: 0, 148 149 /** power used to calculate width of slide steps 150 * 151 * @type float*/ 152 slidePower: 0.7, 153 154 /** @type int */ 155 animatedPanningIntervalID: null, 156 157 /** @type int */ 158 animatedZoomingIntervalID: null, 159 160 161 /** @type boolean */ 162 zoomanimationActive: false, 163 133 164 /** @type int */ 134 165 zoomOutTileSizeFactor: 4, 166 167 /** @type int */ 168 zoomlevel_startScale: null, 169 170 /** @type float */ 171 zoomlevel_scale: null, 172 173 /** @type OpenLayers.Size */ 174 tileSize_startScale: null, 175 176 /** @type OpenLayers.Size */ 177 tileSize_scale: null, 178 179 /** @type OpenLayers.Tile */ 180 centerTile: null, 181 182 /** @type float */ 183 resolution_scale: null, 135 184 136 185 /** … … 212 261 'unload', 213 262 this.destroy.bindAsEventListener(this)); 263 264 this.tileSize_scale = new OpenLayers.Size(); 214 265 }, 215 266 … … 711 762 return this.zoom; 712 763 }, 713 764 714 765 /** Allows user to pan by a value of screen pixels 715 766 * 716 767 * @param {int} dx 717 768 * @param {int} dy 718 */ 719 pan: function(dx, dy) { 720 721 // getCenter 722 var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 723 724 // adjust 725 var newCenterPx = centerPx.add(dx, dy); 726 727 // only call setCenter if there has been a change 728 if (!newCenterPx.equals(centerPx)) { 729 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 730 this.setCenter(newCenterLonLat); 731 } 732 733 }, 769 * @param {Boolean} animated 770 */ 771 pan: function(dx, dy, animated) { 772 773 if (animated == null) { 774 animated = this.animated; 775 } 776 777 if (animated) { 778 this.panSlide(dx, dy, 779 this.slideSteps, 780 this.slideWait, 781 this.slidePower); 782 } else { 783 784 // getCenter 785 var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 786 787 // adjust 788 var newCenterPx = centerPx.add(dx, dy); 789 790 // only call setCenter if there has been a change 791 if (!newCenterPx.equals(centerPx)) { 792 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 793 this.setCenter(newCenterLonLat, null, null, this.animated); 794 } 795 } 796 }, 797 734 798 735 799 /** … … 840 904 }, 841 905 906 /** Position changer with Memory by www.hesido.com 907 * modified by dncpax for OpenLayers 908 * 909 * @param {int} slideX 910 * @param {int} slideY 911 * @param {int} totalSteps 912 * @param {int} intervals 913 * @param {float} power 914 */ 915 panSlide: function( slideX, slideY, totalSteps, interval, power) { 916 if (this.animatedPanningIntervalID) { 917 window.clearInterval(this.animatedPanningIntervalID); 918 this.animatedPanningIntervalID = null; 919 } 920 var context = { 921 'map': this, 922 'slideX': slideX, 923 'slideY': slideY, 924 'totalSteps': totalSteps, 925 'step': 0, 926 'power': power 927 }; 928 var move = function() { 929 var dx = OpenLayers.Util.easeInOut(this.slideX, 930 this.totalSteps, 931 this.step, 932 this.power); 933 var dy = OpenLayers.Util.easeInOut(this.slideY, 934 this.totalSteps, 935 this.step, 936 this.power); 937 this.map.pan(dx, dy, false); 938 this.step++; 939 if (this.step > this.totalSteps) { 940 window.clearInterval(this.map.animatedPanningIntervalID); 941 this.map.animatedPanningIntervalID = null; 942 } 943 }; 944 945 this.animatedPanningIntervalID = 946 window.setInterval(move.bindAsEventListener(context), 947 interval); 948 }, 949 950 /** Position changer with Memory by www.hesido.com 951 * modified by dncpax for OpenLayers 952 * 953 * @param {int} slideZoom 954 * @param {int} totalSteps 955 * @param {int} intervals 956 * @param {float} power 957 */ 958 zoomSlide: function( slideZoom, totalSteps, interval, power) { 959 if (this.animatedZoomingIntervalID) { 960 window.clearInterval(this.animatedZoomingIntervalID); 961 this.animatedZoomingIntervalID = null; 962 } 963 var context = { 964 'map': this, 965 'slideZoom': slideZoom, 966 'totalSteps': totalSteps, 967 'step': 0, 968 'power': power 969 }; 970 var move = function() { 971 var delta = this.slideZoom - this.map.zoom; 972 var dZoom = OpenLayers.Util.easeInOutZoom(delta, 973 this.totalSteps, 974 this.step, 975 this.power); 976 977 this.map.zoomTo(this.map.zoom + dZoom, false, this.step); 978 this.step++; 979 if (this.step > this.totalSteps) { 980 window.clearInterval(this.map.animatedZoomingIntervalID); 981 this.map.animatedZoomingIntervalID = null; 982 } 983 }; 984 985 this.animatedZoomingIntervalID = 986 window.setInterval(move.bindAsEventListener(context), 987 interval); 988 }, 989 842 990 /** 843 991 * @private … … 1044 1192 /** Zoom to a specific zoom level 1045 1193 * 1194 * @param {float} zoom 1195 * @param {Boolean} animated 1196 * @param {int} step 1197 * 1198 */ 1199 zoomTo: function(zoom, animated, step) { 1200 if (this.isValidZoomLevel(zoom)) { 1201 if (animated == null) { 1202 animated = this.animated; 1203 } 1204 1205 if (animated) { 1206 this.zoomSlide(zoom, 1207 this.slideSteps, 1208 this.slideWait, 1209 this.slidePower); 1210 1211 // prepare zoom animation 1212 this.prepareZoomAnimation(); 1213 } else { 1214 1215 if (step <= this.slideSteps ) { 1216 1217 // set new zoomlevel from zoomSlide function 1218 this.zoomlevel_scale = zoom; 1219 1220 // run zoom animation -> scale tile(s)
