Ticket #482: gettilebounds.patch
| File gettilebounds.patch, 5.4 kB (added by crschmidt, 1 year ago) |
|---|
-
tests/Layer/test_Grid.html
old new 528 528 height = layer.tileSize.h; 529 529 t.ok(width == parseInt(width) && height == parseInt(height), "calculated tileSize width/height are integer values"); 530 530 } 531 function test_12_Layer_Grid_getTileBounds(t) { 532 t.plan(2); 533 var map = new OpenLayers.Map("map2"); 534 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 535 layer = new OpenLayers.Layer.WMS(name, url, params); 536 537 var newParams = { layers: 'sooper', 538 chickpeas: 'image/png'}; 531 539 540 map.addLayer(layer); 541 map.zoomToMaxExtent(); 542 map.zoomIn(); 543 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 544 t.eq(bounds.toBBOX(), "-180,-90,0,90", "get tile bounds returns correct bounds"); 545 map.pan(200,0); 546 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 547 t.eq(bounds.toBBOX(), "0,-90,180,90", "get tile bounds returns correct bounds after pan"); 548 } 549 532 550 function test_99_Layer_Grid_destroy (t) { 533 551 534 552 t.plan( 5 ); … … 563 581 </head> 564 582 <body> 565 583 <div id="map" style="width:499px;height:549px;display:none"></div> 584 <div id="map2" style="width:500px;height:550px;display:none"></div> 566 585 </body> 567 586 </html> -
tests/Layer/test_KaMap.html
old new 189 189 t.ok( layer.tileSize != null, "tileSize has been set"); 190 190 t.ok( (layer.tileSize.h == 50) && (layer.tileSize.w == 500), "tileSize has been set correctly"); 191 191 } 192 function test_12_Layer_KaMap_getTileBounds(t) { 193 t.plan(2); 194 var map = new OpenLayers.Map("map"); 195 var url = "http://octo.metacarta.com/cgi-bin/mapserv"; 196 layer = new OpenLayers.Layer.KaMap(name, url, params); 197 198 var newParams = { layers: 'sooper', 199 chickpeas: 'image/png'}; 192 200 201 map.addLayer(layer); 202 map.zoomToMaxExtent(); 203 map.zoomIn(); 204 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 205 t.eq(bounds.toBBOX(), "-180,0,0,180", "get tile bounds returns correct bounds"); 206 map.pan(200,0); 207 var bounds = layer.getTileBounds(new OpenLayers.Pixel(200,200)); 208 t.eq(bounds.toBBOX(), "0,0,180,180", "get tile bounds returns correct bounds after pan"); 209 } 210 193 211 function test_99_Layer_KaMap_destroy (t) { 194 212 195 213 t.plan( 3 ); -
lib/OpenLayers/Layer/Grid.js
old new 673 673 } 674 674 }, 675 675 676 /** 677 * APIMethod: getTileBounds 678 * Returns The tile bounds for a layer given a pixel location 679 * 680 * Parameters: 681 * viewPortPx - {OpenLayers.Pixel} The location in the viewport 682 */ 683 getTileBounds: function(viewPortPx) { 684 var maxExtent = this.map.getMaxExtent(); 685 var resolution = this.getResolution(); 686 var tileMapWidth = resolution * this.tileSize.w; 687 var tileMapHeight = resolution * this.tileSize.h; 688 var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); 689 var tileLeft = maxExtent.left + (tileMapWidth * 690 Math.floor((mapPoint.lon - 691 maxExtent.left) / 692 tileMapWidth)); 693 var tileBottom = maxExtent.bottom + (tileMapHeight * 694 Math.floor((mapPoint.lat - 695 maxExtent.bottom) / 696 tileMapHeight)); 697 return new OpenLayers.Bounds(tileLeft, tileBottom, 698 tileLeft + tileMapWidth, 699 tileBottom + tileMapHeight); 700 }, 701 676 702 CLASS_NAME: "OpenLayers.Layer.Grid" 677 703 }); -
lib/OpenLayers/Layer/KaMap.js
old new 225 225 226 226 return obj; 227 227 }, 228 229 /** 230 * APIMethod: getTileBounds 231 * Returns The tile bounds for a layer given a pixel location. 232 * 233 * Parameters: 234 * viewPortPx - {OpenLayers.Pixel} The location in the viewport 235 */ 236 getTileBounds: function(viewPortPx) { 237 var resolution = this.getResolution(); 238 var tileMapWidth = resolution * this.tileSize.w; 239 var tileMapHeight = resolution * this.tileSize.h; 240 var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); 241 var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth); 242 var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight); 243 return new OpenLayers.Bounds(tileLeft, tileBottom, 244 tileLeft + tileMapWidth, 245 tileBottom + tileMapHeight); 246 }, 228 247 229 248 CLASS_NAME: "OpenLayers.Layer.KaMap" 230 249 });
