Support for multiple resource urls

With this change, createLayer generates url arrays for both KVP and REST
encoding if multiple resource urls are provided. To make this work, the
WMTSCapabilities format got a new resourceUrls property, because
previously only the first resourceUrl for a format was stored.
This commit is contained in:
ahocevar
2012-10-01 15:28:30 +02:00
parent 51ae75a54f
commit 22c5e76b0b
4 changed files with 68 additions and 15 deletions

View File

@@ -73,6 +73,8 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
* matrixSet - {String} The matrix set identifier, required if there is
* more than one matrix set in the layer capabilities.
* style - {String} The name of the style
* format - {String} Image format for the layer. Default is the first
* format returned in the GetCapabilities response.
* param - {Object} The dimensions values eg: {"Year": "2012"}
*
* Returns:
@@ -102,6 +104,11 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
if (!layerDef) {
throw new Error("Layer not found");
}
var format = config.format;
if (!format && layerDef.formats && layerDef.formats.length) {
format = layerDef.formats[0];
}
// find the matrixSet definition
var matrixSet;
@@ -170,19 +177,30 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
}
var url;
if (requestEncoding === "REST" && layerDef.resourceUrl) {
url = layerDef.resourceUrl.tile.template;
if (requestEncoding === "REST" && layerDef.resourceUrls) {
url = [];
var resourceUrls = layerDef.resourceUrls,
resourceUrl;
for (var t = 0, tt = layerDef.resourceUrls.length; t < tt; ++t) {
resourceUrl = layerDef.resourceUrls[t];
if (resourceUrl.format === format && resourceUrl.resourceType === "tile") {
url.push(resourceUrl.template);
}
}
}
else {
var httpGet = capabilities.operationsMetadata.GetTile.dcp.http.get;
url = httpGet[0].url;
url = [];
for (var i = 0, ii = httpGet.length; i < ii; i++) {
if (httpGet[i].constraints && httpGet[i].constraints.
GetEncoding.allowedValues[requestEncoding]) {
url = httpGet[i].url;
break;
url.push(httpGet[i].url);
}
}
// fallback for backwards compatibility
if (url.length === 0) {
url = httpGet[0].url;
}
}
return new OpenLayers.Layer.WMTS(
@@ -191,6 +209,7 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
requestEncoding: requestEncoding,
name: layerDef.title,
style: style.identifier,
format: format,
matrixIds: matrixSet.matrixIds,
matrixSet: matrixSet.identifier,
projection: projection,