Geoportal.Layer.TileCacheNew = OpenLayers.Class(Geoportal.Layer.Grid, {
extension : null,
format: "image/png",
DEFAULT_PARAMS: {
service: "WMS",
version: "1.1.1",
request: "GetMap",
styles: "",
exceptions: "application/vnd.ogc.se_inimage",
format: "image/jpeg"
},
isBaseLayer: false,
initialize: function (E, D, layername,F, C)
{
this.layername = layername;
var B = [];
F = OpenLayers.Util.upperCaseObject(F);
B.push(E, D, F, C);
Geoportal.Layer.Grid.prototype.initialize.apply(this, B);
OpenLayers.Util.applyDefaults(this.params, OpenLayers.Util.upperCaseObject(this.DEFAULT_PARAMS));
if (this.params.TRANSPARENT && this.params.TRANSPARENT.toString().toLowerCase() == "true")
{
if ((C == null) || (!C.isBaseLayer))
{
this.isBaseLayer = false
}
if (this.params.FORMAT == "image/jpeg")
{
this.params.FORMAT = OpenLayers.Util.alphaHack() ? "image/gif" : "image/png"
}
}
this.extension = this.format.split('/')[1].toLowerCase();
this.extension = (this.extension == 'jpg') ? 'jpeg' : this.extension;
},
destroy: function ()
{
Geoportal.Layer.Grid.prototype.destroy.apply(this, arguments)
},
clone: function (B)
{
if (B == null)
{
B = new Geoportal.Layer.TileCacheNew (this.name, this.url, this.params, this.options)
}
B = Geoportal.Layer.Grid.prototype.clone.apply(this, [B]);
return B
},
/**
* Method: getURL
*
* Parameters:
* bounds - {<OpenLayers.Bounds>}
*
* Returns:
* {String} A string with the layer's url and parameters and also the
* passed-in bounds and appropriate tile size specified as parameters.
*/
getURL: function(bounds) {
var res = this.map.getResolution();
var bbox = this.maxExtent;
var size = this.tileSize;
var tileX = Math.round((bounds.left - bbox.left) / (res * size.w));
var tileY = Math.round((bounds.bottom - bbox.bottom) / (res * size.h));
var tileZ = this.serverResolutions != null ?
OpenLayers.Util.indexOf(this.serverResolutions, res) :
this.map.getZoom();
/**
* Zero-pad a positive integer.
* number - {Int}
* length - {Int}
*
* Returns:
* {String} A zero-padded string
*/
function zeroPad(number, length) {
number = String(number);
var zeros = [];
for(var i=0; i<length; ++i) {
zeros.push('0');
}
return zeros.join('').substring(0, length - number.length) + number;
}
var components = [
this.layername,
zeroPad(tileZ, 2),
zeroPad(parseInt(tileX / 1000000), 3),
zeroPad((parseInt(tileX / 1000) % 1000), 3),
zeroPad((parseInt(tileX) % 1000), 3),
zeroPad(parseInt(tileY / 1000000), 3),
zeroPad((parseInt(tileY / 1000) % 1000), 3),
zeroPad((parseInt(tileY) % 1000), 3) + '.' + this.extension
];
var path = components.join('/');
var url = this.url;
if (url instanceof Array) {
url = this.selectUrl(path, url);
}
url = (url.charAt(url.length - 1) == '/') ? url : url + '/';
return url + path;
},
mergeNewParams: function (D)
{
var C = OpenLayers.Util.upperCaseObject(D);
var B = [C];
Geoportal.Layer.Grid.prototype.mergeNewParams.apply(this, B)
},
getFullRequestString: function (C)
{
var B = this.getNativeProjection() || this.map.getProjection();
this.params.SRS = (B == "none") ? null : B;
return Geoportal.Layer.Grid.prototype.getFullRequestString.apply(this, arguments)
},
addTile: function (E, B, D)
{
var C = this.getURL(E);
return new Geoportal.Tile.Image(this, B, E, C, D)
},
getDataExtent: function ()
{
return this.maxExtent
},
changeBaseLayer: function (B)
{
if (OpenLayers.Layer.prototype.changeBaseLayer.apply(this, arguments) === false)
{
return false
}
if (!this.isBaseLayer)
{
if (this.getCompatibleProjection(B.layer) != null)
{
if (this.aggregate == undefined)
{
this.displayInLayerSwitcher = true
}
if (typeof(this.savedStates[B.layer.id]) == "object")
{
if (this.savedStates[B.layer.id].opacity != undefined)
{
this.opacity = undefined;
this.setOpacity(this.savedStates[B.layer.id].opacity)
}
this.setVisibility(this.savedStates[B.layer.id].visibility)
}
else
{
this.setVisibility(this.getVisibility() && this.calculateInRange())
}
return true
}
if (this.getCompatibleProjection(B.baseLayer) != null)
{
if (!this.savedStates[B.baseLayer.id])
{
this.savedStates[B.baseLayer.id] =
{
}
}
this.savedStates[B.baseLayer.id].visibility = this.getVisibility();
this.savedStates[B.baseLayer.id].opacity = this.opacity
}
if (this.aggregate == undefined)
{
this.displayInLayerSwitcher = false
}
this.setVisibility(false)
}
return true
},
getCompatibleProjection: function (D)
{
var C = OpenLayers.Layer.prototype.getCompatibleProjection.apply(this, arguments);
if (C == null)
{
return C
}
if (D == null)
{
D = this.map.baseLayer;
if (D == null)
{
return undefined
}
}
var E = D.getNativeProjection();
if (C.isCompatibleWith(E))
{
var B = this.restrictedExtent || this.maxExtent;
if (!B)
{
return C
}
if (this.map == null)
{
B = B.clone().transform(C, E)
}
if (D.maxExtent.containsBounds(B, true, true) || B.containsBounds(D.maxExtent, true, true))
{
return C
}
}
return null
},
CLASS_NAME: "Geoportal.Layer.TileCacheNew"
});
Partager