[OpenLayers-Users] Tilecache layer temporary patch

Simone Gadenz simone.gadenz at jrc.it
Thu Apr 17 03:57:35 EDT 2008


Hi all.

 

As in one of my previous post on this list I experienced problem wrapping
the dateline for a Tilecache layer. In practice the column of tiles
eastwards to the 180 latitude was calling a not existent 004 folder into the
level 02 of the tilcecahc hierarchy. The level 02 has only 4 subfolders,
from 000 to 003.

 

I tried to understand where the error was generated but I didn't find it.
For now I changed the getURL function into the OpenLayers.Layer.TileCache
to:

 

getURL: function(bounds) {

        var res = this.map.getResolution();

        var bbox = this.maxExtent;

        var size = this.tileSize;

        var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));

        var tileY = Math.round((bounds.bottom - bbox.bottom) / (res *
size.h));

        var tileZ = this.map.zoom;

        /**

         * Zero-pad a positive integer.

         * number - {Int} 

         * length - {Int} 

         *

         * Returns:

         * {String} A zero-padded string

         */

        function zeroPad(number, length) {

            number = String(number);

            var zeros = [];

            for(var i=0; i<length; ++i) {

                zeros.push('0');

            }

            return zeros.join('').substring(0, length - number.length) +
number;

        }

        var corrX = zeroPad((parseInt(tileX) % 1000), 3);

        if(corrX== '004'){

                corrX= '000'

        }

        var components = [

            this.layername,

            zeroPad(tileZ, 2),

            zeroPad(parseInt(tileX / 1000000), 3),

            zeroPad((parseInt(tileX / 1000) % 1000), 3),

            corrX,

            zeroPad(parseInt(tileY / 1000000), 3),

            zeroPad((parseInt(tileY / 1000) % 1000), 3),

            zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension

        ];

        var path = components.join('/'); 

        var url = this.url;

        if (url instanceof Array) {

            url = this.selectUrl(path, url);

        }

        url = (url.charAt(url.length - 1) == '/') ? url : url + '/';

        return url + path;

    },

 

This solved my problem for now but I know that is not the best way to solve
the problems. Is there anybody with a better knowledge of OL than me that
experienced the same malfucntioning and managed to solve it in a better way?

 

Thanks

 

 

Simone

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080417/10dfa270/attachment.html


More information about the Users mailing list