add a ol.layer.wms factory

This commit is contained in:
Éric Lemoine
2012-06-23 21:53:45 +02:00
parent 0b36e10f8f
commit b615eb94b7
5 changed files with 61 additions and 0 deletions

41
src/api/layer/wms.js Normal file
View File

@@ -0,0 +1,41 @@
goog.provide('ol.layer.wms');
goog.require('ol.layer.WMS');
/**
* @export
* @param {Object} opt_arg Config object.
* @return {ol.layer.WMS}
*/
ol.layer.wms = function(opt_arg) {
if (opt_arg instanceof ol.layer.WMS) {
return opt_arg;
}
/** @type {string} */
var url;
/** @type {Array.<string>} */
var layers;
/** @type {string} */
var format;
if (goog.isObject(opt_arg)) {
ol.base.checkKeys(opt_arg, ['url', 'layers', 'format']);
url = opt_arg['url'];
layers = opt_arg['layers'];
format = opt_arg['format'];
}
var msg;
if (!goog.isDef(url)) {
msg = 'Cannot create WMS layer; option "url" is missing';
ol.error(msg);
}
if (!goog.isArray(layers)) {
msg = 'Cannot create WMS layer; option "layers" is missing, ' +
'or is not an array';
ol.error(msg);
}
return new ol.layer.WMS(url, layers, format);
};