Ticket #487: dateline.patch
| File dateline.patch, 29.5 kB (added by euzuro, 1 year ago) |
|---|
-
tests/BaseTypes/test_LonLat.html
old new 88 88 t.ok( lonlat.equals(ll), "lonlat is set correctly"); 89 89 } 90 90 91 function test_08_LonLat_wrapDateLine(t) { 92 t.plan( 6 ); 93 94 var goodLL = new OpenLayers.LonLat(0,0); 95 var testLL, wrappedLL; 96 97 //bad maxextent 98 var maxExtent = null; 99 100 testLL = goodLL.clone(); 101 wrappedLL = testLL.wrapDateLine(maxExtent); 102 t.ok(wrappedLL.equals(goodLL), "wrapping a ll with a bad maxextent does nothing"); 103 104 105 //good maxextent 106 maxExtent = new OpenLayers.Bounds(-10,-10,10,10); 107 108 //inside 109 testLL = goodLL.clone(); 110 wrappedLL = testLL.wrapDateLine(maxExtent); 111 t.ok(wrappedLL.equals(goodLL), "wrapping a ll within the maxextent does nothing"); 112 113 //left 114 testLL = goodLL.add(-20,0); 115 wrappedLL = testLL.wrapDateLine(maxExtent); 116 t.ok(wrappedLL.equals(goodLL), "wrapping a ll once left of maxextent works"); 117 118 //way left 119 testLL = goodLL.add(-200,0); 120 wrappedLL = testLL.wrapDateLine(maxExtent); 121 t.ok(wrappedLL.equals(goodLL), "wrapping a ll way left of maxextent works"); 122 123 //right 124 testLL = goodLL.add(20,0); 125 wrappedLL = testLL.wrapDateLine(maxExtent); 126 t.ok(wrappedLL.equals(goodLL), "wrapping a ll once right of maxextent works"); 127 128 //way right 129 testLL = goodLL.add(200,0); 130 wrappedLL = testLL.wrapDateLine(maxExtent); 131 t.ok(wrappedLL.equals(goodLL), "wrapping a ll way right of maxextent works"); 132 133 } 134 91 135 // --> 92 136 </script> 93 137 </head> -
tests/BaseTypes/test_Bounds.html
old new 379 379 (bounds.top == object.y)), "obj Point to extends correclty modifies right and top"); 380 380 381 381 } 382 383 384 function test_16_Bounds_wrapDateLine(t) { 385 t.plan( 13 ); 386 387 var testBounds, wrappedBounds, desiredBounds; 382 388 389 var maxExtent = new OpenLayers.Bounds(-10,-10,10,10); 390 var exactBounds = maxExtent.clone(); 391 var simpleBounds = new OpenLayers.Bounds( -5,-5,5,5); 392 393 394 395 //bad maxextent 396 testBounds = simpleBounds.clone(); 397 wrappedBounds = testBounds.wrapDateLine(null); 398 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds with a bad maxextent does nothing"); 399 400 401 402 //exactly inside 403 testBounds = exactBounds.clone(); 404 wrappedBounds = testBounds.wrapDateLine(maxExtent); 405 t.ok(wrappedBounds.equals(exactBounds), "wrapping a bounds precisely within (equal to) maxextent does nothing"); 406 407 408 //inside 409 testBounds = simpleBounds.clone(); 410 wrappedBounds = testBounds.wrapDateLine(maxExtent); 411 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds within maxextent does nothing"); 412 413 // LEFT // 414 415 //straddling left 416 testBounds = simpleBounds.add(-10,0); 417 wrappedBounds = testBounds.wrapDateLine(maxExtent); 418 t.ok(wrappedBounds.equals(testBounds), "wrapping a bounds that straddles the left of maxextent does nothing"); 419 420 //left rightTolerance 421 testBounds = simpleBounds.add(-14,0); 422 wrappedBounds = 423 testBounds.wrapDateLine(maxExtent, {'rightTolerance': 1} ); 424 desiredBounds = simpleBounds.add(6,0); 425 t.ok(wrappedBounds.equals(desiredBounds), "wrapping a bounds rightTolerance left of maxextent works"); 426 427 //exactly left 428 testBounds = exactBounds.add(-20,0); 429 wrappedBounds = testBounds.wrapDateLine(maxExtent); 430 t.ok(wrappedBounds.equals(exactBounds), "wrapping an exact bounds once left of maxextent works"); 431 432 //left 433 testBounds = simpleBounds.add(-20,0); 434 wrappedBounds = testBounds.wrapDateLine(maxExtent); 435 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds once left of maxextent works"); 436 437 //way left 438 testBounds = simpleBounds.add(-200,0); 439 wrappedBounds = testBounds.wrapDateLine(maxExtent); 440 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds way left of maxextent works"); 441 442 // RIGHT // 443 444 //straddling right 445 testBounds = simpleBounds.add(10,0); 446 wrappedBounds = testBounds.wrapDateLine(maxExtent); 447 t.ok(wrappedBounds.equals(testBounds), "wrapping a bounds that straddles the right of maxextent does nothing"); 448 449 //right leftTolerance 450 testBounds = simpleBounds.add(14,0); 451 wrappedBounds = 452 testBounds.wrapDateLine(maxExtent, {'leftTolerance': 1} ); 453 desiredBounds = simpleBounds.add(-6,0); 454 t.ok(wrappedBounds.equals(desiredBounds), "wrapping a bounds leftTolerance right of maxextent works"); 455 456 //exactly right 457 testBounds = exactBounds.add(20,0); 458 wrappedBounds = testBounds.wrapDateLine(maxExtent); 459 t.ok(wrappedBounds.equals(exactBounds), "wrapping an exact bounds once right of maxextent works"); 460 461 //right 462 testBounds = simpleBounds.add(20,0); 463 wrappedBounds = testBounds.wrapDateLine(maxExtent); 464 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds once right of maxextent works"); 465 466 //way right 467 testBounds = simpleBounds.add(200,0); 468 wrappedBounds = testBounds.wrapDateLine(maxExtent); 469 t.ok(wrappedBounds.equals(simpleBounds), "wrapping a bounds way right of maxextent works"); 470 471 472 473 } 474 383 475 // --> 384 476 </script> 385 477 </head> -
tests/Layer/test_WrapDateLine.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); 6 var layer; 7 8 var name = 'Test Layer'; 9 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 10 var params = { map: '/mapdata/vmap_wms.map', 11 layers: 'basic', 12 format: 'image/png'}; 13 14 15 function test_Layer_WrapDateLine_adjustBounds(t) { 16 t.plan(10); 17 18 19 var map = new OpenLayers.Map('map'); 20 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); 21 map.addLayer(layer); 22 map.zoomToMaxExtent(); 23 var bounds = layer.adjustBounds(new OpenLayers.Bounds(-270,-90,-180,0)); 24 t.ok( bounds.equals(new OpenLayers.Bounds(90,-90,180,0)), "-270,-90,-180,0 wraps to 90,-90,180,0"); 25 bounds = layer.adjustBounds(new OpenLayers.Bounds(180,-90,270,0)); 26 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,-90,0)), "180,-90,270,0 wraps to -180,-90,-90,0"); 27 bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-90,0,0)); 28 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,0,0)), "-180,-90,0,0 doesn't wrap"); 29 bounds = layer.adjustBounds(new OpenLayers.Bounds(-181,-90,-179,0)); 30 t.ok( bounds.equals(new OpenLayers.Bounds(-181,-90,-179,0)), "-181,-90,-179,0 doesn't wrap, because it straddles the dateline"); 31 bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-180,-90,-90)); 32 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-180,-90,-90)), "-180,-180,-90,-90 doesn't wrap, because we don't wrap lats."); 33 layer = new OpenLayers.Layer.WMS(name, url, params); 34 map.addLayer(layer); 35 var testBounds = null; 36 var outBounds = null; 37 var testList = [ 38 new OpenLayers.Bounds(-270,-90,-180,0), 39 new OpenLayers.Bounds(180,-90,270,0), 40 new OpenLayers.Bounds(-180,-90,0,0), 41 new OpenLayers.Bounds(-181,-90,-179,0), 42 new OpenLayers.Bounds(-180,-180,-90,-90) 43 ]; 44 for (var i = 0; i < testList.length; i++) { 45 outBounds = layer.adjustBounds(testList[i]); 46 t.ok( outBounds.equals(testList[i]), testList[i]+" doesn't wrap in non-wrapping layer."); 47 } 48 } 49 function test_Layer_WrapDateLine_getLonLat(t) { 50 t.plan(12); 51 var map = new OpenLayers.Map('map'); 52 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); 53 map.addLayer(layer); 54 map.zoomToMaxExtent(); 55 var testLonLats = [ 56 new OpenLayers.LonLat(-185,5), 57 new OpenLayers.LonLat(-180,-95), 58 new OpenLayers.LonLat(-180,95), 59 new OpenLayers.LonLat(180,-95), 60 new OpenLayers.LonLat(180,95), 61 new OpenLayers.LonLat(185,5) 62 ]; 63 var outLonLats = [ 64 new OpenLayers.LonLat(175,5), 65 new OpenLayers.LonLat(-180,-95), 66 new OpenLayers.LonLat(-180,95), 67 new OpenLayers.LonLat(180,-95), 68 new OpenLayers.LonLat(180,95), 69 new OpenLayers.LonLat(-175,5) 70 ]; 71 72 for (var i = 0; i < testLonLats.length; i++) { 73 var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]); 74 var lonlat = layer.getLonLatFromViewPortPx(pixel); 75 lonlat.lon = Math.round(lonlat.lon); 76 lonlat.lat = Math.round(lonlat.lat); 77 t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")"); 78 } 79 80 layer = new OpenLayers.Layer.WMS(name, url, params); 81 map.addLayer(layer); 82 var outLonLats = [ 83 new OpenLayers.LonLat(-185,5), 84 new OpenLayers.LonLat(-180,-95), 85 new OpenLayers.LonLat(-180,95), 86 new OpenLayers.LonLat(180,-95), 87 new OpenLayers.LonLat(180,95), 88 new OpenLayers.LonLat(185,5) 89 ]; 90 for (var i = 0; i < testLonLats.length; i++) { 91 var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]); 92 var lonlat = layer.getLonLatFromViewPortPx(pixel); 93 lonlat.lon = Math.round(lonlat.lon); 94 lonlat.lat = Math.round(lonlat.lat); 95 t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")"); 96 } 97 98 } 99 function test_Layer_WrapDateLine_ZoomToExtent (t) { 100 t.plan( 4 ); 101 102 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 103 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); 104 var m = new OpenLayers.Map('map'); 105 m.addLayer(layer); 106 m.setCenter = function(myCenter) { this.center = myCenter; } 107 var testBounds = [ 108 new OpenLayers.Bounds(-185,-90,-175,-85), 109 new OpenLayers.Bounds(0,-90,-170,-85), 110 new OpenLayers.Bounds(-270,-90,-180,-85), 111 new OpenLayers.Bounds(0,0,45,45) 112 ]; 113 var outCenters = [ 114 new OpenLayers.LonLat(-180,-87.5), 115 new OpenLayers.LonLat(95,-87.5), 116 new OpenLayers.LonLat(135,-87.5), 117 new OpenLayers.LonLat(22.5,22.5) 118 ]; 119 for (var i = 0; i < testBounds.length; i++) { 120 m.zoomToExtent(testBounds[i]); 121 t.ok(m.center.equals(outCenters[i]), "Map center from bounds " + testBounds[i] + " should be " + outCenters[i] + ", got " + m.center); 122 } 123 124 125 } 126 function test_Layer_WrapDateLine_WMS (t) { 127 t.plan( 3 ); 128 129 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 130 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); 131 var m = new OpenLayers.Map('map'); 132 m.addLayer(layer); 133 m.zoomToMaxExtent(); 134 t.eq(layer.grid[3][0].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=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "cell [3][0] is wrapped around the world."); 135 t.eq(layer.grid[0][0].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=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "cell [0][0] is wrapped around the world lon, but not lat"); 136 t.eq(layer.grid[0][3].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=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "cell [3][0] is not wrapped at all."); 137 138 } 139 function test_Layer_WrapDateLine_KaMap (t) { 140 t.plan( 3 ); 141 142 var layer = new OpenLayers.Layer.KaMap( "Blue Marble NG", 143 "http://www.openlayers.org/world/index.php", 144 {g: "satellite", map: "world"}, 145 {wrapDateLine: true} ); 146 var m = new OpenLayers.Map('map'); 147 m.addLayer(layer); 148 m.zoomToMaxExtent(); 149 t.eq(layer.grid[0][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=0&s=221471921.25", "grid[0][0] kamap is okay"); 150 t.eq(layer.grid[0][3].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=-256&s=221471921.25", "grid[0][3] kamap is okay"); 151 t.eq(layer.grid[3][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[3][0] is okay"); 152 } 153 function test_Layer_WrapDateLine_WMS_Overlay (t) { 154 t.plan( 3 ); 155 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 156 baselayer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); 157 var layer = new OpenLayers.Layer.WMS( "DM Solutions Demo", 158 "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", 159 {layers: "bathymetry,land_fn,park,drain_fn,drainage," + 160 "prov_bound,fedlimit,rail,road,popplace", 161 transparent: "true", format: "image/png"}, 162 {wrapDateLine: true, reproject: false}); 163 var m = new OpenLayers.Map('map'); 164 m.addLayers([baselayer,layer]); 165 m.zoomToMaxExtent(); 166 t.eq(layer.grid[0][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "grid[0][0] wms overlay is okay"); 167 t.eq(layer.grid[0][3].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "grid[0][3] wms overlay is okay"); 168 t.eq(layer.grid[3][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "grid[3][0] wms overlay okay"); 169 } 170 // --> 171 </script> 172 </head> 173 <body> 174 <div id="map" style="width:1000px;height:550px"></div> 175 </body> 176 </html> -
tests/list-tests.html
old new 48 48 <li>Layer/test_TMS.html</li> 49 49 <li>Layer/test_Vector.html</li> 50 50 <li>Layer/test_GML.html</li> 51 <li>Layer/test_WrapDateLine.html</li> 51 52 <li>test_Tile.html</li> 52 53 <li>Tile/test_Image.html</li> 53 54 <li>test_Control.html</li> -
lib/OpenLayers/Layer.js
old new 139 139 140 140 /** @type Boolean */ 141 141 displayOutsideMaxExtent: false, 142 143 /** wrapDateLine -- #487 for more info. 144 * 145 * @type @Boolean 146 */ 147 wrapDateLine: false, 142 148 143 149 144 150 /** … … 165 171 this.events = new OpenLayers.Events(this, this.div, 166 172 this.EVENT_TYPES); 167 173 } 174 175 if (this.wrapDateLine) { 176 this.displayOutsideMaxExtent = true; 177 } 168 178 }, 169 179 170 180 /** … … 616 626 617 627 lonlat = new OpenLayers.LonLat(center.lon + delta_x * res , 618 628 center.lat - delta_y * res); 629 630 if (this.wrapDateLine) { 631 lonlat = lonlat.wrapDateLine(this.maxExtent); 632 } 619 633 } // else { DEBUG STATEMENT } 620 634 } 621 635 return lonlat; … … 642 656 }, 643 657 644 658 /** 645 * Adjusts the extent of a bounds in map units by the layer's gutter646 * in pixels.647 *648 * @param {OpenLayers.Bounds} bounds649 * @type OpenLayers.Bounds650 * @return A bounds adjusted in height and width by the gutter651 */652 adjustBoundsByGutter: function(bounds) {653 var mapGutter = this.gutter * this.map.getResolution();654 bounds = new OpenLayers.Bounds(bounds.left - mapGutter,655 bounds.bottom - mapGutter,656 bounds.right + mapGutter,657 bounds.top + mapGutter);658 return bounds;659 },660 661 /**662 659 * Sets the opacity for the entire layer (all images) 663 660 * @param {Float} opacity 664 661 */ … … 681 678 this.div.style.zIndex = zIdx; 682 679 }, 683 680 681 /** 682 * This function will take a bounds, and if wrapDateLine option is set 683 * on the layer, it will return a bounds which is wrapped around the world. 684 * We do not wrap for bounds which *cross* the maxExtent.left/right, only 685 * bounds which are entirely to the left or entirely to the right. 686 * 687 * @param {OpenLayers.Bounds} bounds 688 * @private 689 */ 690 adjustBounds: function (bounds) { 691 692 if (this.gutter) { 693 // Adjust the extent of a bounds in map units by the 694 // layer's gutter in pixels. 695 var mapGutter = this.gutter * this.map.getResolution(); 696 bounds = new OpenLayers.Bounds(bounds.left - mapGutter, 697 bounds.bottom - mapGutter, 698 bounds.right + mapGutter, 699 bounds.top + mapGutter); 700 } 701 702 if (this.wrapDateLine) { 703 // wrap around the date line, within the limits of rounding error 704 var wrappingOptions = { 705 'rightTolerance':this.getResolution() 706 }; 707 bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions); 708 709 } 710 return bounds; 711 }, 712 684 713 /** @final @type String */ 685 714 CLASS_NAME: "OpenLayers.Layer" 686 715 }; -
lib/OpenLayers/Map.js
old new 1168 1168 * @param {OpenLayers.Bounds} bounds 1169 1169 */ 1170 1170 zoomToExtent: function(bounds) { 1171 this.setCenter(bounds.getCenterLonLat(), 1172 this.getZoomForExtent(bounds)); 1171 var center = bounds.getCenterLonLat(); 1172 if (this.baseLayer.wrapDateLine) { 1173 var maxExtent = this.getMaxExtent(); 1174 1175 //fix straddling bounds (in the case of a bbox that straddles the 1176 // dateline, it's left and right boundaries will appear backwards. 1177 // we fix this by allowing a right value that is greater than the 1178 // max value at the dateline -- this allows us to pass a valid 1179 // bounds to calculate zoom) 1180 // 1181 bounds = bounds.clone(); 1182 while (bounds.right < bounds.left) { 1183 bounds.right += maxExtent.getWidth(); 1184 } 1185 //if the bounds was straddling (see above), then the center point 1186 // we got from it was wrong. So we take our new bounds and ask it 1187 // for the center. Because our new bounds is at least partially 1188 // outside the bounds of maxExtent, the new calculated center 1189 // might also be. We don't want to pass a bad center value to 1190 // setCenter, so we have it wrap itself across the date line. 1191 // 1192 center = bounds.getCenterLonLat().wrapDateLine(maxExtent); 1193 } 1194 this.setCenter(center, this.getZoomForExtent(bounds)); 1173 1195 }, 1174 1196 1175 1197 /** Zoom to the full extent and recenter. -
lib/OpenLayers/BaseTypes.js
old new 299 299 return equals; 300 300 }, 301 301 302 /** 303 * @param {OpenLayers.Bounds} maxExtent 304 * 305 * @returns A copy of this lonlat, but wrapped around the "dateline" (as 306 * specified by the borders of maxExtent) 307 * @type OpenLayers.LonLat 308 */ 309 wrapDateLine: function(maxExtent) { 310 311 var newLonLat = this.clone(); 312 313 if (maxExtent) { 314 //shift right? 315 while (newLonLat.lon < maxExtent.left) { 316 newLonLat.lon += maxExtent.getWidth(); 317 } 318 319 //shift left? 320 while (newLonLat.lon > maxExtent.right) { 321 newLonLat.lon -= maxExtent.getWidth(); 322 } 323 } 324 325 return newLonLat; 326 }, 327 302 328 /** @final @type String */ 303 329 CLASS_NAME: "OpenLayers.LonLat" 304 330 }; … … 666 692 return quadrant; 667 693 }, 668 694 695 /** 696 * @param {OpenLayers.Bounds} maxExtent 697 * @param {Object} options 698 * @option {float} leftTolerance Allow for a margin of error with the 699 * 'left' value of this bound. 700 * Default is 0 701 * @option {float} rightTolerance Allow for a margin of error with the 702 * 'right' value of this bound. 703 * Default is 0 704 * 705 * @returns A copy of this bounds, but wrapped around the "dateline" (as 706 * specified by the borders of maxExtent). Note that this 707 * function only returns a different bounds value if this bounds 708 * is *entirely* outside of the maxExtent. If this bounds 709 * straddles the dateline (is part in/part out of maxExtent), 710 * the returned bounds will be merely a copy of this one. 711 * @type OpenLayers.Bounds 712 */ 713 wrapDateLine: function(maxExtent, options) { 714 options = options || new Object(); 715 716 var leftTolerance = options.leftTolerance || 0; 717 var rightTolerance = options.rightTolerance || 0; 718 719 var newBounds = this.clone(); 720 721 if (maxExtent) { 722 723 //shift right? 724 while ( newBounds.left < maxExtent.left && 725 (newBounds.right - rightTolerance) <= maxExtent.left ) { 726 newBounds = newBounds.add(maxExtent.getWidth(), 0); 727 } 728 729 //shift left? 730 while ( (newBounds.left + leftTolerance) >= maxExtent.right && 731 newBounds.right > maxExtent.right ) { 732 newBounds = newBounds.add(-maxExtent.getWidth(), 0); 733 } 734 } 735 736 return newBounds; 737 }, 738 669 739 /** @final @type String */ 670 740 CLASS_NAME: "OpenLayers.Bounds" 671 741 }; -
lib/OpenLayers/Layer/MapServer.js
old new 87 87 * @type String 88 88 */ 89 89 getURL: function (bounds) { 90 if(this.gutter) { 91 bounds = this.adjustBoundsByGutter(bounds); 92 } 90 bounds = this.adjustBounds(bounds); 93 91 // Make a list, so that getFullRequestString uses literal "," 94 92 var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top]; 95 93 -
lib/OpenLayers/Layer/WMS.js
old new 94 94 * @type String 95 95 */ 96 96 getURL: function (bounds) { 97 if(this.gutter) { 98 bounds = this.adjustBoundsByGutter(bounds); 99 } 97 bounds = this.adjustBounds(bounds); 100 98 return this.getFullRequestString( 101 99 {BBOX:bounds.toBBOX(), 102 100 WIDTH:this.imageSize.w, -
lib/OpenLayers/Layer/WorldWind.js
old new 69 69 * @type String 70 70 */ 71 71 getURL: function (bounds) { 72 bounds = this.adjustBounds(bounds); 72 73 var zoom = this.getZoom(); 73 74 var extent = this.map.getMaxExtent(); 74 75 var deg = this.lzd/Math.pow(2,this.getZoom()); -
lib/OpenLayers/Layer/KaMap.js
old new 49 49 * @type String 50 50 */ 51 51 getURL: function (bounds) { 52 bounds = this.adjustBounds(bounds); 52 53 var mapRes = this.map.getResolution(); 53 54 var scale = Math.round((this.map.getScale() * 10000)) / 10000; 54 55 var pX = Math.round(bounds.left / mapRes); -
lib/OpenLayers/Layer/TMS.js
old new 71 71 * @type String 72 72 */ 73 73 getURL: function (bounds) { 74 bounds = this.adjustBounds(bounds); 74 75 var res = this.map.getResolution(); 75 76 var x = (bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w); 76 77 var y = (bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h); -
examples/wrapDateLine.html
old new 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <style type="text/css"> 4 #map { 5 width: 800px; 6 height: 475px; 7 border: 1px solid black; 8 } 9 </style> 10 <script src="../lib/OpenLayers.js"></script> 11 <script type="text/javascript"> 12 <!-- 13 var map; 14 function init(){ 15 map = new OpenLayers.Map( 'map', {maxResolution: 1.40625} ); 16 var mapserv = new OpenLayers.Layer.MapServer( "OpenLayers Basic", 17 "http://labs.metacarta.com/wms/vmap0", 18 {layers: 'basic'}, 19 {wrapDateLine: true} ); 20 21 var kamap = new OpenLayers.Layer.KaMap( "Blue Marble NG", 22 "http://www.openlayers.org/world/index.php", 23 {g: "satellite", map: "world"}, 24 {wrapDateLine: true} ); 25 26 var wms = new OpenLayers.Layer.WMS( "DM Solutions Demo", 27 "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", 28 {layers: "bathymetry,land_fn,park,drain_fn,drainage," + 29 "prov_bound,fedlimit,rail,road,popplace", 30 transparent: "true", format: "image/png"}, 31 {wrapDateLine: true, reproject: false}); 32 33 /* TMS is broken, too */ 34 tms = new OpenLayers.Layer.TMS( "OpenStreetMap", 35 "http://labs.metacarta.com/wms-c/Basic.py/", 36 {layername: 'osm-map', type:'png', wrapDateLine: true} ); 37 38 /* WW doesn't quite work yet */ 39 ww = new OpenLayers.Layer.WorldWind( "LANDSAT", 40 "http://worldwind25.arc.nasa.gov/tile/tile.aspx", 2.25, 4, 41 {T:"105"}, 42 {'maxResolution': .28125, 43 tileSize: new OpenLayers.Size(512, 512), 44 wrapDateLine: true}); 45 46 map.addLayers([mapserv, kamap, wms]); 47 map.addControl(new OpenLayers.Control.LayerSwitcher()); 48 map.addControl(new OpenLayers.Control.MousePosition()); 49 map.zoomToMaxExtent(); 50 } 51 // --> 52 </script> 53 </head> 54 <body onload="init()"> 55 <div id="map"></div> 56 <div id="docs"> 57 This is an example that shows wrapping the date line. Wrapping the 58 date line is an option on the layer. 59 </div> 60 </body> 61 </html>
