Ticket #442: final_animatedZooming_Core.patch
| File final_animatedZooming_Core.patch, 65.9 kB (added by emanuel, 3 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 575 576 function test_18_Util_easeInOutZoom(t) { 577 t.plan(1); 578 579 var delta = 5; 580 var totalSteps = 4; 581 var step = 1; 582 var power = 1; 583 var value = OpenLayers.Util.easeInOutZoom(delta,totalSteps,step,power); 584 t.eq( value, 1.25, "calculation correct"); 585 } 586 573 587 // --> 574 588 </script> 575 589 </head> -
tests/test_Map.html
old new 69 69 t.eq( map.theme, 'foo', "map theme set correctly." ); 70 70 } 71 71 function test_05_Map_center(t) { 72 t.plan( 4);72 t.plan(6); 73 73 map = new OpenLayers.Map('map'); 74 74 var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 75 75 "http://octo.metacarta.com/cgi-bin/mapserv?", … … 78 78 var ll = new OpenLayers.LonLat(2,1); 79 79 map.setCenter(ll, 0); 80 80 map.zoomIn(); 81 t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in"); 82 t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter, zoom in"); 83 map.zoomOut(); 84 t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out"); 81 t.delay_call( 82 1, function() { 83 t.eq( map.getZoom(), 1, "map.zoom is correct after calling setCenter,zoom in"); 84 t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter, zoom in"); 85 // set zoomanimation flag manually, 86 // reason: loadend event in layers.js will not achieved in unittests 87 map.zoomanimationActive = false; 88 map.zoomOut(); 89 }, 90 91 1, function() { 92 t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter,zoom in, zoom out"); 93 map.zoomTo(5); 94 }, 95 96 1, function() { 97 t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" ); 98 map.zoomToMaxExtent(); 99 }, 85 100 86 map.zoomTo(5); 87 t.eq( map.getZoom(), 5, "map.zoom is correct after calling zoomTo" ); 88 /** 89 map.zoomToMaxExtent(); 90 t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToMaxExtent" ); 91 var lonlat = map.getCenter(); 92 var zero = new OpenLayers.LonLat(0, 0); 93 t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" ); 94 95 */ 101 1, function() { 102 t.eq( map.getZoom(), 2, "map.zoom is correct after calling zoomToMaxExtent" ); 103 var lonlat = map.getCenter(); 104 var zero = new OpenLayers.LonLat(0, 0); 105 t.ok( lonlat.equals(zero), "map center is correct after calling zoomToFullExtent" ); 106 } 107 ); 96 108 } 97 109 98 110 function test_06_Map_zoomend_event (t) { … … 108 120 }); 109 121 map.setCenter(new OpenLayers.LonLat(2, 1), 0); 110 122 map.zoomIn(); 111 map.zoomOut(); 123 124 t.delay_call( 1, function() { 125 // set zoomanimation flag manually, 126 // reason: loadend event in layers.js will not achieved in unittests 127 map.zoomanimationActive = false; 128 map.zoomOut(); 129 }); 112 130 } 113 131 114 132 function test_07_Map_add_remove_popup (t) { -
tests/Control/test_Permalink.html
old new 17 17 map = new OpenLayers.Map('map'); 18 18 layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); 19 19 map.addLayer(layer); 20 if (!map.getCenter()) map. zoomToMaxExtent();20 if (!map.getCenter()) map.setCenter(0,0); 21 21 map.addControl(control); 22 22 map.pan(5, 0); 23 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");24 t.eq(OpenLayers.Util.getElement('permalink').href, "?lat=0&lon=7.03125&zoom=0&layers=B", "Panning sets permalink"); 25 25 } else { 26 t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon= 1.75781&zoom=2&layers=B", "Panning sets permalink");26 t.eq(OpenLayers.Util.getElement('permalink').href, location+"?lat=0&lon=7.03125&zoom=0&layers=B", "Panning sets permalink"); 27 27 } 28 28 } 29 29 function test_03_Control_Permalink_updateLinksBase (t) { … … 37 37 if (!map.getCenter()) map.zoomToMaxExtent(); 38 38 map.addControl(control); 39 39 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"); 40 t.delay_call( 1, function() { 41 OpenLayers.Util.getElement('edit_permalink').href = './edit.html?lat=0&lon=7.03125&zoom=2&layers=B'; 42 t.eq(OpenLayers.Util.getElement('permalink').href, OpenLayers.Util.getElement('edit_permalink').href, "Panning sets permalink with base"); 43 }); 42 44 } 43 45 function test_04_Control_Permalink_noElement (t) { 44 46 t.plan( 2 ); -
tests/Control/test_PanZoom.html
old new 54 54 t.ok( map.getCenter().lat == centerLL.lat, "Pan down works correctly" ); 55 55 56 56 control.buttons[4].onmousedown(evt); 57 t.eq( map.getZoom(), 6, "zoomin works correctly" ); 57 t.delay_call( 58 1, function() { 59 t.eq( map.getZoom(), 6, "zoomin works correctly" ); 60 // set zoomanimation flag manually, 61 // reason: loadend event in layers.js will not achieved in unittests 62 map.zoomanimationActive = false; 63 control.buttons[6].onmousedown(evt); 64 }, 65 66 1, function() { 67 t.eq( map.getZoom(), 5, "zoomout works correctly" ); 68 control.buttons[5].onmousedown(evt); 69 }, 70 71 1, function() { 72 t.eq( map.getZoom(), 2, "zoomworld works correctly" ); 73 } 74 ); 58 75 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 76 } 66 77 // --> 67 78 </script> -
tests/Control/test_Scale.html
old new 18 18 layer = new OpenLayers.Layer.WMS('Test Layer', "http://octo.metacarta.com/cgi-bin/mapserv", {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'}); 19 19 map.addLayer(layer); 20 20 map.zoomTo(0); 21 map.addControl(control); 22 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 443M", "Scale set by default." ); 23 map.zoomIn(); 24 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 221M", "Zooming in changes scale" ); 25 map.baseLayer.resolutions = [OpenLayers.Util.getResolutionFromScale(110)]; 26 map.zoomTo(0); 27 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 110", "Scale of 100 isn't rounded" ); 21 t.delay_call( 22 1, function() { 23 map.addControl(control); 24 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 443M", "Scale set by default." ); 25 // set zoomanimation flag manually, 26 // reason: loadend event in layers.js will not achieved in unittests 27 map.zoomanimationActive = false; 28 map.zoomIn(); 29 }, 30 1, function() { 31 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 221M", "Zooming in changes scale" ); 32 33 // set zoomanimation flag manually, 34 // reason: loadend event in layers.js will not achieved in unittests 35 map.zoomanimationActive = false; 36 map.baseLayer.resolutions = [OpenLayers.Util.getResolutionFromScale(110)]; 37 map.zoomTo(0,false); 38 }, 39 1, function() { 40 t.eq(OpenLayers.Util.getElement('scale').innerHTML, "Scale = 1 : 110", "Scale of 100 isn't rounded" ); 41 } 42 ); 28 43 } 29 44 function test_03_Control_Scale_internalScale (t) { 30 45 t.plan(2); -
tests/test_Marker.html
old new 3 3 <script src="../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"><!-- 5 5 var marker; 6 6 var layer; 7 7 8 function test_01_Marker_constructor (t) { 8 9 t.plan( 4 ); 9 10 var ll = new OpenLayers.LonLat(2,1); … … 28 29 map.addLayer(mlayer); 29 30 30 31 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 32 t.delay_call( 1, function() { 33 //onscreen marker 34 var ll = new OpenLayers.LonLat(0,0); 35 var marker = new OpenLayers.Marker(ll); 36 mlayer.addMarker(marker); 37 38 t.ok( marker.onScreen(), "marker knows it's onscreen" ); 31 39 32 //onscreen marker 33 var ll = new OpenLayers.LonLat(0,0); 34 var marker = new OpenLayers.Marker(ll); 35 mlayer.addMarker(marker); 36 37 t.ok( marker.onScreen(), "marker knows it's onscreen" ); 40 //offscreen marker 41 var ll = new OpenLayers.LonLat(100,100); 42 var marker2 = new OpenLayers.Marker(ll); 43 mlayer.addMarker(marker2); 38 44 39 //offscreen marker 40 var ll = new OpenLayers.LonLat(100,100); 41 var marker2 = new OpenLayers.Marker(ll); 42 mlayer.addMarker(marker2); 43 44 t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); 45 map.destroy(); 45 t.ok( !marker2.onScreen(), "marker knows it's offscreen" ); 46 }); 46 47 } 47 48 48 49 function test_03_Marker_setOpacity(t) { … … 70 71 marker.setOpacity(0.5); 71 72 72 73 t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works"); 73 map.destroy();74 74 } 75 75 function test_04_Marker_moveTo(t) { 76 76 t.plan( 6 ); … … 102 102 marker.moveTo(new OpenLayers.Pixel(0,0)); 103 103 t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map"); 104 104 t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map"); 105 map.destroy();106 107 105 } 108 106 109 107 // --> -
tests/test_Feature.html
old new 92 92 93 93 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); 94 94 95 //onscreen feature 96 var feature1 = new OpenLayers.Feature(layer, 97 new OpenLayers.LonLat(0,0)); 98 t.ok( feature1.onScreen(), "feature knows it's onscreen" ); 99 100 //onscreen feature 101 var feature2 = new OpenLayers.Feature(layer, 102 new OpenLayers.LonLat(100,100)); 103 t.ok( !feature2.onScreen(), "feature knows it's offscreen" ); 95 t.delay_call( 1, function() { 96 //onscreen feature 97 var feature1 = new OpenLayers.Feature(layer, 98 new OpenLayers.LonLat(0,0)); 99 t.ok( feature1.onScreen(), "feature knows it's onscreen" ); 100 101 //onscreen feature 102 var feature2 = new OpenLayers.Feature(layer, 103 new OpenLayers.LonLat(100,100)); 104 t.ok( !feature2.onScreen(), "feature knows it's offscreen" ); 105 }); 104 106 } 105 107 106 108 // --> -
tests/Layer/test_Grid.html
old new 3 3 <script src="../../lib/OpenLayers.js"></script> 4 4 <script type="text/javascript"><!-- 5 5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); 6 var map; 6 7 var layer; 7 8 8 9 var name = 'Test Layer'; … … 32 33 33 34 function test_02_Layer_Grid_inittiles (t) { 34 35 t.plan( 2 ); 35 varmap = new OpenLayers.Map('map');36 map = new OpenLayers.Map('map'); 36 37 layer = new OpenLayers.Layer.WMS(name, url, params); 37 38 map.addLayer(layer); 38 39 map.setCenter(new OpenLayers.LonLat(0,0),5); … … 43 44 44 45 function test_03_Layer_Grid_clearTiles (t) { 45 46 t.plan(1); 46 varmap = new OpenLayers.Map('map');47 map = new OpenLayers.Map('map'); 47 48 layer = new OpenLayers.Layer.WMS(name, url, params); 48 49 map.addLayer(layer); 49 50 … … 81 82 function test_05_Layer_Grid_getResolution(t) { 82 83 t.plan( 1 ); 83 84 84 varmap = new OpenLayers.Map('map');85 map = new OpenLayers.Map('map'); 85 86 layer = new OpenLayers.Layer.WMS(name, url, params); 86 87 map.addLayer(layer); 87 88 … … 94 95 t.plan( 2 ); 95 96 var bounds, zoom; 96 97 97 varmap = new OpenLayers.Map('map');98 map = new OpenLayers.Map('map'); 98 99 layer = new OpenLayers.Layer.WMS(name, url, params); 99 100 map.addLayer(layer); 100 101 … … 132 133 t.plan(5); 133 134 134 135 var options = {tileSize: new OpenLayers.Size(500,50)}; 135 varmap = new OpenLayers.Map('map', options);136 map = new OpenLayers.Map('map', options); 136 137 layer = new OpenLayers.Layer.Grid(name, url, params); 137 138 map.addLayer(layer); 138 139 … … 156 157 } 157 158 158 159 function test_11_Layer_Grid_setMap(t) { 159 160 160 t.plan(2); 161 161 162 162 var options = {tileSize: new OpenLayers.Size(500,50)}; 163 varmap = new OpenLayers.Map('map', options);163 map = new OpenLayers.Map('map', options); 164 164 layer = new OpenLayers.Layer.Grid(name, url, params); 165 165 166 166 … … 171 171 } 172 172 173 173 174 175 /*** animated zooming test functions ***/ 176 177 function test_12_Layer_Grid_setZoomOutTile (t) { 178 t.plan(5); 179 180 map = new OpenLayers.Map('map'); 181 layer = new OpenLayers.Layer.WMS(name, url, params); 182 map.addLayer(layer); 183 map.tileSize = new OpenLayers.Size(256,256); 184 map.zoomOutTileFactor = 4; 185 var tile = map.baseLayer.zoomOutTile; 186 187 t.ok( tile instanceof OpenLayers.Tile.Image, 188 "zoomOutTile is a Tile.Image object"); 189 190 var firstChild = map.baseLayer.div.firstChild; 191 t.eq( tile.imgDiv.id, firstChild.id, 192 "zoomOutTile is first child of baseLayerDiv"); 193 194 size = map.baseLayer.zoomOutTile.size; 195 t.eq( size.w, 1024, "zoomOutTile width is 1024px"); 196 t.eq( size.h, 1024, "zoomOutTile height is 1024px"); 197 198 t.ok( tile.imgDiv.style.display == "none", 199 "zoomOutTile is invisible"); 200 } 201 202 203 function test_13_Layer_Grid_getTileSize (t) { 204 t.plan(2); 205 206 map = new OpenLayers.Map('map'); 207 layer = new OpenLayers.Layer.WMS(name, url, params); 208 map.addLayer(layer); 209 map.tileSize = new OpenLayers.Size(256,256); 210 211 size = map.baseLayer.getTileSize(); 212 t.eq(size.w, 256, "tile width is correct"); 213 t.eq(size.h, 256, "tile height is correct"); 214 } 215 216 function test_14_Layer_Grid_getCenterTile (t) { 217 t.plan(1); 218 219 map = new OpenLayers.Map('map'); 220 layer = new OpenLayers.Layer.WMS(name, url, params); 221 map.addLayer(layer); 222 map.setCenter(new OpenLayers.LonLat(0,0)); 223 224 tile = map.baseLayer.getCenterTile(); 225 t.ok(tile.bounds.contains(0,0,true), 226 "center tile has been set correctly" ); 227 } 228 229 function test_15_Layer_Grid_setTilesOutsideInvisible (t) { 230 t.plan(1); 231 232 map = new OpenLayers.Map('map'); 233 layer = new OpenLayers.Layer.WMS(name, url, params); 234 map.addLayer(layer); 235 map.setCenter(new OpenLayers.LonLat(0,0)); 236 map.zoomTo(5,false); 237 map.baseLayer.setTilesOutsideInvisible(); 238 239 var tileOutside = map.baseLayer.grid[0][0]; 240 t.ok( tileOutside.imgDiv.style.display == "none", 241 "tiles outside the viewport have been set invisible"); 242 243 } 244 245 function test_16_Layer_Grid_scaleTilesOfGrid (t) { 246 t.plan(4); 247 248 map = new OpenLayers.Map('map'); 249 layer = new OpenLayers.Layer.WMS(name, url, params); 250 map.addLayer(layer); 251 map.setCenter(new OpenLayers.LonLat(0,0)); 252 map.zoomTo(5,false); 253 254 var tile = map.baseLayer.grid[3][2]; 255 var centerTile = map.baseLayer.getCenterTile(); 256 var newTileSize = new OpenLayers.Size(128,128); 257 map.baseLayer.scaleTileTo(centerTile,newTileSize); 258 map.baseLayer.scaleTilesOfGrid(centerTile,newTileSize); 259 260 t.eq( tile.imgDiv.style.width, "128px", 261 "width of tiles has been set correctly"); 262 t.eq( tile.imgDiv.style.height, "128px", 263 "height of tiles has been set correctly"); 264 t.eq( tile.imgDiv.style.top, "147px", 265 "top position of tiles has been set correctly"); 266 t.eq( tile.imgDiv.style.left, "122px", 267 "left position of tiles has been set correctly"); 268 } 269 270 function test_17_Layer_Grid_scaleZoomOutTile (t) { 271 t.plan(5); 272 273 map = new OpenLayers.Map('map'); 274 layer = new OpenLayers.Layer.WMS(name, url, params); 275 map.addLayer(layer); 276 map.setCenter(new OpenLayers.LonLat(0,0)); 277 map.tileSize = new OpenLayers.Size(256,256); 278 map.zoomToMaxExtent(); 279 var tile = map.baseLayer.zoomOutTile; 280 layer.firstCall = false; //set flag manually 281 map.baseLayer.scaleZoomOutTile(1,map.maxResolution/2); 282 283 t.eq( tile.imgDiv.style.width, "512px", 284 "width of zoomOutTile has been set correctly"); 285 t.eq( tile.imgDiv.style.height, "512px", 286 "height of zoomOutTile has been set correctly"); 287 t.eq( tile.imgDiv.style.top, "-109px", 288 "top position of zoomOutTile has been set correctly"); 289 t.eq( tile.imgDiv.style.left, "-6px", 290 "left position of zoomOutTile has been set correctly"); 291 t.ok( tile.imgDiv.style.display != "none", 292 "zoomOutTile has been set visible"); 293 } 294 295 function test_18_Layer_Grid_cloneBaseLayerDiv (t) { 296 t.plan(4); 297 298 map = new OpenLayers.Map('map'); 299 layer = new OpenLayers.Layer.WMS(name, url, params); 300 map.addLayer(layer); 301 302 map.baseLayer.cloneBaseLayerDiv(); 303 var cloneDiv = map.baseLayerDivClone; 304 var originDiv = map.baseLayer.div; 305 t.ok( cloneDiv instanceof HTMLDivElement, 306 "cloned baseLayerDiv is a valid HTMLDivElement"); 307 t.eq( cloneDiv.childNodes.length, originDiv.childNodes.length, 308 "cloned baseLayerDiv has the same number of childs"); 309 t.eq( parseInt(cloneDiv.style.zIndex)+1, parseInt(originDiv.style.zIndex), 310 "zIndex has been set correctly"); 311 t.ok( map.baseLayer.zoomOutTile.imgDiv.style.display == "none", 312 "zoomOutTile of original div has been set invisible"); 313 } 314 315 316 174 317 function test_99_Layer_Grid_destroy (t) { 175 318 176 319 t.plan( 5 ); 177 320 178 varmap = new OpenLayers.Map('map');321 map = new OpenLayers.Map('map'); 179 322 layer = new OpenLayers.Layer.Grid(name, url, params); 180 323 map.addLayer(layer); 181 324 layer.destroy(); … … 183 326 t.eq( layer.tileSize, null, "layer.tileSize is null after destroy" ); 184 327 185 328 186 //test with tile creation329 //test with tile creation 187 330 layer = new OpenLayers.Layer.WMS(name, url, params); 188 331 map.addLayer(layer); 189 332 -
tests/Layer/test_MapServer.html
old new 56 56 "image src is created correctly via addtile" ); 57 57 t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" ); 58 58 t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" ); 59 60 // get the 2nd child, because the 1st is a bigger zoomOutTile 61 var firstChild = layer.div.firstChild.nextSibling; 59 62 60 var firstChild = layer.div.firstChild;61 63 if (!isMozilla) 62 64 t.ok( true, "skipping element test outside of Mozilla"); 63 65 else -
tests/Layer/test_WMS.html
old new 26 26 27 27 } 28 28 29 function test_02_Layer_WMS_addtile (t) { 29 function test_03_Layer_WMS_getURL (t) { 30 t.plan( 3 ); 31 32 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 33 layer = new OpenLayers.Layer.WMS(name, url, params); 34 var map = new OpenLayers.Map('map'); 35 map.addLayer(layer); 36 37 var bounds = new OpenLayers.Bounds(1,2,3,4); 38 var url = map.baseLayer.getURL(bounds); 39 t.eq( url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=1%2C2%2C3%2C4&WIDTH=256&HEIGHT=256", 40 "url has been set correctly"); 41 42 var tileSize = new OpenLayers.Size(512,512); 43 url = map.baseLayer.getURL(bounds,tileSize); 44 t.ok( url.match("WIDTH=512"), 45 "url with custom width has been set correctly"); 46 t.ok( url.match("HEIGHT=512"), 47 "url with custom height has been set correctly"); 48 49 } 50 51 function test_03_Layer_WMS_addtile (t) { 30 52 t.plan( 6 ); 31 53 32 54 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; … … 53 75 t.eq( tile.imgDiv.style.top, "6px", "image top is set correctly via addtile" ); 54 76 t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" ); 55 77 56 var firstChild = layer.div.firstChild; 78 // get the 2nd child, because the 1st is a bigger zoomOutTile 79 var firstChild = layer.div.firstChild.nextSibling; 57 80 if (!isMozilla) 58 81 t.ok( true, "skipping element test outside of Mozilla"); 59 82 else … … 65 88 map.destroy(); 66 89 } 67 90 68 function test_0 3_Layer_WMS_inittiles (t) {91 function test_04_Layer_WMS_inittiles (t) { 69 92 t.plan( 2 ); 70 93 var map = new OpenLayers.Map('map'); 71 94 layer = new OpenLayers.Layer.WMS(name, url, params); … … 77 100 } 78 101 79 102 80 function test_0 4_Layer_WMS_clone (t) {103 function test_05_Layer_WMS_clone (t) { 81 104 t.plan(4); 82 105 83 106 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; … … 105 128 map.destroy(); 106 129 } 107 130 108 function test_0 5_Layer_WMS_isBaseLayer(t) {131 function test_06_Layer_WMS_isBaseLayer(t) { 109 132 t.plan(3); 110 133 111 134 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; … … 121 144 t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" ); 122 145 } 123 146 124 function test_0 6_Layer_WMS_mergeNewParams (t) {147 function test_07_Layer_WMS_mergeNewParams (t) { 125 148 t.plan( 5 ); 126 149 127 150 var map = new OpenLayers.Map("map"); … … 147 170 map.destroy(); 148 171 } 149 172 150 function test_0 7_Layer_WMS_getFullRequestString (t) {173 function test_08_Layer_WMS_getFullRequestString (t) { 151 174 152 175 153 176 t.plan( 2 ); … … 178 201 179 202 } 180 203 181 function test_0 8_Layer_WMS_setOpacity (t) {204 function test_09_Layer_WMS_setOpacity (t) { 182 205 t.plan( 5 ); 183 206 184 207 var map = new OpenLayers.Map('map'); -
lib/OpenLayers/Layer.js
old new 107 107 /** @type Boolean */ 108 108 displayOutsideMaxExtent: false, 109 109 110 110 /** did the image finish loading before a new draw was initiated? 111 * @type Boolean */ 112 doneLoading: false, 113 114 /** @type Boolen */ 115 firstCall: true, 116 117 111 118 /** 112 119 * @constructor 113 120 * … … 133 140 } 134 141 135 142 this.events = new OpenLayers.Events(this, this.div, this.EVENT_TYPES); 143 this.events.register("loadend", this, this.setLoadendVisibility); 136 144 }, 137 145 138 146 /** … … 465 473 */ 466 474 getResolution: function() { 467 475 var zoom = this.map.getZoom(); 476 if (zoom >= this.map.getNumZoomLevels()) 477 zoom = this.map.getNumZoomLevels() - 1; 468 478 return this.resolutions[zoom]; 469 479 }, 470 480 … … 546 556 * translated into view port pixels 547 557 * @type OpenLayers.Pixel 548 558 */ 549 getViewPortPxFromLonLat: function (lonlat ) {559 getViewPortPxFromLonLat: function (lonlat, resolution) { 550 560 var px = null; 551 561 if (lonlat != null) { 552 var resolution = this.map.getResolution(); 562 if (!resolution) 563 resolution = this.map.getResolution(); 553 564 var extent = this.map.getExtent(); 554 565 px = new OpenLayers.Pixel( 555 566 Math.round(1/resolution * (lonlat.lon - extent.left)), … … 580 591 this.div.style.zIndex = zIdx; 581 592 }, 582 593 594 595 596 597 /********************************************************/ 598 /* */ 599 /* Baselayer Functions for zooming/scaling */ 600 /* */ 601 /********************************************************/ 602 603 /** 604 * Initializes zoomOut tile and sets a x-times bigger tile size. 605 * 606 * Default function; will override in subclasses, 607 * otherwise it returns false 608 * 609 * @returns false if no zoomOutTile is set 610 * @type Boolean 611 */ 612 setZoomOutTile:function() { 613 return false; 614 }, 615 616 /** 617 * Initializes zoomOut tile and sets a x-times bigger tile size. 618 * 619 * special function; shares with some baselayers; calls from subclasses 620 * 621 */ 622 setZoomOutTile_share:function() { 623 if (!this.zoomOutTile) { 624 var bounds = this.map.getMaxExtent(); 625 var resolution = this.resolutions[0]; 626 627 // calculate tile bounds 628 var n = 0; 629 do { 630 resolution = resolution * Math.pow(2, n); 631 632 var tilelon = resolution * this.map.tileSize.w; 633 var tilelat = resolution * this.map.tileSize.h; 634 635 var tileoffsetlon = bounds.left; 636 var tileoffsetlat = bounds.bottom; 637 638 var tileBounds = new OpenLayers.Bounds(tileoffsetlon, 639 tileoffsetlat, 640 tileoffsetlon + tilelon, 641 tileoffsetlat + tilelat); 642 n++; 643 } 644 while (!tileBounds.containsBounds(bounds, false, true)); 645 646 var tileSize = new OpenLayers.Size(); 647 tileSize.w = this.map.zoomOutTileSizeFactor * this.map.tileSize.w; 648 tileSize.h = this.map.zoomOutTileSizeFactor * this.map.tileSize.h; 649 650 // formulate request url string 651 var url = this.getURL(tileBounds, tileSize); 652 // default start position 653 var pos = new OpenLayers.Pixel (0,0); 654 // default start size 655 var tilesize = new OpenLayers.Size(0,0); 656 657 this.zoomOutTile = new OpenLayers.Tile.Image(this, pos, tileBounds, 658 url, tileSize); 659 660 // draw tile -> sets imgDiv 661 this.zoomOutTile.draw(); 662 663 // resize zoomOutTile 664 this.zoomOutTile.imgDiv.style.width = 0; 665 this.zoomOutTile.imgDiv.style.height = 0; 666 667 // set zoomOut tile invisible 668 if (this.map.baseLayer.zoomOutTile) 669 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 670 } 671 }, 672 673 /** 674 * Gets the current tile size of the layer. 675 * 676 * Default function; will override in subclasses, 677 * otherwise it returns false - that means: no scaling possible! 678 * 679 * @returns null if no tile size set 680 * @type OpenLayers.Size 681 */ 682 getTileSize:function() { 683 return null; 684 }, 685 686 687 /** 688 * Gets tile, which contains the center of the viewport. 689 * 690 * Default function; will override in subclasses, 691 * otherwise it returns null - that means: no scaling possible! 692 * 693 * @returns returns null if no center tile set 694 * @type OpenLayers.Tile 695 */ 696 getCenterTile:function() { 697 return null; 698 }, 699 700 701 /** 702 * Sets all tiles outside the viewport invisible. 703 * Only for baselayers with a grid of tiles. 704 * 705 * Default function; will override in subclasses, 706 * otherwise it returns false 707 * 708 * @returns false if baselayer has no grid 709 * @type Boolean 710 */ 711 setTilesOutsideInvisible:function() { 712 return false; 713 }, 714 715 /** 716 * Scales tile to the new tile size (changes size and position). 717 * If you have a grid, the tile is the center tile. Otherwise it's 718 * the only one. 719 * 720 * @param {OpenLayers.Tile} tile 721 * @param {OpenLayers.Size} newTileSize 722 * 723 * @returns true if tile is scaled, otherwise false 724 * @type Boolean 725 */ 726 scaleTileTo:function(tile, newTileSize) { 727 //convert the center of the map in pixel 728 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 729 730 //reposition and resize the tile 731 if (tile) { 732 if ((newTileSize.w < Math.pow(2,15)) && 733 (newTileSize.h < Math.pow(2,15)) ){ 734 735 // set real start position of centerTile 736 var startPosX = (tile.position.x + 737 parseInt(this.map.layerContainerDiv.style.left)); 738 // set new left position 739 var leftOffset = newTileSize.w / tile.size.w 740 * (centerPx.x - startPosX); 741 leftOffset = Math.round(leftOffset); 742 var newLeftPos = centerPx.x - leftOffset 743 - parseInt(this.map.layerContainerDiv.style.left); 744 tile.imgDiv.style.left = Math.round(newLeftPos) + "px"; 745 746 // set real start position of centerTile 747 var startPosY = (tile.position.y + 748 parseInt(this.map.layerContainerDiv.style.top)); 749 //set new top position 750 var topOffset = newTileSize.h / tile.size.h 751 * (centerPx.y - startPosY); 752 topOffset = Math.round(topOffset); 753 var newTopPos = centerPx.y - topOffset 754 - parseInt(this.map.layerContainerDiv.style.top); 755 tile.imgDiv.style.top = Math.round(newTopPos) + "px"; 756 757 //set new width and height 758 tile.imgDiv.style.width = Math.round(newTileSize.w) + "px"; 759 tile.imgDiv.style.height = Math.round(newTileSize.h) + "px"; 760 } 761 return true; 762 } 763 else { 764 return false; 765 } 766 }, 767 768 /** 769 * Scales all tiles of a grid to the new tile size 770 * (changes size and position). 771 * 772 * Default function; will override in subclasses, 773 * otherwise it returns false 774 * 775 * @param {OpenLayers.Tile} centerTile 776 * @param {OpenLayers.Size} newTileSize 777 * 778 * @returns false if no grid is scaled 779 * @type Boolean 780 */ 781 scaleTilesOfGrid:function(centertile, newTileSize) { 782 return false; 783 }, 784 785 786 /** 787 * Reposition and resize the zoomOut tile to prevent a white frame 788 * during zoomOut. 789 * 790 * @param {float} newZoomlevel 791 * @param {float} newResolution 792 * 793 * @returns false if no zoomOutTile scaled 794 * @type Boolean 795 */ 796 scaleZoomOutTile: function(newZoomlevel, newResolution) { 797 return false; 798 }, 799 800 /** 801 * The actual zoomOutTile scale function: 802 * Reposition and resize the zoomOut tile to prevent a white frame 803 * during zoomOut. 804 * 805 * special function; shares with some baselayers; calls from subclasses 806 * 807 * @param {float} newZoomlevel 808 * @param {float} newResolution 809 * 810 * @returns true after the zoomOutTile is scaled 811 * @type Boolean 812 */ 813 scaleZoomOutTile_share: function(newZoomlevel, newResolution) { 814 815 //convert the current center of the map in pixel 816 var centerPx = this.map.getPixelFromLonLat(this.map.getCenter()); 817 818 819 var newTileSize = new OpenLayers.Size(); 820 newTileSize.w = Math.round(this.map.tileSize.w * Math.pow(2, newZoomlevel)); 821 newTileSize.h = Math.round(this.map.tileSize.h * Math.pow(2, newZoomlevel)); 822 823 // handles bug in ie: 824 // turn zoomOut tile scale off, if tileSize > 2^15 825 var ieBug; 826 if (navigator.appName == "Microsoft Internet Explorer"){ 827 if ((newTileSize.w > Math.pow(2,15)) && 828 (newTileSize.h > Math.pow(2,15)) ){ 829 ieBug = true; 830 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 831 } 832 else { 833 ieBug = false; 834 } 835 } 836 else { 837 ieBug = false; 838 } 839 840 if (!ieBug && !this.firstCall) { 841 //set new size (width and height) 842 this.zoomOutTile.imgDiv.style.width = newTileSize.w + "px"; 843 this.zoomOutTile.imgDiv.style.height = newTileSize.h + "px"; 844 845 //set new position (top and left) 846 var bounds = this.zoomOutTile.bounds; 847 var extent = this.map.getExtent(); 848 var maxExtent = this.map.getMaxExtent(); 849 850 var resolution = this.map.getMaxResolution(); 851 var centerLonLat = extent.getCenterLonLat(); 852 853 var offsetlon = bounds.left - centerLonLat.lon; 854 var offsetlat = -bounds.top + centerLonLat.lat; 855 856 var offsetx = offsetlon / newResolution 857 - parseInt(this.map.layerContainerDiv.style.left); 858 var offsety = offsetlat / newResolution 859 - parseInt(this.map.layerContainerDiv.style.top); 860 861 this.zoomOutTile.imgDiv.style.left = 862 Math.round(centerPx.x + offsetx) + "px"; 863 this.zoomOutTile.imgDiv.style.top = 864 Math.round(centerPx.y + offsety) + "px"; 865 866 867 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "block"; 868 } 869 870 return true; 871 }, 872 873 /** 874 * Clones layerContainer for "smooth tile update". 875 * So, it gets no blank map while map is loading in new zoomlevel. 876 * 877 * Default function; will override in subclasses, 878 * otherwise it returns false 879 * 880 * @returns false if no layerContainer cloned 881 * @type Boolean 882 */ 883 cloneBaseLayerDiv:function() { 884 return false; 885 }, 886 887 /** 888 * The actual clone function: 889 * Hold scaled map while tiles are loading successive. 890 * 891 * special function; shares with some baselayers; calls from subclasses 892 * 893 */ 894 cloneBaseLayerDiv_share:function() { 895 // function for map only; not for overviewmap! 896 if (this.map.div.id == "map") { 897 898 // 1. clone baseLayerDiv with all childs (replace, if already exist) 899 if (this.map.baseLayerDivClone){ 900 this.map.layerContainerDiv.removeChild(this.map.baseLayerDivClone); 901 this.map.baseLayerDivClone = null; 902 } 903 this.map.baseLayerDivClone = this.map.baseLayer.div.cloneNode(true); 904 this.map.baseLayerDivClone.id = 905 this.map.baseLayer.div.id + "_clone"; 906 907 908 // 2. append baseLayerDivClone to layerContainer 909 // (now the cloned div is above the original; it hides the original) 910 this.map.layerContainerDiv.appendChild(this.map.baseLayerDivClone); 911 912 // 3. set zIndex 913 this.map.baseLayerDivClone.style.zIndex--; 914 915 // 4. set zoomOut tile (of original div) invisible 916 if (this.map.baseLayer.zoomOutTile) 917 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 918 919 // 5. adjust left and top position 920 // (if map is panning before, layerContainer is displaced) 921 if (this.map.layerContainerDiv.style.left != "") 922 this.map.baseLayerDivClone.style.left += 923 parseInt(this.map.layerContainerDiv.style.left); 924 if (this.map.layerContainerDiv.style.top != "") 925 this.map.baseLayerDivClone.style.top += 926 parseInt(this.map.layerContainerDiv.style.top); 927 } 928 }, 929 930 931 /** 932 * Sets visibility of map after zoomend/loadend: 933 * - freezed/cloned layerContainer invisible 934 * - zoomOutTile invisibile 935 * 936 * Calls automatically after fire loadend event. 937 */ 938 setLoadendVisibility: function() { 939 // set flag that zoom animation finished 940 this.map.zoomanimationActive = false; 941 942 // function for map only; not for overviewmap! 943 if (this.map.div.id == "map") { 944 // remove cloned baseLayerDiv 945 if (this.map.baseLayerDivClone){ 946 this.map.layerContainerDiv.removeChild(this.map.baseLayerDivClone); 947 this.map.baseLayerDivClone = null; 948 } 949 } 950 951 // after map is loaded the first time the flag sets to false 952 // (reason: zoomOutTile shouldn't visible by first zoom/scale) 953 if (this.firstCall) 954 this.firstCall = false; 955 }, 956 957 583 958 /** @final @type String */ 584 959 CLASS_NAME: "OpenLayers.Layer" 585 960 }; -
lib/OpenLayers/Map.js
old new 62 62 /** @type HTMLDivElement */ 63 63 layerContainerDiv: null, 64 64 65 /** @type HTMLDivElement */ 66 baseLayerDivClone: null, 67 65 68 /** ordered list of layers in the map 66 69 * 67 70 * @type Array(OpenLayers.Layer) … … 136 139 /** @type string */ 137 140 theme: null, 138 141 142 143 //ANIMATION 144 145 /** @type Boolean */ 146 animated: true, 147 148 /** steps in the slide 149 * 150 * @type int */ 151 slideSteps: 4, 152 153 /** millisecondss between each step 154 * 155 * @type int */ 156 slideWait: 1, 157 158 /** power used to calculate width of slide steps 159 * 160 * @type float*/ 161 slidePower: 0.7, 162 163 164 /** @type int */ 165 animatedZoomingIntervalID: null, 166 167 168 /** @type boolean */ 169 zoomanimationActive: false, 170 171 /** @type int */ 172 zoomOutTileSizeFactor: 4, 173 174 /** @type int */ 175 zoomlevel_startScale: null, 176 177 /** @type float */ 178 zoomlevel_scale: null, 179 180 /** @type OpenLayers.Size */ 181 tileSize_startScale: null, 182 183 /** @type OpenLayers.Size */ 184 tileSize_scale: null, 185 186 /** @type OpenLayers.Tile */ 187 centerTile: null, 188 189 /** @type float */ 190 resolution_scale: null, 191 192 139 193 /** Should OpenLayers allow events on the map to fall through to other 140 194 * elements on the page, or should it swallow them? (#457) 141 195 * … … 182 236 183 237 this.updateSize(); 184 238 185 // Because Mozilla does not support the "resize" event for elements other186 // than "window", we need to put a hack here.187 //239 // Because Mozilla does not support the "resize" event for elements other 240 // than "window", we need to put a hack here. 241 // 188 242 if (navigator.appName.contains("Microsoft")) { 189 243 // If IE, register the resize on the div 190 244 this.events.register("resize", this, this.updateSize); … … 229 283 230 284 // always call map.destroy() 231 285 OpenLayers.Event.observe(window, 'unload', this.unloadDestroy); 232 286 287 // set tile size for scaling 288 this.tileSize_scale = new OpenLayers.Size(); 233 289 }, 234 290 235 291 /** … … 511 567 512 568 // set new baselayer and make it visible 513 569 this.baseLayer = newBaseLayer; 570 571 // preload a bigger tile for zooming out (not supported 572 // for every baselayer! for map only; not for ovmap!) 573 if (this.div.id == "map") 574 this.baseLayer.setZoomOutTile(); 514 575 515 576 // Increment viewRequestID since the baseLayer is 516 577 // changing. This is used by tiles to check if they should 517 578 // draw themselves. 518 579 this.viewRequestID++; 580 581 // make new baselayer visible 519 582 this.baseLayer.setVisibility(true, noEvent); 520 583 521 584 //redraw all layers … … 655 718 var centerLL = this.getLonLatFromViewPortPx(center); 656 719 var zoom = this.getZoom(); 657 720 this.zoom = null; 658 this.setCenter(this.getCenter(), zoom); 721 this.setCenter(this.getCenter(), zoom); 722 723 // reposition zoomOutTile (only if tile visible) 724 if(this.baseLayer.zoomOutTile.imgDiv.style.display != "none") 725 this.baseLayer.scaleZoomOutTile(zoom,this.getResolution()); 659 726 } 660 727 661 728 } … … 872 939 } 873 940 }, 874 941 942 943 /** Position changer with Memory by www.hesido.com 944 * modified by dncpax for OpenLayers 945 * 946 * @param {int} slideZoom 947 * @param {int} totalSteps 948 * @param {int} intervals 949 * @param {float} power 950 */ 951 zoomSlide: function( slideZoom, totalSteps, interval, power) { 952 if (this.animatedZoomingIntervalID) { 953 window.clearInterval(this.animatedZoomingIntervalID); 954 this.animatedZoomingIntervalID = null; 955 } 956 var context = { 957 'map': this, 958 'slideZoom': slideZoom, 959 'totalSteps': totalSteps, 960 'step': 0, 961 'power': power 962 }; 963 var move = function() { 964 var delta = this.slideZoom - this.map.zoom; 965 var dZoom = OpenLayers.Util.easeInOutZoom(delta, 966 this.totalSteps, 967 this.step, 968 this.power); 969 970 this.map.zoomTo(this.map.zoom + dZoom, false, this.step); 971 this.step++; 972 if (this.step > this.totalSteps) { 973 window.clearInterval(this.map.animatedZoomingIntervalID); 974 this.map.animatedZoomingIntervalID = null; 975 } 976 }; 977 978 this.animatedZoomingIntervalID = 979 window.setInterval(move.bindAsEventListener(context), 980 interval); 981 }, 982 983 875 984 /** 876 985 * @private 877 986 * … … 906 1015 return valid; 907 1016 }, 908 1017 1018 909 1019 /********************************************************/ 910 1020 /* */ 911 1021 /* Layer Options */ … … 1058 1168 1059 1169 /** Zoom to a specific zoom level 1060 1170 * 1061 * @param {int} zoom 1171 * @param {float} zoom 1172 * @param {Boolean} animated 1173 * @param {int} step 1174 * 1062 1175 */ 1063 zoomTo: function(zoom ) {1176 zoomTo: function(zoom, animated, step) { 1064 1177 if (this.isValidZoomLevel(zoom)) { 1065 this.setCenter(null, zoom); 1178 if (animated == null) { 1179 animated = this.animated; 1180 } 1181 1182 if (animated) { 1183 this.zoomSlide(zoom, 1184 this.slideSteps, 1185 this.slideWait, 1186 this.slidePower); 1187 1188 // prepare zoom animation 1189 this.prepareZoomAnimation(); 1190 } else { 1191 1192 if (step <= this.slideSteps ) { 1193 1194 // set new zoomlevel from zoomSlide function 1195 this.zoomlevel_scale = zoom; 1196 1197 // run zoom animation -> scale tile(s) 1198 this.runZoomAnimation(null,null); 1199 } 1200 1201 // finish scaling -> redraw map in new zoomlevel 1202 // or no animation set 1203 if ( (step == this.slideSteps) 1204 || ((step == null)&&(!animated)) ){ 1205 1206 this.finishZoomAnimation(zoom); 1207 } 1208 } 1066 1209 } 1067 1210 }, 1068 1211 1069 1212 /** 1070 1213 * @param {int} zoom 1071 1214 */ 1072 zoomIn: function() { 1073 this.zoomTo(this.getZoom() + 1); 1215 zoomIn: function(animated) { 1216 if (animated==null) 1217 animated = true; 1218 1219 if (!this.zoomanimationActive) 1220 this.zoomTo(this.getZoom() + 1,animated, null); 1074 1221 }, 1075 1222 1076 1223 /** 1077 1224 * @param {int} zoom 1078 1225 */ 1079 zoomOut: function() { 1080 this.zoomTo(this.getZoom() - 1); 1226 zoomOut: function(animated) { 1227 if (animated==null) 1228 animated = true; 1229 1230 if (!this.zoomanimationActive) 1231 this.zoomTo(this.getZoom() - 1,animated, null); 1081 1232 }, 1082 1233 1083 1234 /** Zoom to the passed in bounds, recenter … … 1085 1236 * @param {OpenLayers.Bounds} bounds 1086 1237 */ 1087 1238 zoomToExtent: function(bounds) { 1088 this.setCenter(bounds.getCenterLonLat(), 1089 this.getZoomForExtent(bounds)); 1239 // recenter map to new center of bounds (in OLD zoom level) 1240 this.setCenter(bounds.getCenterLonLat(), this.getZoom()); 1241 1242 // determine new zoomlevel 1243 var newZoomlevel = this.getZoomForExtent(bounds); 1244 1245 // zoom to new zoomlevel 1246 this.zoomTo(newZoomlevel); 1090 1247 }, 1091 1248 1092 1249 /** Zoom to the full extent and recenter. … … 1113 1270 center.lat + h_deg / 2); 1114 1271 this.zoomToExtent(extent); 1115 1272 }, 1273 1116 1274 1275 /** 1276 * get and set some settings for zoom animation 1277 * 1278 * 1279 */ 1280 prepareZoomAnimation:function() { 1281 // begin zoom animation -> set flag 1282 this.zoomanimationActive = true; 1283 1284 // get current zoomlevel 1285 this.zoomlevel_startScale = this.zoom; 1286 1287 // get current tile size (it's the base for scaling) 1288 this.tileSize_startScale = this.baseLayer.getTileSize(); 1289 1290 // get tile, which contains the center of the viewport 1291 this.centerTile = this.baseLayer.getCenterTile(); 1292 1293 // set all active overlays temporarily invisible 1294 for (var i = 0; i < this.layers.length; i++) { 1295 var layer = this.layers[i]; 1296 if (!layer.isBaseLayer) { 1297 this.layers[i].div.style.display = "none"; 1298 } 1299 } 1300 1301 // set all tiles outside the viewport invisible 1302 // (only for baselayers with grid of tiles) 1303 this.baseLayer.setTilesOutsideInvisible(); 1304 }, 1305 1306 /** 1307 * run zoom animation -> scale tile(s) 1308 * 1309 * @param {int} zoomStopHeight 1310 * @param {OpenLayers.Pixel} sliderPosition 1311 */ 1312 runZoomAnimation:function(zoomStopHeight, sliderPosition) { 1313 // scale baselayer if tileSize and centerTile is set 1314 if ( this.tileSize_startScale && this.centerTile ) { 1315 1316 // determine zoomlevel (only if slider used ->zoomStopHeight exists) 1317 if (zoomStopHeight && sliderPosition ) 1318 this.calculateNewZoomlevel(zoomStopHeight,sliderPosition); 1319 1320 // determine tile size and map resolution 1321 this.calculateNewTileSize(); 1322 1323 // get tile, which contains the center of the viewport again 1324 // (it's necessary for synchronous animated panning and zooming) 1325 if (!zoomStopHeight) 1326 this.centerTile = this.baseLayer.getCenterTile(); 1327 1328 // scale (center) tile to new scaled size 1329 this.baseLayer.scaleTileTo(this.centerTile, 1330 this.tileSize_scale); 1331 1332 // scale all tiles to new scaled size (if there 1333 // are more than one tile) 1334 this.baseLayer.scaleTilesOfGrid(this.centerTile, 1335 this.tileSize_scale); 1336 1337 // scale zoomOut tile (to prevent a white frame during zoomOut) 1338 this.baseLayer.scaleZoomOutTile(this.zoomlevel_scale, 1339 this.resolution_scale); 1340 1341 // set new scaled map resolution (important for overviewmap) 1342 this.setScaleResolution(this.resolution_scale); 1343 1344 // update zoom slider position (only if slider NOT used -> 1345 // zoomStopHeight not exisits) 1346 if (!zoomStopHeight){ 1347 for (i=0; i<this.controls.length; i++) { 1348 if (this.controls[i].CLASS_NAME == "OpenLayers.Control.PanZoomBar") 1349 this.controls[i].moveZoomBar(this.zoomlevel_scale); 1350 } 1351 } 1352 } 1353 }, 1354 1355 /** 1356 * finish zoom animation 1357 * 1358 * @param {int} finalZoomlevel 1359 */ 1360 finishZoomAnimation:function(finalZoomlevel) { 1361 // clone layerContainer for "smooth tile update" without blank map 1362 this.baseLayer.cloneBaseLayerDiv(); 1363 1364 // zooom to final zoomlevel 1365 if (this.isValidZoomLevel(finalZoomlevel)) 1366 this.setCenter(null, finalZoomlevel); 1367 1368 // set zoomanimation flag to false _manually_ 1369 // (only for baselayers without onimageload events, f.e. imagelayer 1370 // and for ie, where the loadend event doesn't works correctly); 1371 // for all other layers it calls automatically from 1372 // loadendevent in layers.js 1373 if (this.baseLayer.CLASS_NAME.match("OpenLayers.Layer.Image") || 1374 (navigator.appName == "Microsoft Internet Explorer") ){ 1375 this.zoomanimationActive = false; 1376 } 1377 }, 1378 1379 1380 /** 1381 * Calculates new zoomlevel of current zoomslider position. 1382 * 1383 * @param {int} zoomStopHeight 1384 * @param {OpenLayers.Pixel} sliderPosition 1385 */ 1386 calculateNewZoomlevel:function(zoomStopHeight, sliderPosition) { 1387 // convert current sliderposition to new zoomlevel 1388 var deltaY_zoomlevel = this.zoomStart.y - sliderPosition.y; 1389 this.zoomlevel_scale = this.zoomlevel_startScale + 1390 deltaY_zoomlevel/zoomStopHeight; 1391 1392 // check zoomlevel validity 1393 if (this.zoomlevel_scale < 0) { 1394 this.zoomlevel_scale = 0; 1395 } 1396 if (this.zoomlevel_scale > (this.getNumZoomLevels()- 1)) { 1397 this.zoomlevel_scale = this.getNumZoomLevels() - 1; 1398 } 1399 }, 1400 1401 1402 /** 1403 * Calculates new tile size and map resolution of current zoomlevel. 1404 * 1405 */ 1406 calculateNewTileSize:function() { 1407 // calculate new tile size for... 1408 // ...zoomIn 1409 if (this.zoomlevel_startScale < this.zoomlevel_scale) { 1410 this.tileSize_scale.w = Math.pow(2,(this.zoomlevel_scale - 1411 this.zoomlevel_startScale)) * this.tileSize_startScale.w; 1412 this.tileSize_scale.h = Math.pow(2,(this.zoomlevel_scale - 1413 this.zoomlevel_startScale)) * this.tileSize_startScale.h; 1414 1415 // set new map resolution 1416 this.resolution_scale = 1/(Math.pow(2,(this.zoomlevel_scale - 1417 this.zoomlevel_startScale))) * this.getResolution(); 1418 } 1419 // ...zoomOut / no zoom changes 1420 if (this.zoomlevel_startScale >= this.zoomlevel_scale) { 1421 this.tileSize_scale.w = 1/(Math.pow(2,(this.zoomlevel_startScale - 1422 this.zoomlevel_scale))) * this.tileSize_startScale.w; 1423 this.tileSize_scale.h = 1/(Math.pow(2,(this.zoomlevel_startScale - 1424 this.zoomlevel_scale))) * this.tileSize_startScale.h; 1425 1426 // set new map resolution 1427 this.resolution_scale = Math.pow(2,(this.zoomlevel_startScale - 1428 this.zoomlevel_scale)) * this.getResolution(); 1429 } 1430 }, 1431 1432 1433 1117 1434 /********************************************************/ 1118 1435 /* */ 1119 1436 /* Translation Functions */ -
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 next zoomlevel in the zoom animation movement 979 * @type float 980 */ 981 OpenLayers.Util.easeInOutZoom = function(delta, totalSteps, step, power) { 982 var stepVal = Math.pow(((1/totalSteps)*step),power) * delta; 983 return stepVal; 984 }; -
lib/OpenLayers/Layer/WMS.js
old new 86 86 87 87 /** 88 88 * @param {OpenLayers.Bounds} bounds 89 * @param {OpenLayers.Size} tileSize 89 90 * 90 91 * @returns A string with the layer's url and parameters and also the 91 92 * passed-in bounds and appropriate tile size specified as 92 93 * parameters 93 94 * @type String 94 95 */ 95 getURL: function (bounds) { 96 getURL: function (bounds, tileSize) { 97 if (!tileSize) { 98 var tileSize = this.tileSize; 99 } 96 100 return this.getFullRequestString( 97 101 {BBOX:bounds.toBBOX(), 98 WIDTH:t his.tileSize.w,99 HEIGHT:t his.tileSize.h});102 WIDTH:tileSize.w, 103 HEIGHT:tileSize.h}); 100 104 }, 101 105 102 106 /** -
lib/OpenLayers/Layer/Grid.js
old new 23 23 /** @type Integer */ 24 24 buffer: 2, 25 25 26 /** @type Integer */ 27 centerRow: null, 28 29 /** @type Integer */ 30 centerCol: null, 31 26 32 /** 27 33 * @constructor 28 34 * … … 290 296 * Once all the grid's tiles have been added to the queue, we go back 291 297 * and iterate through the queue (thus reversing the spiral order from 292 298 * outside-in to inside-out), calling draw() on each tile. 299 * 300 * Fires loadend event after all tiles in viewport loaded. 293 301 */ 294 302 spiralTileLoad: function() { 295 303 var tileQueue = new Array(); … … 344 352 directionsTried++; 345 353 } 346 354 } 347 355 356 // fire loadstart event 357 this.events.triggerEvent("loadstart"); 358 this.doneLoading = false; 359 360 // set tileQueue temporary as class parameter; 361 // necessaray to get values also in onload event function 362 this.tileQueue = tileQueue; 363 348 364 // now we go through and draw the tiles in forward order 349 365 for(var i=0; i < tileQueue.length; i++) { 350 var tile = tileQueue[i] 351 tile.draw(); 352 //mark tile as unqueued for the next time (since tiles are reused) 353 tile.queued = false; 366 var drawn = tileQueue[i].draw(); 367 // mark tile as unqueued for the next time (since tiles are reused) 368 tileQueue[i].queued = false; 369 370 371 // onload event function; 372 // it calls automatically when image fires onload event 373 var onload = function() { 374 // get object array 375 var tile = this[0]; 376 var layer = this[1]; 377 if (layer.map.div.id == "map") { 378 // default assumption: every images in extent are loaded 379 var stillLoading = false; 380 381 // set internal alt message after image loaded 382 if (tile.imgDiv) 383 tile.imgDiv.alt = "loaded"; 384 385 // check if all visible tiles are loaded 386 for (var j=0; j < layer.tileQueue.length; j++) { 387 if (layer.tileQueue[j].imgDiv){ 388 if((layer.tileQueue[j].bounds.intersectsBounds( 389 layer.map.getExtent(),false)) 390 && (layer.tileQueue[j].imgDiv.alt != "loaded")){ 391 // at least one image tile is still loading 392 stillLoading = true; 393 } 394 } 395 } 396 397 // any visible images loaded? -> fire loadend event 398 if ((!stillLoading) && (!layer.map.baseLayer.doneLoading)) { 399 layer.map.baseLayer.doneLoading = true; 400 layer.events.triggerEvent("loadend"); 401 } 402 } 403 } 404 405 406 // if tile is start drawing (imgDiv exists)... 407 if (drawn){ 408 // create an object with current tile and layer for onload event 409 var object = new Array(); 410 object[0] = tileQueue[i]; 411 object[1] = this; 412 413 // start onload event listener 414 OpenLayers.Event.observe(tileQueue[i].imgDiv, 'load', 415 onload.bindAsEventListener(object)); 416 } 354 417 } 355 418 }, 356 419 420 357 421 /** 358 422 * addTile gives subclasses of Grid the opportunity to create an 359 423 * OpenLayer.Tile of their choosing. The implementer should initialize … … 447 511 } 448 512 } 449 513 }, 514 515 516 517 /********************************************************/ 518 /* */ 519 /* Baselayer Functions for zooming/scaling */ 520 /* */ 521 /********************************************************/ 522 523 /** 524 * Initializes zoomOut tile and sets a x-times bigger tile size. 525 * 526 * @returns true after zoomOutTile is set 527 * @type Boolean 528 */ 529 setZoomOutTile:function() { 530 this.setZoomOutTile_share(); 531 return true; 532 }, 533 534 /** 535 * Gets the current tile size of the layer. 536 * 537 * @returns the current map tile size 538 * @type OpenLayers.Size 539 */ 540 getTileSize:function() { 541 return this.map.getTileSize(); 542 }, 543 544 /** 545 * Gets tile, which contains the center of the viewport. 546 * 547 * @returns the tile, which contains the center of the viewport 548 * @type OpenLayers.Tile 549 */ 550 getCenterTile:function() { 551 var center = this.map.getCenter(); 552 553 if (this.grid) { 554 for (var iRow=0; iRow < this.grid.length; iRow++) { 555 for (var iCol=0; iCol < this.grid[iRow].length; iCol++) { 556 var tileBounds = this.grid[iRow][iCol].bounds; 557 if (tileBounds.containsLonLat(center, true)) { 558 this.centerRow = iRow; 559 this.centerCol = iCol; 560 return this.grid[iRow][iCol]; 561 } 562 } 563 } 564 } 565 return false; // something runs fail! 566 }, 450 567 568 569 /** 570 * Sets all tiles outside the viewport invisible. 571 * Only for baselayers with a grid of tiles. 572 * 573 * @returns true if tiles are set invisible 574 * @type Boolean 575 */ 576 setTilesOutsideInvisible:function() { 577 var extent = this.map.getExtent(); 578 var layerGrid = this.map.baseLayer.grid; 579 580 // go through the whole grid 581 for (var iRow=0; iRow < layerGrid.length; iRow++) { 582 for (var iCol=0; iCol < layerGrid[iRow].length; iCol++) { 583 var tile = layerGrid[iRow][iCol]; 584 if (tile.imgDiv) { 585 // scale all (visible) tiles within the viewport 586 if (!extent.containsBounds(tile.bounds,true, false)) 587 tile.imgDiv.style.display = "none"; 588 } 589 } 590 } 591 return true; 592 }, 593 594 595 /** 596 * Scales all tiles of a grid to the new tile size 597 * (changes size and position). 598 * 599 * @param {OpenLayers.Tile} centerTile 600 * @param {OpenLayers.Size} newTileSize 601 * 602 * @returns true after the grid is scaled 603 * @type Boolean 604 */ 605 scaleTilesOfGrid:function(centerTile, newTileSize) { 606 607 var extent = this.map.getExtent(); 608 609 // reposition and resize all _visible_ tiles of the active baselayer 610 var layerGrid = this.map.baseLayer.grid; 611 612 // go through the whole grid 613 for (var iRow=0; iRow < layerGrid.length; iRow++) { 614 for (var iCol=0; iCol < layerGrid[iRow].length; iCol++) { 615 var tile = layerGrid[iRow][iCol]; 616 if (tile.imgDiv) { 617 if ((newTileSize.w < Math.pow(2,15)) && 618 (newTileSize.h < Math.pow(2,15)) ){ 619 620 // scale all (visible) tiles within the viewport 621 if (extent.containsBounds(tile.bounds,true, false)) { 622 //define the factors for rows and columns 623 //(relates to the center tile) 624 var deltaRow = iRow - this.centerRow; 625 var deltaCol = iCol - this.centerCol; 626 627 //set new left position 628 var newLeftPos = parseInt(centerTile.imgDiv.style.left) 629 + deltaCol * newTileSize.w ; 630 tile.imgDiv.style.left = Math.round(newLeftPos) + "px"; 631 632 //set new top position 633 var newTopPos = parseInt(centerTile.imgDiv.style.top) 634 + deltaRow * newTileSize.h ; 635 tile.imgDiv.style.top = Math.round(newTopPos) + "px"; 636 637 //set new width and height 638 tile.imgDiv.style.width = Math.round(newTileSize.w) + "px"; 639 tile.imgDiv.style.height = Math.round(newTileSize.h) + "px"; 640 } 641 } 642 } 643 } 644 } 645 return true; 646 }, 647 648 /** 649 * Reposition and resize the zoomOut tile to prevent a white frame 650 * during zoomOut. 651 * share scale algorithm with other baselayers 652 * 653 * @param {float} newZoomlevel 654 * @param {float} newResolution 655 * 656 * @returns true if zoomOutTile is scaled, otherwise false 657 * @type Boolean 658 */ 659 scaleZoomOutTile: function(newZoomlevel, newResolution) { 660 if (this.zoomOutTile) { 661 this.scaleZoomOutTile_share(newZoomlevel, newResolution); 662 return true; 663 } 664 else { 665 return false; 666 } 667 }, 668 669 /** 670 * Clones layerContainer for "smooth tile update". 671 * So, it gets no blank map while map is loading in new zoomlevel. 672 * 673 * @returns true after layerContainer is cloned 674 * @type Boolean 675 */ 676 cloneBaseLayerDiv:function() { 677 // share clone algorithm with other baselayers 678 this.cloneBaseLayerDiv_share(); 679 680 // remove all old imgDiv tiles 681 // (so it doesn't becomes complicate with the same imgDivs of the 682 // cloned layerContainerDiv) 683 for (iRow=0; iRow<this.grid.length; iRow++){ 684 for (iCol=0; iCol<this.grid[iRow].length; iCol++){ 685 var tile = this.grid[iRow][iCol]; 686 if (tile.imgDiv) 687 this.div.removeChild(tile.imgDiv); 688 } 689 } 690 //reset grid array 691 this.grid = new Array(); 692 693 return true; 694 }, 695 696 697 451 698 /** @final @type String */ 452 699 CLASS_NAME: "OpenLayers.Layer.Grid" 453 700 });
