diff --git a/CHANGES.md b/CHANGES.md index 5e0e29d56022..7ee7ef5b9047 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ Change Log ========== +### 1.37 - 2017 + +* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. + ### 1.36 - 2017-08-01 * Breaking changes diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index 7187182f0700..245a68583a2b 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -132,6 +132,7 @@ define([ * source does not support picking features or if you don't want this provider's features to be pickable. Note * that this can be dynamically overridden by modifying the {@link UriTemplateImageryProvider#enablePickFeatures} * property. + * @param {Object} [options.customTags] Allow to replace custom keywords in the URL template. The object must have strings as keys and functions as values. * * * @example @@ -157,6 +158,15 @@ define([ * 'width=256&height=256', * rectangle : Cesium.Rectangle.fromDegrees(96.799393, -43.598214999057824, 153.63925700000001, -9.2159219997013) * }); + * // Using custom tags in your template url. + * var custom = new Cesium.UrlTemplateImageryProvider({ + * url : 'https://yoururl/{time}/{z}/{y}/{x}.png', + * customTags : { + * '{time}': function(imageryProvider, x, y , level) { + * return '20171231' + * } + * } + * }); * * @see ArcGisMapServerImageryProvider * @see BingMapsImageryProvider @@ -568,6 +578,15 @@ define([ } that._credit = credit; + if (properties.customTags) { + for (var tag in properties.customTags) { + if (properties.customTags.hasOwnProperty(tag)) { + tags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + pickFeaturesTags[tag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + } + } + } + that._urlParts = urlTemplateToParts(that._url, tags); //eslint-disable-line no-use-before-define that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, pickFeaturesTags); //eslint-disable-line no-use-before-define return true; diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index b8befc7068a8..b166e49550b0 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -634,6 +634,34 @@ defineSuite([ }); }); + it('uses custom tags', function() { + var provider = new UrlTemplateImageryProvider({ + url: 'made/up/tms/server/{custom1}/{custom2}/{z}/{y}/{x}.PNG', + tilingScheme: new GeographicTilingScheme(), + maximumLevel: 6, + customTags: { + '{custom1}': function() { return 'foo';}, + '{custom2}': function() { return 'bar';} + } + }); + + return pollToPromise(function() { + return provider.ready; + }).then(function() {console.error('spyon'); + spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) { + expect(url).toEqual('made/up/tms/server/foo/bar/2/1/3.PNG'); + + // Just return any old image. + loadImage.defaultCreateImage('Data/Images/Red16x16.png', crossOrigin, deferred); + }); + + return provider.requestImage(3, 1, 2).then(function(image) { + expect(loadImage.createImage).toHaveBeenCalled(); + expect(image).toBeInstanceOf(Image); + }); + }); + }); + describe('pickFeatures', function() { it('returns undefined when enablePickFeatures is false', function() { var provider = new UrlTemplateImageryProvider({