Ticket #110: animatedPanning#2.patch
| File animatedPanning#2.patch, 13.1 kB (added by emanuel, 2 years ago) |
|---|
-
tests/test_Util.html
old new 563 563 564 564 565 565 } 566 function test_ Util_createUniqueIDSeq(t) {566 function test_16_Util_createUniqueIDSeq(t) { 567 567 t.plan(1); 568 568 OpenLayers.Util.lastSeqID = 0; 569 569 OpenLayers.Util.createDiv(); 570 570 OpenLayers.Util.createDiv(); 571 571 t.eq(OpenLayers.Util.createDiv().id, "OpenLayersDiv3", "Div created is sequential, starting at lastSeqID in Util."); 572 572 } 573 574 function test_17_Util_easeInOutPan(t) { 575 t.plan(1); 576 var delta = 5; 577 var totalSteps = 4; 578 var step = 1; 579 var power = 1; 580 var value = OpenLayers.Util.easeInOutPan(delta,totalSteps,step,power); 581 t.eq( value, 2, "calculation correct"); 582 } 583 584 585 586 587 588 589 590 591 592 593 594 595 596 573 597 // --> 574 598 </script> 575 599 </head> -
tests/test_Map.html
old new 316 316 t.ok(map.getCenter().equals(new OpenLayers.LonLat(0,0)), "safely sets out-of-bounds lonlat"); 317 317 } 318 318 319 319 /** animated panning **/ 320 function test_08_Map_pan(t) { 321 t.plan(2); 322 323 map = new OpenLayers.Map('map'); 324 var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 325 "http://octo.metacarta.com/cgi-bin/mapserv?", 326 {map: "/mapdata/vmap_wms.map", layers: "basic"}, 327 {maxResolution: 'auto', maxExtent: new OpenLayers.Bounds(-10,-10,10,10)}); 328 map.addLayer(baseLayer); 329 var ll = new OpenLayers.LonLat(0,0); 330 map.setCenter(ll, 0); 331 332 map.pan(0,3); 333 t.delay_call( 334 1, function() { 335 var newCent = new OpenLayers.LonLat(0,-0.1); 336 t.ok( map.getCenter().equals(newCent), 337 "map center is correct after panning with animation"); 338 339 map.pan(0,-3, false); 340 newCent = new OpenLayers.LonLat(0,0); 341 t.ok( map.getCenter().equals(newCent), 342 "map center is correct after panning without animation"); 343 } 344 ); 345 } 346 347 320 348 function test_01_Map_defaultTheme(t) { 321 349 t.plan(5); 322 350 -
tests/Control/test_Permalink.html
old new 20 20 if (!map.getCenter()) map.zoomToMaxExtent(); 21 21 map.addControl(control); 22 22 map.pan(5, 0); 23 if (/MSIE/.test(navigator.userAgent)) { 24 t.eq(OpenLayers.Util.getElement('permalink').href, "?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink"); 25 } else { 26 t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=1.75781&zoom=2&layers=B", "Panning sets permalink"); 27 } 23 t.delay_call( 1, function() { 24 if (/MSIE/.test(navigator.userAgent)) { 25 t.eq(OpenLayers.Util.getElement('permalink').href, "?lat=0&lon=7.03125&zoom=2&layers=B", "Panning sets permalink"); 26 } else { 27 t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=7.03125&zoom=2&layers=B", "Panning sets permalink"); 28 } 29 }); 28 30 } 29 31 function test_03_Control_Permalink_updateLinksBase (t) { 30 32 t.plan( 2 ); … … 37 39 if (!map.getCenter()) map.zoomToMaxExtent(); 38 40 map.addControl(control); 39 41 map.pan(5, 0); 40 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=1.75781&zoom=2&layers=B'; 41 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base"); 42 t.delay_call( 1, function() { 43 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=7.03125&zoom=2&layers=B'; 44 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base"); 45 }); 42 46 } 43 47 function test_04_Control_Permalink_noElement (t) { 44 48 t.plan( 2 ); -
tests/Control/test_PanZoom.html
old new 42 42 map.setCenter(centerLL, 5); 43 43 44 44 control.buttons[0].onmousedown(evt); 45 t.ok( map.getCenter().lat > centerLL.lat, "Pan up works correctly" ); 45 t.delay_call( 46 1, function() { 47 t.ok( map.getCenter().lat > centerLL.lat, "Pan up works correctly" ); 48 control.buttons[1].onmousedown(evt); 49 }, 50 51 1, function() { 52 t.ok( map.getCenter().lon < centerLL.lon, "Pan left works correctly" ); 53 control.buttons[2].onmousedown(evt); 54 }, 55 56 1, function() { 57 t.ok( map.getCenter().lon == centerLL.lon, "Pan right works correctly" ); 58 control.buttons[3].onmousedown(evt); 59 }, 60 61 1, function() { 62 t.ok( map.getCenter().lat == centerLL.lat, "Pan down works correctly" ); 63 control.buttons[4].onmousedown(evt); 64 65 t.eq( map.getZoom(), 6, "zoomin works correctly" ); 46 66 47 control.buttons[1].onmousedown(evt);48 t.ok( map.getCenter().lon < centerLL.lon, "Pan left works correctly" );67 control.buttons[6].onmousedown(evt); 68 t.eq( map.getZoom(), 5, "zoomout works correctly" ); 49 69 50 control.buttons[2].onmousedown(evt); 51 t.ok( map.getCenter().lon == centerLL.lon, "Pan right works correctly" ); 70 control.buttons[5].onmousedown(evt); 71 t.eq( map.getZoom(), 2, "zoomworld works correctly" ); 72 } 73 ); 52 74 53 control.buttons[3].onmousedown(evt);54 t.ok( map.getCenter().lat == centerLL.lat, "Pan down works correctly" );55 56 control.buttons[4].onmousedown(evt);57 t.eq( map.getZoom(), 6, "zoomin works correctly" );58 59 control.buttons[6].onmousedown(evt);60 t.eq( map.getZoom(), 5, "zoomout works correctly" );61 62 control.buttons[5].onmousedown(evt);63 t.eq( map.getZoom(), 2, "zoomworld works correctly" );64 65 75 } 66 76 // --> 67 77 </script> -
lib/OpenLayers/Control/PanZoom.js
old new 15 15 OpenLayers.Class.inherit( OpenLayers.Control, { 16 16 17 17 /** @type int */ 18 slideFactor: 50,18 slideFactor: 75, 19 19 20 20 /** @type Array of Button Divs */ 21 21 buttons: null, … … 114 114 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": 129 129 this.map.zoomIn(); -
lib/OpenLayers/Layer.js
old new 529 529 var size = this.map.getSize(); 530 530 var center = this.map.getCenter(); 531 531 var res = this.map.getResolution(); 532 533 var delta_x = viewPortPx.x - (size.w / 2);534 var delta_y = viewPortPx.y - (size.h / 2);532 533 var delta_x = viewPortPx.x - Math.ceil(size.w / 2); 534 var delta_y = viewPortPx.y - Math.ceil(size.h / 2); 535 535 536 536 lonlat = new OpenLayers.LonLat(center.lon + delta_x * res , 537 537 center.lat - delta_y * res); -
lib/OpenLayers/Map.js
old new 136 136 /** @type string */ 137 137 theme: null, 138 138 139 140 //ANIMATION 141 142 /** @type Boolean */ 143 animated: true, 144 145 /** steps in the slide 146 * 147 * @type int */ 148 slideSteps: 4, 149 150 /** millisecondss between each step 151 * 152 * @type int */ 153 slideWait: 1, 154 155 /** power used to calculate width of slide steps 156 * 157 * @type float*/ 158 slidePower: 0.7, 159 160 /** @type int */ 161 animatedPanningIntervalID: null, 162 139 163 /** Should OpenLayers allow events on the map to fall through to other 140 164 * elements on the page, or should it swallow them? (#457) 141 165 * … … 749 773 * @param {int} dx 750 774 * @param {int} dy 751 775 */ 752 pan: function(dx, dy) { 776 pan: function(dx, dy, animated) { 777 if (animated == null) { 778 animated = this.animated; 779 } 780 781 if (animated) { 782 this.panSlide(dx, dy, 783 this.slideSteps, 784 this.slideWait, 785 this.slidePower); 786 } else { 753 787 754 // getCenter755 var centerPx = this.getViewPortPxFromLonLat(this.getCenter());788 // getCenter 789 var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 756 790 757 // adjust 758 var newCenterPx = centerPx.add(dx, dy); 759 760 // only call setCenter if there has been a change 761 if (!newCenterPx.equals(centerPx)) { 762 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 763 this.setCenter(newCenterLonLat); 791 // adjust 792 var newCenterPx = centerPx.add(dx, dy); 793 794 // only call setCenter if there has been a change 795 if (!newCenterPx.equals(centerPx)) { 796 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 797 this.setCenter(newCenterLonLat); 798 } 764 799 } 765 766 800 }, 767 801 768 802 /** … … 871 905 this.layerContainerDiv.style.top = (originPx.y - newPx.y) + "px"; 872 906 } 873 907 }, 908 /** Position changer with Memory by www.hesido.com 909 * modified by dncpax for OpenLayers 910 * 911 * @param {int} slideX 912 * @param {int} slideY 913 * @param {int} totalSteps 914 * @param {int} intervals 915 * @param {float} power 916 */ 917 panSlide: function( slideX, slideY, totalSteps, interval, power) { 918 if (this.animatedPanningIntervalID) { 919 window.clearInterval(this.animatedPanningIntervalID); 920 this.animatedPanningIntervalID = null; 921 } 922 var context = { 923 'map': this, 924 'slideX': slideX, 925 'slideY': slideY, 926 'totalSteps': totalSteps, 927 'step': 0, 928 'power': power 929 }; 930 var move = function() { 931 var dx = OpenLayers.Util.easeInOutPan(this.slideX, 932 this.totalSteps, 933 this.step, 934 this.power); 935 var dy = OpenLayers.Util.easeInOutPan(this.slideY, 936 this.totalSteps, 937 this.step, 938 this.power); 939 this.map.pan(dx, dy, false); 940 this.step++; 941 if (this.step > this.totalSteps) { 942 window.clearInterval(this.map.animatedPanningIntervalID); 943 this.map.animatedPanningIntervalID = null; 944 } 945 }; 874 946 947 this.animatedPanningIntervalID = 948 window.setInterval(move.bindAsEventListener(context), 949 interval); 950 }, 951 875 952 /** 876 953 * @private 877 954 * -
lib/OpenLayers/Util.js
old new 965 965 } 966 966 return head; 967 967 }; 968 969 970 /** Generic Animation Step Value Generator By www.hesido.com, slightly modified 971 * 972 * 973 * @param {int} delta 974 * @param {int} totalSteps 975 * @param {int} step 976 * @param {float} power 977 * 978 * @returns The delta to the next position in the pan animation movement 979 * @type int 980 */ 981 OpenLayers.Util.easeInOutPan = function(delta, totalSteps, step, power) { 982 var prevStepVal = Math.pow(((1/totalSteps)*(step-1)),power) * delta; 983 var stepVal = Math.pow(((1/totalSteps)*step),power) * delta; 984 return Math.ceil(stepVal) - Math.ceil(prevStepVal); 985 }; 986
