Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 10cec10

Browse files
committed
Merge pull request #2 from TerriaJS/osm-subdomains
Support an array of subdomains to prepend to tiles, for performance.
2 parents c695086 + 43e42b0 commit 10cec10

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Source/Scene/OpenStreetMapImageryProvider.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ define([
4242
* @param {Number} [options.maximumLevel] The maximum level-of-detail supported by the imagery provider, or undefined if there is no limit.
4343
* @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
4444
* @param {Credit|String} [options.credit='MapQuest, Open Street Map and contributors, CC-BY-SA'] A credit for the data source, which is displayed on the canvas.
45-
*
45+
* @param {Array} [options.subdomains=['a','b','c']] List of subdomains one of which will be prepended to each tile URL for performance.
46+
*
4647
* @see ArcGisMapServerImageryProvider
4748
* @see BingMapsImageryProvider
4849
* @see GoogleEarthImageryProvider
@@ -63,7 +64,7 @@ define([
6364
*/
6465
var OpenStreetMapImageryProvider = function OpenStreetMapImageryProvider(options) {
6566
options = defaultValue(options, {});
66-
67+
6768
var url = defaultValue(options.url, '//a.tile.openstreetmap.org/');
6869

6970
if (!trailingSlashRegex.test(url)) {
@@ -72,6 +73,11 @@ define([
7273

7374
this._url = url;
7475
this._fileExtension = defaultValue(options.fileExtension, 'png');
76+
this._subdomains = options.subdomains;
77+
if (this._url === '//a.tile.openstreetmap.org/' && this._subdomains === undefined) {
78+
this._url = '//tile.openstreetmap.org/';
79+
this._subdomains = ['a','b','c'];
80+
}
7581
this._proxy = options.proxy;
7682
this._tileDiscardPolicy = options.tileDiscardPolicy;
7783

@@ -106,8 +112,17 @@ define([
106112
this._credit = credit;
107113
};
108114

115+
function chooseSubdomain(subdomains, x, y) {
116+
if (subdomains === undefined) {
117+
return '';
118+
} else {
119+
return subdomains[ (x + y) % subdomains.length ] + '.';
120+
}
121+
}
122+
109123
function buildImageUrl(imageryProvider, x, y, level) {
110-
var url = imageryProvider._url + level + '/' + x + '/' + y + '.' + imageryProvider._fileExtension;
124+
var url = imageryProvider.url.replace('//', '//' + chooseSubdomain(imageryProvider._subdomains, x, y));
125+
url += level + '/' + x + '/' + y + '.' + imageryProvider._fileExtension;
111126

112127
var proxy = imageryProvider._proxy;
113128
if (defined(proxy)) {

0 commit comments

Comments
 (0)