[ka-Map-users] Detecting when tile images have loaded

Paul Spencer pspencer at dmsolutions.ca
Fri Apr 21 08:48:46 EDT 2006

David et al

you will notice there are onload and onerror functions for handling  
images.  I had originally wanted to track if tiles failed to load and  
automatically re-request them after a small delay assuming that they  
failed due to load on the server or transient network issues.  The  
idea was to re-request a couple of times, then assume that the tile  
had failed to draw and the request was now cached, so force=true  
would be added to regenerate the tile and reset the reload count.

I was never able to get this to work.  The reload count was always  
reset on every reload, regardless of whether I used global variables  
or attached a counter to the image object (via 'this').  It seems  
that the onerror/onload has some sort of special scope that I don't  
understand (at least in some circumstances).

This could mean that there is some serious flaw somewhere that I  
haven't uncovered yet (in my logic for loading images).

I think this is the same problem that is happening with counting  
image loads (the scope problem causes a problem with counting onload  

I am hoping that if I ever get around to integrating prototype.js  
into kaMap's core engine, this will be resolved using the  
Function.bind (or bindAsEventListener) approach to attaching event  
handlers.  I've had great success with this in other projects and  
just need to find a few quiet moments to work on this in kaMap.

A long answer without really solving the problem I guess :)



On 20-Apr-06, at 5:44 PM, David Badke wrote:

> Pete:
> Thanks for the info - I missed that discussion.
> I'm not sure I understand Brent's idea, but wouldn't you have to  
> keep a list of the IDs that were generated but not yet loaded? I  
> suspect that the same problem would still be there anyway. The  
> count of the number of times the tiler is called (in setTile) is  
> always some fixed number higher (depends on the number of layers  
> somehow) than the number of times onload is triggered - on my  
> system, it is a difference of about 16 or 17 per layer. But even  
> compensating for that, and ignoring aPixel tiles and already  
> visible tiles, the count hits zero before the images are all drawn.  
> My tests seem to suggest that all of the onload events have fired  
> before the browser has actually rendered everything - like they  
> trigger when the browser receives the image (has it in its local  
> cache?), not after the image is rendered. If so, this method will  
> never work.
> Frustrating...
> David
> Pete Giencke wrote:
>> David,
>> There was actually some discussion on this topic last year
>> (http://lists.maptools.org/pipermail/ka-map-users/2005-October/ 
>> 000484.html).
>> Through that discussion, I ran into the same luck you're having  
>> with this,
>> which is, I wasn't able to (repeatably) detect when all the images  
>> had
>> loaded. I think Brent Peterson was on the right track back when he  
>> suggested
>> comparing the ids of the tiles loaded with the tiles generated.
>> -pete
>> -----Original Message-----
>> From: ka-map-users-bounces at lists.maptools.org
>> [mailto:ka-map-users-bounces at lists.maptools.org] On Behalf Of  
>> David Badke
>> Sent: Thursday, April 20, 2006 2:17 PM
>> To: ka-map-users at lists.maptools.org
>> Subject: [ka-Map-users] Detecting when tile images have loaded
>> I would like to be able to detect when all of the tile images have  
>> been
>> loaded - that is, get an event to trigger when the map image (or  
>> only a
>> certain layer) has been fully drawn by the browser. Since there is  
>> no such
>> event in ka-Map now, I have been trying to create one, with very  
>> limited
>> success. I had thought I could count the number of calls to  
>> tile.php (which
>> I can, in kaMap.setTile) to get a count of the number of images  
>> expected,
>> then decrement the count in the tile image onload event hander
>> (kaMap_imgOnLoad) as each image loads. This doesn't work; even when I
>> compensate for kaMap_imgOnLoad being called for already visible  
>> tiles, the
>> count hits zero when the browser has only partly finished drawing.  
>> I have
>> not found any reliable way to detect when all tiles are loaded, so
>> triggering an event (which in itself is easy to do with the event  
>> manager)
>> is problematic - when do I trigger it?
>> Anyone have any ideas how this could be done?
>> David
> -- 
> David Badke
> Humanities Computing and Media Center
> University of Victoria, BC, Canada
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users

|Paul Spencer                           pspencer at dmsolutions.ca   |
|Applications & Software Development                              |
|DM Solutions Group Inc                 http://www.dmsolutions.ca/|

More information about the ka-Map-users mailing list