[OpenLayers-Users] Pink tiles in FireFox doesn't disappear after refresh - a possible solution

Pietro Ianniello pietro.ianniello at gmail.com
Fri Mar 12 07:04:12 EST 2010


Dear list,

I have a problem on pink tiles showing up in FireFox. The are generated
because of too many connection. It's OK that they are displayed. The problem
is that when I zoom out and zoom in they don't disappear as they should.
This is because of aggressive caching on tile to be displayed. If I disable
caching on server side for tiles, the behave ok... bu I want tiles to be
able to cache them on clients!

After some days thinking about it I decided to inspect OL code.
I realized that the problem is related to "*OpenLayers.Util.onImageLoadError
*". In fact if I change it in tha following way, firefox will reload missing
tiles after a refresh:

OpenLayers.Util.onImageLoadError = function() {
    this._attempts = (this._attempts) ? (this._attempts + 1) : 1;
    if (this._attempts <= OpenLayers.IMAGE_RELOAD_ATTEMPTS) {
        var urls = this.urls;
        if (urls && urls instanceof Array && urls.length > 1) {
            var src = this.src.toString();
            var current_url, k;
            for (k = 0; current_url = urls[k]; k++) {
                if (src.indexOf(current_url) != -1) {
                    break;
                }
            }
            var guess = Math.floor(urls.length * Math.random());
            var new_url = urls[guess];
            k = 0;
            while (new_url == current_url && k++ < 4) {
                guess = Math.floor(urls.length * Math.random());
                new_url = urls[guess];
            }
            this.src = src.replace(current_url, new_url);
        } else {
            this.src = this.src;
        }
        OpenLayers.Console.log("attemp n.:",this._attempts);
    } else {
        *OpenLayers.Console.log("error loading", "appending uuu!");**
        this.src = this.src + "&uuu";*
        this.style.backgroundColor = OpenLayers.Util.onImageLoadErrorColor;
    }
    this.style.display = "";
};

That is: I change the the url of the tile appending some dummy character [in
this case "uuu", but it can be anything].
It's not a general solution, because it should be, perhaps, checked that
there is a query string before appending... perhaps not, because the *src *will
not be used...

Pietro Ianniello
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100312/cb133b11/attachment.html


More information about the Users mailing list