Ticket #110: animated_panning.patch
| File animated_panning.patch, 17.4 kB (added by crschmidt, 1 year ago) |
|---|
-
tests/test_Map.html
old new 681 681 map.zoomToMaxExtent(); 682 682 map.setBaseLayer(tmsLayer); 683 683 map.zoomIn(); 684 map.pan(0, -200 );684 map.pan(0, -200, {immediate:true}); 685 685 map.setBaseLayer(wmsLayer); 686 686 t.eq(map.layerContainerDiv.style.top, "0px", "layerContainer is recentered after setBaseLayer"); 687 687 } -
tests/Control/test_Permalink.html
old new 38 38 layer.setVisibility(true); 39 39 if (!map.getCenter()) map.zoomToMaxExtent(); 40 40 map.addControl(control); 41 map.pan(5, 0 );41 map.pan(5, 0, {immediate:true}); 42 42 t.ok(OpenLayers.Util.isEquivalentUrl(OpenLayers.Util.getElement('permalink').href, location+"?zoom=2&lat=0&lon=1.75781&layers=BT"), 'pan sets permalink'); 43 43 44 44 map.layers[1].setVisibility(false); … … 55 55 map.addLayer(layer); 56 56 if (!map.getCenter()) map.zoomToMaxExtent(); 57 57 map.addControl(control); 58 map.pan(5, 0 );58 map.pan(5, 0, {immediate:true}); 59 59 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; 60 60 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base"); 61 61 } … … 76 76 map.addLayer(layer); 77 77 if (!map.getCenter()) map.zoomToMaxExtent(); 78 78 map.addControl(control); 79 map.pan(5, 0 );79 map.pan(5, 0, {immediate:true}); 80 80 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?foo=bar&zoom=2&lat=0&lon=1.75781&layers=B'; 81 81 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring"); 82 82 83 83 control = new OpenLayers.Control.Permalink('permalink', "./edit.html?foo=bar&" ); 84 84 map.addControl(control); 85 map.pan(0, 0 );85 map.pan(0, 0, {immediate:true}); 86 86 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '&'"); 87 87 88 88 control = new OpenLayers.Control.Permalink('permalink', "./edit.html?" ); 89 89 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; 90 90 map.addControl(control); 91 map.pan(5, 0 );92 map.pan(-5, 0 );91 map.pan(5, 0, {immediate:true}); 92 map.pan(-5, 0, {immediate:true}); 93 93 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base and querystring ending with '?'"); 94 94 95 95 } … … 104 104 map.addLayer(layer); 105 105 if (!map.getCenter()) map.zoomToMaxExtent(); 106 106 map.addControl(control); 107 map.pan(5, 0 );107 map.pan(5, 0, {immediate:true}); 108 108 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?zoom=2&lat=0&lon=1.75781&layers=B'; 109 109 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with existing zoom in base"); 110 110 } -
tests/Control/test_PanZoom.html
old new 61 61 wnd.mapper.events.register("dblclick", mapper, setFlag); 62 62 63 63 simulateClick(wnd, wnd.control.buttons[0]); 64 t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" ); 65 t.ok(!flag.mousedown, "mousedown does not get to the map"); 66 t.ok(flag.mouseup, "mouseup does get to the map"); 67 t.ok(!flag.click, "click does not get to the map"); 68 t.ok(!flag.dblclick, "dblclick does not get to the map"); 69 resetFlags(); 64 t.delay_call(2, function() { 65 t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" ); 66 t.ok(!flag.mousedown, "mousedown does not get to the map"); 67 t.ok(flag.mouseup, "mouseup does get to the map"); 68 t.ok(!flag.click, "click does not get to the map"); 69 t.ok(!flag.dblclick, "dblclick does not get to the map"); 70 resetFlags(); 70 71 71 simulateClick(wnd, wnd.control.buttons[1]); 72 simulateClick(wnd, wnd.control.buttons[1]); 73 }, 2, function() { 72 74 t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" ); 73 75 t.ok(!flag.mousedown, "mousedown does not get to the map"); 74 76 t.ok(flag.mouseup, "mouseup does get to the map"); … … 77 79 resetFlags(); 78 80 79 81 simulateClick(wnd, wnd.control.buttons[2]); 82 }, 2, function() { 80 83 t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" ); 81 84 t.ok(!flag.mousedown, "mousedown does not get to the map"); 82 85 t.ok(flag.mouseup, "mouseup does get to the map"); … … 85 88 resetFlags(); 86 89 87 90 simulateClick(wnd, wnd.control.buttons[3]); 91 }, 2, function() { 88 92 t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" ); 89 93 t.ok(!flag.mousedown, "mousedown does not get to the map"); 90 94 t.ok(flag.mouseup, "mouseup does get to the map"); … … 93 97 resetFlags(); 94 98 95 99 simulateClick(wnd, wnd.control.buttons[4]); 100 }, 2, function() { 96 101 t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" ); 97 102 t.ok(!flag.mousedown, "mousedown does not get to the map"); 98 103 t.ok(flag.mouseup, "mouseup does get to the map"); … … 101 106 resetFlags(); 102 107 103 108 simulateClick(wnd, wnd.control.buttons[6]); 109 }, 2, function() { 104 110 t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" ); 105 111 t.ok(!flag.mousedown, "mousedown does not get to the map"); 106 112 t.ok(flag.mouseup, "mouseup does get to the map"); … … 109 115 resetFlags(); 110 116 111 117 simulateClick(wnd, wnd.control.buttons[5]); 118 }, 2, function() { 112 119 t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" ); 113 120 t.ok(!flag.mousedown, "mousedown does not get to the map"); 114 121 t.ok(flag.mouseup, "mouseup does get to the map"); 115 122 t.ok(!flag.click, "click does not get to the map"); 116 123 t.ok(!flag.dblclick, "dblclick does not get to the map"); 117 124 resetFlags(); 118 125 }); 119 126 }); 120 127 }); 121 128 } … … 146 153 147 154 148 155 var layer = new OpenLayers.Layer.WMS("Test Layer", 149 "http:// octo.metacarta.com/cgi-bin/mapserv?",150 { map: "/mapdata/vmap_wms.map",layers: "basic"});156 "http://labs.metacarta.com/wms-c/Basic.py?", 157 {layers: "basic"}); 151 158 mapper.addLayer(layer); 152 159 153 160 centerLL = new OpenLayers.LonLat(0,0); -
tests/Control/test_OverviewMap.html
old new 38 38 39 39 var centerLL = new OpenLayers.LonLat(-71,42); 40 40 map.setCenter(centerLL, 11); 41 41 t.delay_call(1, function() { 42 42 var overviewCenter = control.ovmap.getCenter(); 43 43 var overviewZoom = control.ovmap.getZoom(); 44 44 t.eq(overviewCenter.lon, -71, "Overviewmap center lon correct"); … … 46 46 t.eq(overviewZoom, 8, "Overviewmap zoomcorrect"); 47 47 48 48 control.mapDivClick({'xy':new OpenLayers.Pixel(5,5)}); 49 49 }, 2, function() { 50 50 var cent = map.getCenter(); 51 51 t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon"); 52 52 t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); … … 57 57 }; 58 58 control.rectDrag(new OpenLayers.Pixel(15, 15)); 59 59 control.updateMapToRect(); 60 60 }, 2, function() { 61 61 var cent = map.getCenter(); 62 62 t.eq(cent.lon, -71.2734375, "Dragging on the Overview Map has the correct effect on map lon"); 63 63 t.eq(cent.lat, 42.09765625, "Dragging on the Overview Map has the correct effect on map lat"); … … 68 68 t.eq(overviewCenter.lon, 0, "Overviewmap center lon correct -- second zoom"); 69 69 t.eq(overviewCenter.lat, 0, "Overviewmap center lat correct -- second zoom"); 70 70 t.eq(overviewZoom, 0, "Overviewmap zoomcorrect -- second zoom"); 71 72 71 map.destroy(); 73 72 }); 74 73 } 75 74 76 75 </script> -
tests/Layer/test_Grid.html
old new 542 542 map.zoomIn(); 543 543 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 544 544 t.eq(bounds.toBBOX(), "-180,-90,0,90", "get tile bounds returns correct bounds"); 545 map.pan(200,0 );545 map.pan(200,0, {immediate:true}); 546 546 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 547 547 t.eq(bounds.toBBOX(), "0,-90,180,90", "get tile bounds returns correct bounds after pan"); 548 548 } -
tests/Layer/test_KaMap.html
old new 245 245 map.zoomIn(); 246 246 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 247 247 t.eq(bounds.toBBOX(), "-180,0,0,180", "get tile bounds returns correct bounds"); 248 map.pan(200,0 );248 map.pan(200,0,{immediate:true}); 249 249 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 250 250 t.eq(bounds.toBBOX(), "0,0,180,180", "get tile bounds returns correct bounds after pan"); 251 251 map.destroy(); -
lib/OpenLayers/Map.js
old new 1229 1229 * Parameters: 1230 1230 * dx - {Integer} 1231 1231 * dy - {Integer} 1232 * options - {Object} Only one at this time: "immediate", does not use 1233 * panTo, but uses setCenter instead. 1232 1234 */ 1233 pan: function(dx, dy) { 1234 1235 pan: function(dx, dy, options) { 1236 1237 if (!options) { 1238 options = {} 1239 } 1235 1240 // getCenter 1236 1241 var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 1237 1242 … … 1241 1246 // only call setCenter if there has been a change 1242 1247 if (!newCenterPx.equals(centerPx)) { 1243 1248 var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 1244 this.setCenter(newCenterLonLat); 1249 if (options.immediate) { 1250 this.setCenter(newCenterLonLat); 1251 } else { 1252 this.panTo(newCenterLonLat); 1253 } 1245 1254 } 1246 1255 1247 1256 }, 1257 1258 /** 1259 * APIMethod: panTo 1260 * Allows user to pan to a new lonlat 1261 * If the new lonlat is in the current extent the map will slide smoothly 1262 * 1263 * Parameters: 1264 * lonlat - {<OpenLayers.Lonlat>} 1265 */ 1266 panTo: function(lonlat) { 1267 if (this.getExtent().containsLonLat(lonlat)) { 1268 if (!this.panTween) { 1269 this.panTween = new OpenLayers.Tween(OpenLayers.Easing.Expo.easeOut); 1270 } 1271 var center = this.getCenter(); 1272 var from = { 1273 lon: center.lon, 1274 lat: center.lat 1275 }; 1276 var to = { 1277 lon: lonlat.lon, 1278 lat: lonlat.lat 1279 }; 1280 this.panTween.start(from, to, 50, { 1281 callbacks: { 1282 start: OpenLayers.Function.bind(function(lonlat) { 1283 this.events.triggerEvent("movestart"); 1284 }, this), 1285 eachStep: OpenLayers.Function.bind(function(lonlat) { 1286 var lonlat = new OpenLayers.LonLat(lonlat.lon, lonlat.lat); 1287 this.moveTo(lonlat, this.zoom, true); 1288 }, this), 1289 done: OpenLayers.Function.bind(function(lonlat) { 1290 this.events.triggerEvent("moveend"); 1291 }, this) 1292 } 1293 }); 1294 } else { 1295 this.setCenter(lonlat); 1296 } 1297 }, 1248 1298 1249 1299 /** 1250 1300 * APIMethod: setCenter … … 1285 1335 var forceZoomChange = options.forceZoomChange; 1286 1336 // noEvent is false by default 1287 1337 var noEvent = options.noEvent; 1338 1339 if (this.panTween && options.caller == "setCenter") { 1340 this.panTween.stop(); 1341 } 1288 1342 1289 1343 if (!this.center && !this.isValidLonLat(lonlat)) { 1290 1344 lonlat = this.maxExtent.getCenterLonLat(); -
lib/OpenLayers/Control/OverviewMap.js
old new 511 511 */ 512 512 updateMapToRect: function() { 513 513 var lonLatBounds = this.getMapBoundsFromRectBounds(this.rectPxBounds); 514 this.map. setCenter(lonLatBounds.getCenterLonLat(), this.map.zoom);514 this.map.panTo(lonLatBounds.getCenterLonLat()); 515 515 }, 516 516 517 517 /** -
examples/animated_panning.html
old new 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Animated Panning of the Map via map.panTo</title> 4 <style type="text/css"> 5 #map { 6 width: 512px; 7 height: 256px; 8 border: 1px solid black; 9 } 10 </style> 11 <script src="../lib/OpenLayers.js"></script> 12 <script type="text/javascript"> 13 var map, layer, running = false; 14 15 OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { 16 defaultHandlerOptions: { 17 'single': true, 18 'delay': 200 19 }, 20 21 initialize: function(options) { 22 this.handlerOptions = OpenLayers.Util.extend( 23 {}, this.defaultHandlerOptions 24 ); 25 OpenLayers.Control.prototype.initialize.apply( 26 this, arguments 27 ); 28 this.handler = new OpenLayers.Handler.Click( 29 this, { 30 'click': this.onClick 31 }, this.handlerOptions 32 ); 33 }, 34 35 onClick: function(evt) { 36 map.panTo(map.getLonLatFromPixel(evt.xy)); 37 } 38 39 }); 40 41 function init(){ 42 map = new OpenLayers.Map('map'); 43 layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", 44 "http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} ); 45 46 map.addLayer(layer); 47 map.zoomToMaxExtent(); 48 var click = new OpenLayers.Control.Click(); 49 map.addControl(click); 50 click.activate(); 51 map.addControl(new OpenLayers.Control.OverviewMap()); 52 } 53 54 function setCenterInterval() { 55 if (!running) { 56 setCenter(); 57 running = setInterval('setCenter()', 500); 58 } else { 59 clearInterval(running); 60 running = false; 61 } 62 } 63 64 function setCenter() { 65 var lon = Math.random() * 360 - 180; 66 var lat = Math.random() * 180 - 90; 67 var lonlat = new OpenLayers.LonLat(lon, lat); 68 map.panTo(lonlat); 69 } 70 </script> 71 </head> 72 <body onload="init()"> 73 <h1 id="title">map.panTo Example</h1> 74 <div id="tags">map.panTo</div> 75 <div id="shortdesc">Show animated panning effects in the map</div> 76 <div id="map"></div> 77 <div id="docs"> 78 This is an example of transition effects. If the new random center is in the current extent, the map will pan smoothly. <br /> 79 The random selection will continue until you press it again. Additionally, you can single click in the map to pan smoothly 80 to that area, or use the pan control to pan smoothly. 81 82 </div> 83 <button onclick="setCenterInterval()">Start/stop random recenter</button> 84 </body> 85 </html>
