From 93e9b4524bc21f7291da05963b247d1fb6facc7f Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 6 Apr 2013 21:41:01 +0200 Subject: [PATCH 1/3] Add OpenStreetMap options --- src/objectliterals.exports | 6 +++++ src/ol/source/openstreetmapsource.js | 35 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 8 deletions(-) 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 }); }; From 910ee493e5d1c378f4c3782d4b4d175f2a4036c2 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 7 Apr 2013 10:24:44 +0200 Subject: [PATCH 2/3] Add localized OpenStreetMap example --- examples/localized-openstreetmap.html | 55 +++++++++++++++++++++++++++ examples/localized-openstreetmap.js | 29 ++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 examples/localized-openstreetmap.html create mode 100644 examples/localized-openstreetmap.js diff --git a/examples/localized-openstreetmap.html b/examples/localized-openstreetmap.html new file mode 100644 index 0000000000..abe0b2aae3 --- /dev/null +++ b/examples/localized-openstreetmap.html @@ -0,0 +1,55 @@ + + + + + + + + + + Localized OpenStreetMap example + + + + + +
+ +
+
+
+
+
+ +
+ +
+

Localized OpenStreetMap example

+

Example of a localized OpenStreetMap map with a custom tile server and a custom attribution.

+
+

See the localized-openstreetmap.js source to see how this is done.

+
+
localized-openstreetmap, openstreetmap
+
+ +
+ +
+ + + + + + diff --git a/examples/localized-openstreetmap.js b/examples/localized-openstreetmap.js new file mode 100644 index 0000000000..458f92bc04 --- /dev/null +++ b/examples/localized-openstreetmap.js @@ -0,0 +1,29 @@ +goog.require('ol.Attribution'); +goog.require('ol.Map'); +goog.require('ol.RendererHints'); +goog.require('ol.View2D'); +goog.require('ol.layer.TileLayer'); +goog.require('ol.source.OpenStreetMap'); + + +var map = new ol.Map({ + layers: [ + new ol.layer.TileLayer({ + source: new ol.source.OpenStreetMap({ + attribution: new ol.Attribution( + 'All maps © ' + + 'OpenCycleMap, ' + + 'map data © ' + + 'OpenStreetMap ' + + '(ODbL)'), + url: 'http://{a-c}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png' + }) + }) + ], + renderers: ol.RendererHints.createFromQueryData(), + target: 'map', + view: new ol.View2D({ + center: [-172857, 5977746], + zoom: 12 + }) +}); From fe6b418cbd73000aebdfec1430364c14fbbd75f8 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sun, 7 Apr 2013 10:34:05 +0200 Subject: [PATCH 3/3] Use common attribution for OpenStreetMap --- src/ol/source/openstreetmapsource.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/ol/source/openstreetmapsource.js b/src/ol/source/openstreetmapsource.js index d31c2e2981..5f73770068 100644 --- a/src/ol/source/openstreetmapsource.js +++ b/src/ol/source/openstreetmapsource.js @@ -4,6 +4,16 @@ goog.require('ol.Attribution'); goog.require('ol.source.XYZ'); +/** + * @const + * @type {Array.} + */ +ol.source.OPENSTREETMAP_ATTRIBUTIONS = [new ol.Attribution( + '© OpenStreetMap ' + + 'contributors, ' + + 'CC BY-SA')]; + + /** * @constructor @@ -20,14 +30,7 @@ ol.source.OpenStreetMap = function(opt_options) { } else if (goog.isDef(options.attribution)) { attributions = [options.attribution]; } else { - attributions = [ - new ol.Attribution( - '© OpenStreetMap ' + - 'contributors, ' + - ' ' + - 'CC BY-SA' + - '') - ]; + attributions = ol.source.OPENSTREETMAP_ATTRIBUTIONS; } var maxZoom = goog.isDef(options.maxZoom) ? options.maxZoom : 18;