Skip to content

Commit

Permalink
Merge pull request #371 from fredj/convertUrlToCesium
Browse files Browse the repository at this point in the history
Add olcs.core.convertUrlToCesium function
  • Loading branch information
gberaudo authored Jun 20, 2016
2 parents 7357b3a + c8b0270 commit 58e6932
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions externs/olcsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ olcsx.core.OlFeatureToCesiumContext;
* @api
*/
olcsx.core.RotateAroundAxisOption;


/**
* @typedef {{
* url: string,
* subdomains: string
* }}
* @api
*/
olcsx.core.CesiumUrlDefinition;
26 changes: 26 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,29 @@ olcs.core.convertColorToCesium = function(olColor) {
}
goog.asserts.fail('impossible');
};


/**
* Convert an OpenLayers url to Cesium.
* @param {string} url
* @return {!olcsx.core.CesiumUrlDefinition}
* @api
*/
olcs.core.convertUrlToCesium = function(url) {
var subdomains = '';
var re = /\{(\d|[a-z])-(\d|[a-z])\}/;
var match = re.exec(url);
if (match) {
url = url.replace(re, '{s}');
var startCharCode = match[1].charCodeAt(0);
var stopCharCode = match[2].charCodeAt(0);
var charCode;
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
subdomains += String.fromCharCode(charCode);
}
}
return {
url: url,
subdomains: subdomains
};
};

0 comments on commit 58e6932

Please sign in to comment.