Skip to content

Commit

Permalink
Allow custom parameters in the template url of an UrlTemplateImageryP…
Browse files Browse the repository at this point in the history
…rovider
  • Loading branch information
Kogis IWI committed Aug 2, 2017
1 parent ecfd3cb commit 7092a04
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 19 additions & 0 deletions Source/Scene/UrlTemplateImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down
28 changes: 28 additions & 0 deletions Specs/Scene/UrlTemplateImageryProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 7092a04

Please sign in to comment.