[OpenLayers-Users] caching tiles with phonegap

Tue Topholm tt at sugee.dk
Mon Apr 16 12:57:23 EDT 2012


the window.plugins.fileDownload is a plugin for PG, but use the one that ships with PG now.

You have to set getUrl on the layer....


layer = new OpenLayers.Layer.WMS(ms[s].name ,ms[s].url,{
										layers:new String(ms[s].layers),
										format:'image/png',
										TRANSPARENT:transparent
										},{
										transitionEffect:'resize',
										singleTile: false, 
										ratio: 1.3671875,
										isBaseLayer:false,
										visibility:(ms[s].layers != ''),
getURL:function(bounds)
{
var url = this.getFullRequestString({bbox:bounds.toBBOX(),height:this.tileSize.h,width:this.tileSize.w},'');
//console.log(url);
var filename = mm.encrypt('md5',url);
if(typeof(localStorage[filename]) != 'undefined')
{
    console.log('cache');
    return localStorage[filename];
}
else
{
    console.log('not cache');
    window.plugins.fileDownload.downloadFile(url,'/' + mm.encrypt('sha1',url) + '.png',function(fp){localStorage[filename] = fp},function(){});
    return url;
}
}
										});

								map.addLayer(layer);

this the one I use.....


Den 16/04/2012 kl. 15.36 skrev Steve Nelson:

> I didn't see this message. That looks exactly like what i'm looking for.
> 
> What the heck is window.plugins.fileDownload? I've never seen that before.
> 
> Also, I did a search through OpenLayers.js and it found 17 getURL:function(bounds) can you point me in the right direction with which one you modified? If not, I'll just use trial and error to figure it out. Thanks Tue!
> 
> Steve
> 
> On Fri, Mar 23, 2012 at 9:56 AM, Tue Topholm <tt at sugee.dk> wrote:
> I have used this_
> 
> getURL:function(bounds)
> {
> var url = this.getFullRequestString({bbox:bounds.toBBOX(),height:this.tileSize.h,width:this.tileSize.w},'');
> 
> if(typeof(localStorage[filename]) != 'undefined')
> {
>     return localStorage[filename];
> }
> else
> {
>    window.plugins.fileDownload.downloadFile(url,'/' + sha1(url) +
> '.png',function(fp){localStorage[filename] = fp},function(){});
>    return url;
> }
> }
> 
> 
> 
> it was using another download plugin, so it just needs to be changed to PG's
> 
> md5 and sha1 is js functions for doing md5 and sha1
> --
> 
> Med venlig hilsen / Kind regards
> 
> Tue Topholm
> Sugee
> Tlf: +45 32 13 32 32
> W: http://www.sugee.dk
> 
> 
> 
> 23. mar. 2012 14.49 skrev Diego Guidi <diegoguidi at gmail.com>:
> >> Phonegap (a tool for creating native iphone/android apps with HTML/js) is
> >> able to do it and HTML5 is able to do it also.
> >>
> >> http://docs.phonegap.com/en/1.5.0/phonegap_file_file.md.html#FileTransfer
> > HTML5 uses localstorage, i.e 10mb space maximum available.
> > PhoneGap file API doesn't suffer of this limit.
> > _______________________________________________
> > Users mailing list
> > Users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
> 

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


More information about the Users mailing list