[OpenLayers-Users] offline tiles

Jürgen Dankoweit Juergen.Dankoweit at T-Online.de
Thu Jul 11 08:22:05 PDT 2013


Hi Jochen,


Am 11.07.2013 10:51, schrieb Jochen Wagner:
> Hi,
> 
> I try to use downloaded TMS tiles offline without a Server.
> My tiles are saved local on my Windows machine (no tileserver!):
> C:\inetpub\wwwroot\test\tiles\1.0.0\test1
> C:\inetpub\wwwroot is the root dir of my local webserver.
> 
> If I use folowing configuration the client shows the tiles fine (because the tiles come via http):
> 
> var test_xyz = new OpenLayers.Layer.TMS( "test_xyz",
> 	"http://localhost/test/tiles/",
> 	{ 
> 	layername: 'test1',
> 	type: "jpg",
> 	isBaseLayer:true,
> 	transitionEffect:'resize',
> 	resolutions:[529.16666666670005270134,396.87500000000000000000,264.58333333330000414207],
> 	units: projUnits,
> 	projection: mapProj,
> 	sphericalMercator: false
> 	}
> );
> 
> if I change the URL to the file it doesn't work.
> 
> var test_xyz = new OpenLayers.Layer.TMS( "test_xyz",
> 	"file:///C:/inetpub/wwwroot/test/tiles/",
> 	{ 
> 	layername: 'test1',
> 	type: "jpg",
> 	isBaseLayer:true,
> 	transitionEffect:'resize',
> 	resolutions:[529.16666666670005270134,396.87500000000000000000,264.58333333330000414207],
> 	units: projUnits,
> 	projection: mapProj,
> 	sphericalMercator: false
> 	}
> );
> 
> In Firebug I see that there comes no request.
> If I try to use a OpenLayers.Layer.XYZ Object I have the same problem.
> Later I want to use the tiles on an android device.

I'm trying to create an application for my Nokia N900 that uses offline
maps too. I found the following solution:

var tms = new OpenLayers.Layer.TMS( "TMS", "", {
 type: 'png',
 getURL: my_getTileURL, // <------------+
 alpha: true,           //              |
 isBaseLayer: true      //              |
});                     //              |
                        //              |
function my_getTileURL(bounds) { // <---+
 var res = this.map.getResolution();
 var x = Math.round((bounds.left - this.maxExtent.left) / (res *
this.tileSize.w));
 var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res *
this.tileSize.h));
 var z = this.map.getZoom();
 if (mapBounds.intersectsBounds( bounds ) && z >= mapMinZoom && z <=
mapMaxZoom ) {
  console.log( this.url + z + "/" + x + "/" + y + "." + this.type);
  return 'file:///<tiles_directory>/'+this.url + z + "/" + x + "/" + y +
"." + this.type;
 } else {
  return "empty_image.png";
 }
}

I hope this helps.

Best regards

Jürgen

-- 
Meine stets unfertige Homepage: www.dankoweit.de


More information about the Users mailing list