Changeset 4088
- Timestamp:
- 08/28/07 19:16:23 (11 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Layer/Grid.js (modified) (2 diffs)
- trunk/openlayers/lib/OpenLayers/Layer/KaMap.js (modified) (1 diff)
- trunk/openlayers/tests/Layer/test_Grid.html (modified) (2 diffs)
- trunk/openlayers/tests/Layer/test_KaMap.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Layer/Grid.js
r3984 r4088 230 230 231 231 /** 232 * Method: getTilesBounds 233 * Get the bounds of the grid 234 * 235 * Return: 232 * APIMethod: getTileBounds 233 * Returns The tile bounds for a layer given a pixel location. 234 * 235 * Parameters: 236 * viewPortPx - {<OpenLayers.Pixel>} The location in the viewport. 237 * 238 * Returns: 236 239 * {<OpenLayers.Bounds>} A Bounds object representing the bounds of all the 237 * currently loaded tiles (including those partially or not at all seen238 * onscreen)240 * currently loaded tiles (including those partially or not at all seen 241 * onscreen). 239 242 */ 240 243 getTilesBounds: function() { … … 674 677 }, 675 678 679 /** 680 * APIMethod: getTileBounds 681 * Returns The tile bounds for a layer given a pixel location 682 * 683 * Parameters: 684 * viewPortPx - {OpenLayers.Pixel} The location in the viewport 685 */ 686 getTileBounds: function(viewPortPx) { 687 var maxExtent = this.map.getMaxExtent(); 688 var resolution = this.getResolution(); 689 var tileMapWidth = resolution * this.tileSize.w; 690 var tileMapHeight = resolution * this.tileSize.h; 691 var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); 692 var tileLeft = maxExtent.left + (tileMapWidth * 693 Math.floor((mapPoint.lon - 694 maxExtent.left) / 695 tileMapWidth)); 696 var tileBottom = maxExtent.bottom + (tileMapHeight * 697 Math.floor((mapPoint.lat - 698 maxExtent.bottom) / 699 tileMapHeight)); 700 return new OpenLayers.Bounds(tileLeft, tileBottom, 701 tileLeft + tileMapWidth, 702 tileBottom + tileMapHeight); 703 }, 704 676 705 CLASS_NAME: "OpenLayers.Layer.Grid" 677 706 }); trunk/openlayers/lib/OpenLayers/Layer/KaMap.js
r3984 r4088 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 * Returns: 237 * {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location. 238 */ 239 getTileBounds: function(viewPortPx) { 240 var resolution = this.getResolution(); 241 var tileMapWidth = resolution * this.tileSize.w; 242 var tileMapHeight = resolution * this.tileSize.h; 243 var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); 244 var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth); 245 var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight); 246 return new OpenLayers.Bounds(tileLeft, tileBottom, 247 tileLeft + tileMapWidth, 248 tileBottom + tileMapHeight); 249 }, 228 250 229 251 CLASS_NAME: "OpenLayers.Layer.KaMap" trunk/openlayers/tests/Layer/test_Grid.html
r4059 r4088 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'}; 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 } 531 549 532 550 function test_99_Layer_Grid_destroy (t) { … … 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> trunk/openlayers/tests/Layer/test_KaMap.html
r4059 r4088 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'}; 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 } 192 210 193 211 function test_99_Layer_KaMap_destroy (t) {
