diff --git a/src/api/layer/wms.js b/src/api/layer/wms.js new file mode 100644 index 0000000000..ee48e9d232 --- /dev/null +++ b/src/api/layer/wms.js @@ -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.} */ + 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); +}; diff --git a/src/ol.export.js b/src/ol.export.js index 86d1b75727..f1f7e3820a 100644 --- a/src/ol.export.js +++ b/src/ol.export.js @@ -48,6 +48,10 @@ goog.exportSymbol('ol.layer.XYZ', ol.layer.XYZ); goog.exportSymbol('ol.layer.osm', ol.layer.osm); goog.exportSymbol('ol.layer.OSM', ol.layer.OSM); +// ol.layer.wms +goog.exportSymbol('ol.layer.wms', ol.layer.wms); +goog.exportSymbol('ol.layer.WMS', ol.layer.WMS); + // ol.feature goog.exportSymbol('ol.feature', ol.feature); goog.exportSymbol('ol.Feature', ol.Feature); diff --git a/src/ol.js b/src/ol.js index 1ea61696e2..733f1ec8c2 100644 --- a/src/ol.js +++ b/src/ol.js @@ -13,6 +13,7 @@ goog.require("ol.feature"); goog.require("ol.projection"); goog.require("ol.layer.xyz"); goog.require("ol.layer.osm"); +goog.require("ol.layer.wms"); goog.require("ol.popup"); goog.require("ol.Tile"); goog.require("ol.TileSet"); diff --git a/test/api.html b/test/api.html index 3cb67c3177..ff00d35ff7 100644 --- a/test/api.html +++ b/test/api.html @@ -57,6 +57,7 @@ + diff --git a/test/spec/api/layer/wms.test.js b/test/spec/api/layer/wms.test.js new file mode 100644 index 0000000000..4896f0b239 --- /dev/null +++ b/test/spec/api/layer/wms.test.js @@ -0,0 +1,14 @@ +describe('ol.layer.wms', function() { + + describe('create a wms layer', function() { + + it('creates an ol.layer.WMS instance', function() { + var wms = ol.layer.wms({ + url: 'http://wms', + layers: ['layer1', 'layer2'], + format: 'image/png' + }); + expect(wms).toBeA(ol.layer.WMS); + }); + }); +});