AW: [OpenLayers-Users] WMS-C/TMS and WMTS
Phil Scadden
p.scadden at gns.cri.nz
Wed Aug 3 21:42:39 EDT 2011
> Would be possible to show us the code snippets for TMS maptiles
> without a server using the file created by maptiler?
>
> I like to see e.g. overlay_getTileURL / (your custom getURL to fetch
> the tile) function with file protocol (file://) in local directory.
>
Sure. tms tiles in a directory on disk has relative of
Content/outputs/Magnetics
lay.imageBounds is tms bounds in lat/long (so dproj is a 4326 projection
and proj is 900913)
lay.minZoom and maxZoom and the zoom you specified when you created the
TMS. I could do this the
"proper" OL way but its a pain to calculate and setup. This works just fine.
tmsLayer = new OpenLayers.Layer.TMS(lay.name,
'Content/outputs/', {
type: 'png',
alpha: true,
serviceVersion: '',
layername: 'Magnetics',
tileExtent: new OpenLayers.Bounds(lay.imageBounds.left,
lay.imageBounds.bottom, lay.imageBounds.right,
lay.imageBounds.top).transform(dproj, proj),
mapMinZoom: lay.imageMinZoom,
mapMaxZoom: lay.imageMaxZoom,
getURL: tms_getTileURL,
displayOutsideMaxExtent: true,
zoomOffset: 0,
isBaseLayer: lay.baselayer
});
the getURL to use is:
function tms_getTileURL(bounds) {
adjustBounds(bounds, this.maxExtent);
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();
z = this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions, res) : z + this.zoomOffset;
if (this.tileExtent.left > this.tileExtent.right) {
var b1 = new OpenLayers.Bounds(this.tileExtent.left,
this.tileExtent.bottom, this.map.maxExtent.right, this.tileExtent.top);
var b2 = new OpenLayers.Bounds(this.map.maxExtent.left,
this.tileExtent.bottom, this.tileExtent.right, this.tileExtent.top);
if ((b1.intersectsBounds(bounds) ||
b2.intersectsBounds(bounds)) && z >= this.mapMinZoom && z <=
this.mapMaxZoom) {
return this.url + this.serviceVersion + "/" +
this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
} else {
return "images/none.png";
}
} else {
if (this.tileExtent.intersectsBounds(bounds) && z >=
this.mapMinZoom && z <= this.mapMaxZoom) {
return this.url + this.serviceVersion + "/" +
this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
} else {
return "images/none.png";
}
}
}
Note that instead of returning a null image, I am looking at css that
gives blank tile when tileurlload fails. If I can get this to work, then
it is easily to have merge TMS into one mozaic which dont have complete
tile coverage.
--
Phil Scadden, Senior Scientist GNS Science Ltd 764 Cumberland St,
Private Bag 1930, Dunedin, New Zealand Ph +64 3 4799663, fax +64 3 477 5232
Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.
More information about the Users
mailing list