Making it more convenient to create WMTS layers from capabilities documents. The format now has a createLayer method that takes a capabilities response object and a layer configuration object. This returns a properly configured WMTS layer based on the layer and matrix definition found in the capabilities. Unless otherwise specified, the layer name will be derived from the advertised title, and the style identifier will be the advertised default. r=ahocevar (closes #2676)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10449 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -18,7 +18,7 @@ function init() {
|
||||
doc = request.responseText;
|
||||
}
|
||||
var capabilities = format.read(doc);
|
||||
var layer = createLayer(capabilities, {
|
||||
var layer = format.createLayer(capabilities, {
|
||||
layer: "medford:buildings",
|
||||
matrixSet: "EPSG:900913",
|
||||
format: "image/png",
|
||||
@@ -50,39 +50,3 @@ function init() {
|
||||
map.setCenter(new OpenLayers.LonLat(-13677832, 5213272), 13);
|
||||
|
||||
}
|
||||
|
||||
function createLayer(capabilities, config) {
|
||||
|
||||
var contents = capabilities.contents;
|
||||
var matrixSet = contents.tileMatrixSets[config.matrixSet];
|
||||
|
||||
// find the layer definition with the given identifier
|
||||
var layers = contents.layers;
|
||||
var layer;
|
||||
for (var i=0, ii=layers.length; i<ii; ++i) {
|
||||
if (layers[i].identifier === config.layer) {
|
||||
layer = layers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// get the default style for the layer
|
||||
var style;
|
||||
for (var i=0, ii=layer.styles.length; i<ii; ++i) {
|
||||
style = layer.styles[i];
|
||||
if (style.isDefault === "true") { // TODO: change this to boolean
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// create the layer
|
||||
return new OpenLayers.Layer.WMTS(
|
||||
OpenLayers.Util.applyDefaults(config, {
|
||||
url: capabilities.operationsMetadata.GetTile.dcp.http.get,
|
||||
name: layer.title,
|
||||
style: style,
|
||||
matrixIds: matrixSet.matrixIds
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user