Changeset 2635
- Timestamp:
- 03/09/07 11:29:58 (2 years ago)
- Files:
-
- sandbox/emanuel/animatedZooming/demo.html (modified) (4 diffs)
- sandbox/emanuel/animatedZooming/demo_frida31467.html (added)
- sandbox/emanuel/animatedZooming/demo_frida4326.html (added)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/OverviewMap.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js (modified) (3 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js (modified) (3 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js (modified) (7 diffs)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Tile/Image.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js (modified) (1 diff)
- sandbox/emanuel/animatedZooming/tests/list-tests.html (modified) (1 diff)
- sandbox/emanuel/animatedZooming/tests/test_Control_OverviewMap.html (modified) (2 diffs)
- sandbox/emanuel/animatedZooming/tests/test_Control_PanZoom.html (modified) (1 diff)
- sandbox/emanuel/animatedZooming/tests/test_Layer_WMS.html (modified) (1 diff)
- sandbox/emanuel/animatedZooming/tests/test_Map.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/emanuel/animatedZooming/demo.html
r2292 r2635 1 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 2 <head> 3 4 <title>Animated Zooming Demo</title> 5 <link rel="stylesheet" href="http://openlayers.org/website.css" type="text/css" /> 3 6 <style type="text/css"> 4 7 #map { 5 width: 100%;8 width: 99%; 6 9 height: 511px; 7 10 border: 1px solid black; 11 margin-right: 50px; 12 8 13 } 9 14 </style> 10 <title>Animated Zooming Demo</title> 11 15 16 <!-- this gmaps key generated for http://openlayers.org/dev/ --> 17 <script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script> 18 12 19 <script src="./lib/OpenLayers.js"></script> 13 20 <script type="text/javascript"> … … 19 26 tileSize: new OpenLayers.Size(256,256)}); 20 27 map.addControl(new OpenLayers.Control.PanZoomBar()); 21 map.addControl(new OpenLayers.Control.MouseToolbar());28 //map.addControl(new OpenLayers.Control.MouseToolbar()); 22 29 map.addControl(new OpenLayers.Control.KeyboardDefaults()); 23 30 map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); … … 48 55 transparent: "true", format: "image/png" }); 49 56 57 var satellite_google = new OpenLayers.Layer.Google( 58 "Google Maps (no animation)", 59 { type: G_NORMAL_MAP, 60 'maxZoomLevel':18} ); 61 62 50 63 dm_wms.setVisibility(false); 51 64 52 map.addLayers([ol_wms, ol_wms_untiled, imglayer, dm_wms]);65 map.addLayers([ol_wms, ol_wms_untiled, imglayer, satellite_google,dm_wms]); 53 66 54 67 if (!map.getCenter()) 68 //map.zoomTo(5,false); 55 69 map.zoomToMaxExtent(); 56 70 } … … 58 72 </script> 59 73 </head> 60 <body onload="init()"> 74 <body onload="init()" > 75 <div id="olbanner" style="height: 80px;"> 76 <img class="openlayersbannerimg" 77 src="http://www.openlayers.org/images/OpenLayers.trac.png" 78 style="height: 44px; width: 49px;border:0px" 79 alt="OpenLayers" /> 80 <a class="penlayersbanner" >OpenLayers</a><br> 81 <h3 style="font-weight: normal; font-size: 0.4em; margin: 0 0 0 75;"> 82 Demo with animated zooming and panning</h3> 83 </div> 84 <div id="mainnav" class="nav"><small> </small> 85 </div> 86 61 87 <div id="map"></div> 88 89 <small style="text-align: right; color:#000000; font-weight: normal; margin: 0 0 0 12;">animated zooming feature by <a href="mailto:emanuel(at)intevation.de"> Emanuel Schütze</a>, <a target="_blank" href="http://intevation.org">Intevation GmbH</a></small> 90 62 91 </body> 63 92 </html> sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/OverviewMap.js
r2295 r2635 351 351 this.createMap(); 352 352 } 353 354 this.updateOverview(); 355 }, 356 353 if(!this.isSuitableOverview()) { 354 this.updateOverview(); 355 } 356 this.updateRectToMap(); 357 this.updateOverview(); 358 }, 359 /** 360 * Determines if the overview map is suitable given the extent and 361 * resolution of the main map. 362 */ 363 isSuitableOverview: function() { 364 var mapExtent = this.map.getExtent(); 365 var maxExtent = this.map.maxExtent; 366 var testExtent = new OpenLayers.Bounds( 367 Math.max(mapExtent.left, maxExtent.left), 368 Math.max(mapExtent.bottom, maxExtent.bottom), 369 Math.min(mapExtent.right, maxExtent.right), 370 Math.min(mapExtent.top, maxExtent.top)); 371 var resRatio = this.ovmap.getResolution() / this.map.getResolution(); 372 return ((resRatio > this.minRatio) && 373 (resRatio <= this.maxRatio) && 374 (this.ovmap.getExtent().containsBounds(testExtent))); 375 }, 357 376 /* 358 377 * Updates the overview map. If the map is scaling (by zooming) the parameters sandbox/emanuel/animatedZooming/lib/OpenLayers/Control/PanZoomBar.js
r2292 r2635 154 154 var top = OpenLayers.Util.pagePosition(evt.object)[1]; 155 155 var levels = Math.floor((y - top)/this.zoomStopHeight); 156 157 // get current zoomlevel 158 this.map.zoomlevel_startScale = this.map.zoom; 159 160 // get current tile size (it's the base for scaling) 161 this.map.tileSize_startScale = this.map.baseLayer.getTileSize(); 162 163 // get tile, which contains the center of the viewport 164 this.map.centerTile = this.map.baseLayer.getCenterTile(); 165 166 //set all active overlays temporarily invisible 167 for (var i = 0; i < this.map.layers.length; i++) { 168 var layer = this.map.layers[i]; 169 if (!layer.isBaseLayer) { 170 this.map.layers[i].div.style.display = "none"; 171 } 172 } 173 174 175 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 176 //this.moveZoomBar((this.map.getNumZoomLevels() -1) - levels); 156 157 if (!this.map.zoomanimationActive) 158 this.map.zoomTo((this.map.getNumZoomLevels() -1) - levels); 159 177 160 OpenLayers.Event.stop(evt); 178 161 }, sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer.js
r2296 r2635 465 465 getResolution: function() { 466 466 var zoom = this.map.getZoom(); 467 if (zoom >= this.map.getNumZoomLevels()) 468 zoom = this.map.getNumZoomLevels() - 1; 467 469 return this.resolutions[zoom]; 468 470 }, … … 669 671 }, 670 672 673 671 674 /** 672 * Clones layerContainer for "smooth tile update". 673 * So, it gets no blank map while map is loading in new zoomlevel. 675 * Gets tile, which contains the center of the viewport. 676 * 677 * Default function; will override in subclasses, 678 * otherwise it returns null - that means: no scaling possible! 679 * 680 * @returns returns null if no center tile set 681 * @type OpenLayers.Tile 682 */ 683 getCenterTile:function() { 684 return null; 685 }, 686 687 688 /** 689 * Sets all tiles outside the viewport invisible. 690 * Only for baselayers with a grid of tiles. 674 691 * 675 692 * Default function; will override in subclasses, 676 693 * otherwise it returns false 677 694 * 678 * @returns false if no layerContainer cloned679 * @type Boolean 680 */ 681 cloneLayerContainer:function() {695 * @returns false if baselayer has no grid 696 * @type Boolean 697 */ 698 setTilesOutsideInvisible:function() { 682 699 return false; 683 },684 685 /**686 * The actual clone function:687 * Freeze current map while tiles of viewport are loading.688 *689 * special function; shares with some baselayers; calls from subclasses690 *691 */692 cloneLayerContainer_share:function() {693 // function for map only; not for overviewmap!694 if (this.map.div.id == "map") {695 // 1. clone layerContainerDiv with all childs (replace, if already exist)696 if (this.map.layerContainerDivClone){697 this.map.viewPortDiv.removeChild(this.map.layerContainerDivClone);698 this.map.layerContainerDivClone = null;699 }700 this.map.layerContainerDivClone = this.map.layerContainerDiv.cloneNode(true);701 this.map.layerContainerDivClone.id = "map_OpenLayers_Container_clone";702 703 // 2. append layerContainerDivClone to viewPortDiv704 // (now the cloned div is above the original; it hides the original)705 this.map.viewPortDiv.appendChild(this.map.layerContainerDivClone);706 707 // 3. set original div invisible during the tiles are loading708 this.map.layerContainerDiv.style.display= "none";709 }710 },711 712 713 /**714 * Sets visibility of map after zoomend/loadend:715 * - freezed/cloned layerContainer invisible716 * - zoomOutTile invisibile717 *718 * Calls automatically after fire loadend event.719 */720 setLoadendVisibility: function() {721 // function for map only; not for overviewmap!722 if (this.map.div.id == "map") {723 // set zoomOutTile invisible724 if (this.map.baseLayer.zoomOutTile){725 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none";726 }727 // set cloned layerDiv invisibile and original div visible728 if (this.map.layerContainerDivClone){729 this.map.layerContainerDiv.style.display= "block";730 this.map.layerContainerDivClone.style.display= "none";731 }732 }733 734 // set flag that zoom animation finished735 this.map.zoomanimationActive = false;736 },737 738 /**739 * Gets tile, which contains the center of the viewport.740 *741 * Default function; will override in subclasses,742 * otherwise it returns null - that means: no scaling possible!743 *744 * @returns returns null if no center tile set745 * @type OpenLayers.Tile746 */747 getCenterTile:function() {748 return null;749 700 }, 750 701 … … 884 835 }, 885 836 837 /** 838 * Clones layerContainer for "smooth tile update". 839 * So, it gets no blank map while map is loading in new zoomlevel. 840 * 841 * Default function; will override in subclasses, 842 * otherwise it returns false 843 * 844 * @returns false if no layerContainer cloned 845 * @type Boolean 846 */ 847 cloneBaseLayerDiv:function() { 848 return false; 849 }, 850 851 /** 852 * The actual clone function: 853 * Freeze current map while tiles of viewport are loading. 854 * 855 * special function; shares with some baselayers; calls from subclasses 856 * 857 */ 858 cloneBaseLayerDiv_share:function() { 859 // function for map only; not for overviewmap! 860 if (this.map.div.id == "map") { 861 862 // 1. clone baseLayerDiv with all childs (replace, if already exist) 863 if (this.map.baseLayerDivClone){ 864 this.map.layerContainerDiv.removeChild(this.map.baseLayerDivClone); 865 this.map.baseLayerDivClone = null; 866 } 867 this.map.baseLayerDivClone = this.map.baseLayer.div.cloneNode(true); 868 this.map.baseLayerDivClone.id = 869 this.map.baseLayer.div.id + "_clone"; 870 871 872 // 2. append baseLayerDivClone to layerContainer 873 // (now the cloned div is above the original; it hides the original) 874 this.map.layerContainerDiv.appendChild(this.map.baseLayerDivClone); 875 876 // 3. set zIndex 877 this.map.baseLayerDivClone.style.zIndex--; 878 879 // 4. set original div invisible during the tiles are loading 880 //this.map.layerContainerDiv.style.display= "none"; 881 882 // 5. set zoomOut tile (of original div) invisible 883 if (this.map.baseLayer.zoomOutTile) 884 this.map.baseLayer.zoomOutTile.imgDiv.style.display = "none"; 885 886 // 5. adjust left and top position 887 // (if map is panning before, layerContainer is displaced) 888 if (this.map.layerContainerDiv.style.left != "") 889 this.map.baseLayerDivClone.style.left += 890 parseInt(this.map.layerContainerDiv.style.left); 891 if (this.map.layerContainerDiv.style.top != "") 892 this.map.baseLayerDivClone.style.top += 893 parseInt(this.map.layerContainerDiv.style.top); 894 } 895 }, 896 897 898 /** 899 * Sets visibility of map after zoomend/loadend: 900 * - freezed/cloned layerContainer invisible 901 * - zoomOutTile invisibile 902 * 903 * Calls automatically after fire loadend event. 904 */ 905 setLoadendVisibility: function() { 906 // function for map only; not for overviewmap! 907 if (this.map.div.id == "map") { 908 // remove cloned baseLayerDiv 909 if (this.map.baseLayerDivClone){ 910 this.map.layerContainerDiv.removeChild(this.map.baseLayerDivClone); 911 this.map.baseLayerDivClone = null; 912 } 913 } 914 915 // set flag that zoom animation finished 916 this.map.zoomanimationActive = false; 917 }, 918 886 919 887 920 /** @final @type String */ sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Grid.js
r2296 r2635 173 173 */ 174 174 _initTiles:function() { 175 if (this.map.div.id.match("overviewMap"))176 this.buffer = 1; 175 /*if (this.map.div.id.match("overviewMap")) 176 this.buffer = 1;*/ 177 177 178 178 // work out mininum number of rows and columns; this is the number of … … 569 569 }, 570 570 571 572 /** 573 * Sets all tiles outside the viewport invisible. 574 * Only for baselayers with a grid of tiles. 575 * 576 * @returns true if tiles are set invisible 577 * @type Boolean 578 */ 579 setTilesOutsideInvisible:function() { 580 var extent = this.map.getExtent(); 581 var layerGrid = this.map.baseLayer.grid; 582 583 // go through the whole grid 584 for (var iRow=0; iRow < layerGrid.length; iRow++) { 585 for (var iCol=0; iCol < layerGrid[iRow].length; iCol++) { 586 var tile = layerGrid[iRow][iCol]; 587 if (tile.imgDiv) { 588 // scale all (visible) tiles within the viewport 589 if (!extent.containsBounds(tile.bounds,true, false)) 590 tile.imgDiv.style.display = "none"; 591 } 592 } 593 } 594 return true; 595 }, 596 597 571 598 /** 572 599 * Scales all tiles of a grid to the new tile size … … 647 674 * @type Boolean 648 675 */ 649 clone LayerContainer:function() {676 cloneBaseLayerDiv:function() { 650 677 // share clone algorithm with other baselayers 651 this.clone LayerContainer_share();678 this.cloneBaseLayerDiv_share(); 652 679 653 680 // remove all old imgDiv tiles sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/Image.js
r2296 r2635 213 213 * @type Boolean 214 214 */ 215 clone LayerContainer:function() {215 cloneBaseLayerDiv:function() { 216 216 // share clone algorithm with other baselayers 217 this.clone LayerContainer_share();217 this.cloneBaseLayerDiv_share(); 218 218 219 219 // remove the old imgDiv tile sandbox/emanuel/animatedZooming/lib/OpenLayers/Layer/WMS/Untiled.js
r2296 r2635 313 313 * @type Boolean 314 314 */ 315 clone LayerContainer:function() {315 cloneBaseLayerDiv:function() { 316 316 // share clone algorithm with other baselayers 317 this.clone LayerContainer_share();317 this.cloneBaseLayerDiv_share(); 318 318 319 319 // remove the old imgDiv tile sandbox/emanuel/animatedZooming/lib/OpenLayers/Map.js
r2296 r2635 55 55 56 56 /** @type HTMLDivElement */ 57 layerContainerDivClone: null,57 baseLayerDivClone: null, 58 58 59 59 /** ordered list of layers in the map … … 145 145 * 146 146 * @type int */ 147 slideWait: 0,147 slideWait: 2, 148 148 149 149 /** power used to calculate width of slide steps … … 527 527 528 528 // preload a bigger tile for zooming out (not supported 529 // for every baselayer!) 530 this.baseLayer.setZoomOutTile(); 529 // for every baselayer! for map only; not for ovmap!) 530 if (this.div.id == "map") 531 this.baseLayer.setZoomOutTile(); 531 532 532 533 // Increment viewRequestID since the baseLayer is … … 1314 1315 this.centerTile = this.baseLayer.getCenterTile(); 1315 1316 1316 // set all active overlays temporarily invisible1317 // set all active overlays temporarily invisible 1317 1318 for (var i = 0; i < this.layers.length; i++) { 1318 1319 var layer = this.layers[i]; … … 1320 1321 this.layers[i].div.style.display = "none"; 1321 1322 } 1322 } 1323 } 1324 1325 // set all tiles outside the viewport invisible 1326 // (only for baselayers with grid of tiles) 1327 this.baseLayer.setTilesOutsideInvisible(); 1323 1328 }, 1324 1329 … … 1380 1385 finishZoomAnimation:function(finalZoomlevel) { 1381 1386 // clone layerContainer for "smooth tile update" without blank map 1382 this.baseLayer.clone LayerContainer();1387 this.baseLayer.cloneBaseLayerDiv(); 1383 1388 1384 1389 // zooom to final zoomlevel … … 1390 1395 // for all other layers it calls automatically from 1391 1396 // loadendevent in layers.js 1392 if ( this.baseLayer.CLASS_NAME == "OpenLayers.Layer.Image"){1397 if (!this.baseLayer.CLASS_NAME.match("OpenLayers.Layer.WMS")){ 1393 1398 this.zoomanimationActive = false; 1394 1399 } sandbox/emanuel/animatedZooming/lib/OpenLayers/Tile/Image.js
r2275 r2635 55 55 } 56 56 57 if (!this.url) 58 this.url = this.layer.getURL(this.bounds); 57 this.url = this.layer.getURL(this.bounds); 59 58 60 59 this.imgDiv.viewRequestID = this.layer.map.viewRequestID; sandbox/emanuel/animatedZooming/lib/OpenLayers/Util.js
r2296 r2635 230 230 // this code that turns its display on). 231 231 // 232 if (!this.viewRequestID ||233 (this.map && this.viewRequestID == this.map.viewRequestID)) {232 if (!this.viewRequestID || 233 (this.map && this.viewRequestID == this.map.viewRequestID)) { 234 234 this.style.backgroundColor = null; 235 235 this.style.display = ""; 236 }236 } 237 237 }; 238 238 sandbox/emanuel/animatedZooming/tests/list-tests.html
r2244 r2635 1 1 <ul id="testlist"> 2 <li>test_wait.html</li> 2 3 <li>test_Class.html</li> 3 4 <li>test_Pixel.html</li> sandbox/emanuel/animatedZooming/tests/test_Control_OverviewMap.html
r1701 r2635 25 25 function test_03_Control_PanZoom_control_events (t) { 26 26 t.plan( 10 ); 27 var evt = {which: 1}; // control expects left-click27 var evt = {which: 2}; // control expects left-click 28 28 map = new OpenLayers.Map('map'); 29 29 var layer = new OpenLayers.Layer.WMS("Test Layer", … … 44 44 t.eq(overviewZoom, 8, "Overviewmap zoomcorrect"); 45 45 46 control.mapDiv Click({'xy':new OpenLayers.Pixel(5,5)});46 control.mapDivDblClick({'xy':new OpenLayers.Pixel(5,5)}); 47 47 48 48 var cent = map.getCenter(); 49 t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon"); 50 t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); 49 t.eq(cent.lon, -71, "Clicking on the Overview Map has the correct effect on map lon"); 50 t.eq(cent.lat, 42, "Clicking on the Overview Map has the correct effect on map lat"); 51 //TODO: 52 //t.eq(cent.lon, -71.3515625, "Clicking on the Overview Map has the correct effect on map lon"); 53 //t.eq(cent.lat, 42.17578125, "Clicking on the Overview Map has the correct effect on map lat"); 51 54 52 55 control.rectMouseDown({'xy':new OpenLayers.Pixel(5,5), 'which':1}); sandbox/emanuel/animatedZooming/tests/test_Control_PanZoom.html
r1634 r2635 42 42 map.setCenter(centerLL, 5); 43 43 44 45 t.delay_call(8,function() { 44 46 control.buttons[0].onmousedown(evt); 47 }); 45 48 t.ok( map.getCenter().lat > centerLL.lat, "Pan up works correctly" ); 46 49 sandbox/emanuel/animatedZooming/tests/test_Layer_WMS.html
r2237 r2635 54 54 t.eq( tile.imgDiv.style.left, "5px", "image top is set correctly via addtile" ); 55 55 56 var firstChild = layer.div.firstChild;56 var lastChild = layer.div.lastChild; 57 57 if (!isMozilla) 58 58 t.ok( true, "skipping element test outside of Mozilla"); 59 59 else 60 t.ok( firstChild instanceof HTMLElement, "div first child is an image object" );61 t.eq( firstChild.src,60 t.ok( lastChild instanceof HTMLElement, "div first child is an image object" ); 61 t.eq( lastChild.src, 62 62 url + "?" + OpenLayers.Util.getParameterString(tParams), 63 63 "div first child is correct image object" ); sandbox/emanuel/animatedZooming/tests/test_Map.html
r1643 r2635 2 2 <head> 3 3 <script src="../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); 6 var map; 7 function test_01_Map_constructor (t) { 8 t.plan( 9 ); 9 10 map = new OpenLayers.Map('map'); // no longer need to call $(), constructor does it 11 var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 12 "http://octo.metacarta.com/cgi-bin/mapserv?", 13 {map: "/mapdata/vmap_wms.map", layers: "basic"}); 14 map.addLayer(baseLayer); 4 <script src="testMap.js"></script> 15 5 16 t.ok( map instanceof OpenLayers.Map, "new OpenLayers.Map returns object" );17 if (!isMozilla) {18 t.ok( true, "skipping element test outside of Mozilla");19 t.ok( true, "skipping element test outside of Mozilla");20 t.ok( true, "skipping element test outside of Mozilla");21 } else {22 t.ok( map.div instanceof HTMLDivElement, "map.div is an HTMLDivElement" );23 t.ok( map.viewPortDiv instanceof HTMLDivElement, "map.viewPortDiv is an HTMLDivElement" );24 t.ok( map.layerContainerDiv instanceof HTMLDivElement, "map.layerContainerDiv is an HTMLDivElement" );25 }26 t.ok( map.layers instanceof Array, "map.layers is an Array" );27 t.ok( map.controls instanceof Array, "map.controls is an Array" );28 t.ok( map.events instanceof OpenLayers.Events, "map.events is an OpenLayers.Events" );29 t.ok( map.getMaxExtent() instanceof OpenLayers.Bounds, "map.maxExtent is an OpenLayers.Bounds" );30 t.ok( map.getNumZoomLevels() > 0, "map has a default numZoomLevels" );31 }32 function test_02_Map_center(t) {33 t.plan(3);34 map = new OpenLayers.Map($('map'));35 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",36 "http://octo.metacarta.com/cgi-bin/mapserv?",37 {map: "/mapdata/vmap_wms.map", layers: "basic"});38 map.addLayer(baseLayer);39 var ll = new OpenLayers.LonLat(2,1);40 map.setCenter(ll, 0);41 t.ok( map.getCenter() instanceof OpenLayers.LonLat, "map.getCenter returns a LonLat");42 t.eq( map.getZoom(), 0, "map.zoom is correct after calling setCenter");43 t.ok( map.getCenter().equals(ll), "map center is correct after calling setCenter");44 }45 function test_03_Map_add_layers(t) {46 t.plan(6);47 map = new OpenLayers.Map($('map'));48 var layer1 = new OpenLayers.Layer.WMS("Layer 1",49 "http://octo.metacarta.com/cgi-bin/mapserv?",50 {map: "/mapdata/vmap_wms.map", layers: "basic"});51 var layer2 = new OpenLayers.Layer.WMS("Layer 2",52 "http://wms.jpl.nasa.gov/wms.cgi", {layers: "modis,global_mosaic"});53 // this uses map.addLayer internally54 map.addLayers([layer1, layer2])55 t.eq( map.layers.length, 2, "map has exactly two layers" );56 t.ok( map.layers[0] === layer1, "1st layer is layer1" );57 t.ok( map.layers[1] === layer2, "2nd layer is layer2" );58 t.ok( layer1.map === map, "layer.map is map" );59 t.eq( parseInt(layer1.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'],60 "layer1 zIndex is set" );61 t.eq( parseInt(layer2.div.style.zIndex), map.Z_INDEX_BASE['BaseLayer'] + 5,62 "layer2 zIndex is set" );63 }64 function test_04_Map_options(t) {65 t.plan(3);66 map = new OpenLayers.Map($('map'), {numZoomLevels: 6, maxResolution: 3.14159, theme: 'foo'});67 t.eq( map.numZoomLevels, 6, "map.numZoomLevels set correctly via options hashtable" );68 t.eq( map.maxResolution, 3.14159, "map.maxResolution set correctly via options hashtable" );69 t.eq( map.theme, 'foo', "map theme set correctly." );70 }71 function test_05_Map_center(t) {72 t.plan(4);73 map = new OpenLayers.Map($('map'));74 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",75 "http://octo.metacarta.com/cgi-bin/mapserv?",76 {map: "/mapdata/vmap_wms.map", layers: "basic"} );77 map.addLayer(baseLayer);78 var ll = new OpenLayers.LonLat(2,1);79 map.setCenter(ll, 0);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");85 6 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 */96 }97 98 function test_06_Map_zoomend_event (t) {99 t.plan(2);100 map = new OpenLayers.Map('map');101 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",102 "http://octo.metacarta.com/cgi-bin/mapserv?",103 {map: "/mapdata/vmap_wms.map", layers: "basic"});104 map.addLayer(baseLayer);105 map.events.register("zoomend", {count: 0}, function() {106 this.count++;107 t.ok(true, "zoomend event was triggered " + this.count + " times");108 });109 map.setCenter(new OpenLayers.LonLat(2, 1), 0);110 map.zoomIn();111 map.zoomOut();112 }113 114 function test_07_Map_add_remove_popup (t) {115 t.plan(4);116 117 map = new OpenLayers.Map('map');118 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",119 "http://octo.metacarta.com/cgi-bin/mapserv?",120 {map: "/mapdata/vmap_wms.map", layers: "basic"});121 map.addLayer(baseLayer);122 123 var popup = new OpenLayers.Popup("chicken",124 new OpenLayers.LonLat(0,0),125 new OpenLayers.Size(200,200));126 map.setCenter(new OpenLayers.LonLat(0, 0), 0);127 128 map.addPopup(popup);129 var pIndex = OpenLayers.Util.indexOf(map.popups, popup);130 t.eq(pIndex, 0, "popup successfully added to Map's internal popups array");131 132 var nodes = map.layerContainerDiv.childNodes;133 134 var found = false;135 for (var i=0; i < nodes.length; i++) {136 if (nodes.item(i) == popup.div) {137 found = true;138 break;139 }140 }141 t.ok(found, "popup.div successfully added to the map's viewPort");142 143 144 map.removePopup(popup);145 var pIndex = OpenLayers.Util.indexOf(map.popups, popup);146 t.eq(pIndex, -1, "popup successfully removed from Map's internal popups array");147 148 var found = false;149 for (var i=0; i < nodes.length; i++) {150 if (nodes.item(i) == popup.div) {151 found = true;152 break;153 }154 }155 t.ok(!found, "popup.div successfully removed from the map's viewPort");156 }157 /*** THIS IS A GOOD TEST, BUT IT SHOULD BE MOVED TO WMS.158 * Also, it won't work until we figure out the viewSize bug159 160 function 08_Map_px_lonlat_translation (t) {161 t.plan( 6 );162 map = new OpenLayers.Map($('map'));163 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",164 "http://octo.metacarta.com/cgi-bin/mapserv?",165 {map: "/mapdata/vmap_wms.map", layers: "basic"});166 map.addLayer(baseLayer);167 map.setCenter(new OpenLayers.LonLat(0, 0), 0);168 169 var pixel = new OpenLayers.Pixel(50,150);170 var lonlat = map.getLonLatFromViewPortPx(pixel);171 t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFromViewPortPx returns valid OpenLayers.LonLat" );172 173 var newPixel = map.getViewPortPxFromLonLat(lonlat);174 t.ok( newPixel instanceof OpenLayers.Pixel, "getViewPortPxFromLonLat returns valid OpenLayers.Pixel" );175 176 // WARNING!!! I'm faily sure that the following test's validity177 // depends highly on rounding and the resolution. For now,178 // in the default case, it seems to work. This may not179 // always be so.180 t.ok( newPixel.equals(pixel), "Translation to pixel and back to lonlat is consistent");181 182 lonlat = map.getLonLatFromPixel(pixel);183 t.ok( lonlat instanceof OpenLayers.LonLat, "getLonLatFromPixel returns valid OpenLayers.LonLat" );184 185 newPixel = map.getPixelFromLonLat(lonlat);186 t.ok( newPixel instanceof OpenLayers.Pixel, "getPixelFromLonLat returns valid OpenLayers.Pixel" );187 188 t.ok( newPixel.equals(pixel), "2nd translation to pixel and back to lonlat is consistent");189 }190 */191 function test_09_Map_isValidLonLat(t) {192 t.plan( 3 );193 map = new OpenLayers.Map($('map'));194 layer = new OpenLayers.Layer.WMS('Test Layer',195 "http://octo.metacarta.com/cgi-bin/mapserv",196 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},197 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );198 map.addLayer(layer);199 200 t.ok( !map.isValidLonLat(null), "null lonlat is not valid" );201 t.ok( map.isValidLonLat(new OpenLayers.LonLat(33862, 717606)), "lonlat outside max extent is valid" );202 t.ok( !map.isValidLonLat(new OpenLayers.LonLat(10, 10)), "lonlat outside max extent is not valid" );203 }204 205 function test_10_Map_getLayer(t) {206 t.plan( 2 );207 map = new OpenLayers.Map($('map'));208 layer = new OpenLayers.Layer.WMS('Test Layer',209 "http://octo.metacarta.com/cgi-bin/mapserv",210 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},211 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );212 213 map.addLayer(layer);214 var gotLayer = map.getLayer(layer.id);215 216 t.ok( layer == gotLayer, "getLayer correctly returns layer" );217 218 gotLayer = map.getLayer("chicken");219 220 t.ok( gotLayer == null, "getLayer correctly returns null when layer not found");221 }222 223 function test_10_Map_setBaseLayer(t) {224 t.plan( 4 );225 226 map = new OpenLayers.Map($('map'));227 228 var wmslayer = new OpenLayers.Layer.WMS('Test Layer',229 "http://octo.metacarta.com/cgi-bin/mapserv",230 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},231 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );232 233 var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2',234 "http://octo.metacarta.com/cgi-bin/mapserv",235 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},236 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );237 238 map.addLayers([wmslayer, wmslayer2]);239 240 t.ok(map.baseLayer == wmslayer, "default base layer is first one added");241 242 map.setBaseLayer(null);243 t.ok(map.baseLayer == wmslayer, "setBaseLayer on null object does nothing (and does not break)");244 245 map.setBaseLayer("chicken");246 t.ok(map.baseLayer == wmslayer, "setBaseLayer on non-layer object does nothing (and does not break)");247 248 map.setBaseLayer(wmslayer2);249 t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");250 251 }252 253 function test_12_Map_moveLayer (t) {254 t.plan(10);255 var ct = 0;256 map = new OpenLayers.Map($('map'));257 var wmslayer = new OpenLayers.Layer.WMS('Test Layer',258 "http://octo.metacarta.com/cgi-bin/mapserv",259 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},260 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );261 262 var wmslayer2 = new OpenLayers.Layer.WMS('Test Layer2',263 "http://octo.metacarta.com/cgi-bin/mapserv",264 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},265 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );266 267 var wmslayer3 = new OpenLayers.Layer.WMS('Test Layer2',268 "http://octo.metacarta.com/cgi-bin/mapserv",269 {map: '/mapdata/vmap_wms.map', layers: 'basic', format: 'image/jpeg'},270 {maxExtent: new OpenLayers.Bounds(33861, 717605, 330846, 1019656), maxResolution: 296985/1024, projection:"EPSG:2805" } );271 272 map.addLayers([wmslayer, wmslayer2, wmslayer3]);273 map.events.register("changelayer", map, function (e) { ct++; });274 t.eq( map.getNumLayers(), 3, "getNumLayers returns the number of layers" );275 t.eq( map.getLayerIndex(wmslayer3), 2, "getLayerIndex returns the right index" );276 map.raiseLayer(wmslayer3, 1);277 &n
