diff --git a/src/objectliterals.exports b/src/objectliterals.exports index 3ec7c4af74..4d2e882759 100644 --- a/src/objectliterals.exports +++ b/src/objectliterals.exports @@ -150,6 +150,12 @@ @exportObjectLiteralProperty ol.source.DebugTileSourceOptions.projection ol.ProjectionLike @exportObjectLiteralProperty ol.source.DebugTileSourceOptions.tileGrid ol.tilegrid.TileGrid|undefined +@exportObjectLiteral ol.source.OpenStreetMapOptions +@exportObjectLiteralProperty ol.source.OpenStreetMapOptions.attribution ol.Attribution|undefined +@exportObjectLiteralProperty ol.source.OpenStreetMapOptions.attributions Array.|undefined +@exportObjectLiteralProperty ol.source.OpenStreetMapOptions.maxZoom number|undefined +@exportObjectLiteralProperty ol.source.OpenStreetMapOptions.url string|undefined + @exportObjectLiteral ol.source.SingleImageWMSOptions @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.attributions Array.|undefined @exportObjectLiteralProperty ol.source.SingleImageWMSOptions.crossOrigin null|string|undefined diff --git a/src/ol/source/openstreetmapsource.js b/src/ol/source/openstreetmapsource.js index 7818574939..d31c2e2981 100644 --- a/src/ol/source/openstreetmapsource.js +++ b/src/ol/source/openstreetmapsource.js @@ -8,20 +8,39 @@ goog.require('ol.source.XYZ'); /** * @constructor * @extends {ol.source.XYZ} + * @param {ol.source.OpenStreetMapOptions=} opt_options Open Street Map options. */ -ol.source.OpenStreetMap = function() { +ol.source.OpenStreetMap = function(opt_options) { - var attribution = new ol.Attribution( - '© OpenStreetMap ' + - 'contributors, ' + - 'CC BY-SA'); + var options = goog.isDef(opt_options) ? opt_options : {}; + + var attributions; + if (goog.isDef(options.attributions)) { + attributions = options.attributions; + } else if (goog.isDef(options.attribution)) { + attributions = [options.attribution]; + } else { + attributions = [ + new ol.Attribution( + '© OpenStreetMap ' + + 'contributors, ' + + ' ' + + 'CC BY-SA' + + '') + ]; + } + + var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18; + + var url = goog.isDef(options.url) ? + options.url : 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'; goog.base(this, { - attributions: [attribution], + attributions: attributions, crossOrigin: 'anonymous', opaque: true, - maxZoom: 18, - url: 'http://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png' + maxZoom: maxZoom, + url: url }); };