UrlTemplateImageryProvider pad url with zeros?

I’m trying to create a UrlTemplateImageryProvider, but the image URL naming requires a format of:


which I was able to create with this template:

var TILE_LOAD_URI_TEMPLATE = ‘/{z}/000{reverseY}/000{reverseY}_000{x}.png’;

The problem of course is that this breaks when e.g. {reverseY} is greater than 9. The generated URL (fragment) is e.g.:


but it needs to be:


(Notice one fewer zero in front of each ‘11’.)

I had a quick look at the source and can’t find a way to do this. Am I missing something?

  • Dave

Hi Dave,

I don’t think the UrlTemplateImageryProvider can currently do this. It replaces the bracketed values with the number, so it doesn’t have a way of knowing how many zeros you need in front of the number.

I don’t think it would be too difficult to change the code to do this though. You should be able to change these functions to return a string with the appropriate number of zeros:

Just for reference, take a look at our build guide if you need help checkout out the code or building it: https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/BuildGuide



Thanks Hannah,

I’ll look at adding this to the code and issue a pull request when I’m done.

  • Dave