OpenLayers OpenLayers

Ticket #482: kamap_tile_bounds.patch

File kamap_tile_bounds.patch, 1.8 kB (added by tschaub, 2 years ago)

and the same for ka-map layers

  • KaMap.js

    old new  
    5050     */ 
    5151    getURL: function (bounds) { 
    5252        var mapRes = this.map.getResolution(); 
    53         var scale = Math.round((this.map.getScale() * 10000)) / 10000;         
    54         var cellSize = new OpenLayers.Size(mapRes*this.tileSize.w, mapRes*this.tileSize.h); 
    55         var pX = Math.round(((bounds.left) / cellSize.w) * this.tileSize.w); 
    56         var pY = -Math.round(((bounds.top) / cellSize.h) * this.tileSize.h); 
     53        var scale = Math.round((this.map.getScale() * 10000)) / 10000; 
     54        var pX = Math.round(bounds.left / mapRes); 
     55        var pY = -Math.round(bounds.top / mapRes); 
    5756        return this.getFullRequestString( 
    5857                      { t: pY,  
    5958                        l: pX, 
     
    146145        this.spiralTileLoad(); 
    147146 
    148147    }, 
     148    /** 
     149     * 
     150     * @param {OpenLayers.Pixel} viewPortPx The location in the viewport 
     151     * 
     152     * @returns The tile bounds for a layer given a pixel location 
     153     * @type OpenLayers.Bounds 
     154     */ 
     155    getTileBounds: function(viewPortPx) { 
     156        var resolution = this.getResolution(); 
     157        var tileMapWidth = resolution * this.tileSize.w; 
     158        var tileMapHeight = resolution * this.tileSize.h; 
     159        var mapPoint = this.getLonLatFromViewPortPx(viewPortPx); 
     160        var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth); 
     161        var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight); 
     162        return new OpenLayers.Bounds(tileLeft, tileBottom, 
     163                                     tileLeft + tileMapWidth, 
     164                                     tileBottom + tileMapHeight); 
     165    }, 
    149166 
    150167    /** @final @type String */ 
    151168    CLASS_NAME: "OpenLayers.Layer.KaMap"