Dom,

Thanks for the response.  I've done something very similar to what you suggest. 
 The results I see suggest a race of some sort: sometimes I get the cached 
image, but sometimes I get a pink or transparent tile instead.  When I use the 
localStorage version (or any code where tile.url gets set synchronously within 
the fetch method), things are reliable and consistent.

>From what I see, lots of methods within OpenLayers.Tile.Image call setImgSrc, 
>such that what I set from my database callback could be overwritten by one of 
>them.  So here's a possible explanation from my admittedly poor understanding 
>of the code:

My modified OpenLayers.Control.CacheRead.fetch method (responding to the 
tileloadstart event) kicks off an asynchronous database query.  Meanwhile, my 
fetch method returns without having modified the tile's URL.  Tile loading 
proceeds with the unmodified URL.  OpenLayers.Tile.Image.initImage calls 
setImgSrc to blank out the tile, and then there's a race between the blank 
image loading and my database query returning.  When my query returns, I call 
setImgSrc, briefly setting the image's src attribute to the loaded data URL.  
If the blank image finishes loading after my query returns, the src attribute 
is set back to the unmodified tile.url, and if the user is offline, loading of 
that URL fails and the result is a pink tile.

Thanks for your help; I'll keep reading code to try to better understand the 
issue.

Andrew

-----Original Message-----
From: Dominik Mikiewicz [mailto:[email protected]] 
Sent: Wednesday, April 04, 2012 2:17 AM
To: 'Vardeman, Andrew [CSSM]'; [email protected]
Subject: RE: [OpenLayers-Dev] RE: CacheRead and CacheWrite with Web SQL Storage?

Andrew,

I haven't had a chance to play with these cool cotrols yet but from what I see 
fetching data asynchronously should not be a problem indeed.
In the fetch method you have the access to a tile so you can pass it along with 
your async calls and then modify the tile imgSrc when completed.

Try something like this (not tested):

getTileData : function(tile){
                
        this.db.transaction(
                function(tx){
                        tx.executeSql(
                                'HereGoesYourSql;',
                                [andParams],
                                function (tx, results) { //success callback
                                        if(results.rows.length == 1){
                                                var tileCache =
results.rows.item(0);
                                                
        
tile.setImgSrc(tileCache.data);
                                        }
                                },
                                function(tx, error){ //error callback
                                }
                        );
                }
        );
}

Hope this help

dom 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Vardeman, Andrew 
[CSSM]
Sent: Tuesday, April 03, 2012 10:47 PM
To: [email protected]
Subject: [OpenLayers-Dev] RE: CacheRead and CacheWrite with Web SQL Storage?

Okay, I've started on this and have the OpenLayers.Control.CacheWrite.cache
part working (tiles are getting cached to the Web SQL DB), but I think I've run 
into a problem with the OpenLayers.Control.CacheRead.fetch method.  I'm not 
quite sure what's happening, but it appears that the fetch method needs to 
complete synchronously for the dataURL it supplies to be used as the image src. 
 Does that sound right?  If so, I think I'm dead in the water.

Andrew

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Vardeman, Andrew 
[CSSM]
Sent: Monday, April 02, 2012 1:44 PM
To: [email protected]
Subject: [OpenLayers-Dev] CacheRead and CacheWrite with Web SQL Storage?

Hi, OpenLayers developers.  This is my first email; I hope I'm posting this to 
the proper list.

I'm interested in the work done here:

https://github.com/openlayers/openlayers/pull/301

The pull request says that "even asynchronous backends could be added."  By any 
chance, is anyone working on Web SQL Storage version or the mentioned pluggable 
version with multiple backends?  I need such a thing for my current project, so 
I'll probably try if no one else is already doing it.
If I get something working that's sufficiently generic, I'll submit it as a 
patch.

Thanks,

Andrew Vardeman

_______________________________________________
Dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
_______________________________________________
Dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev

_______________________________________________
Dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev

Reply via email to