diff --git a/examples/wmts-capabilities.js b/examples/wmts-capabilities.js index 9ed04ec364..adc4f9fcd9 100644 --- a/examples/wmts-capabilities.js +++ b/examples/wmts-capabilities.js @@ -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 call to this + * format. + * config - {Object} Configuration properties for the layer. Defaults for + * the layer will apply if not provided. + * + * Required config properties: + * layer - {String} The layer identifier. + * matrixSet - {String} The matrix set identifier. + * + * Returns: + * {} A properly configured WMTS layer. Throws an + * error if an incomplete config is provided. Returns undefined if no + * layer could be created with the provided config. + */ + createLayer: function(capabilities, config) { + var layer; + + // confirm required properties are supplied in config + var required = { + layer: true, + matrixSet: true + }; + for (var prop in required) { + if (!(prop in config)) { + throw new Error("Missing property '" + prop + "' in layer configuration."); + } + } + + var contents = capabilities.contents; + var matrixSet = contents.tileMatrixSets[config.matrixSet]; + + // find the layer definition with the given identifier + var layers = contents.layers; + var layerDef; + for (var i=0, ii=contents.layers.length; i