Skip to content

Commit

Permalink
Merge pull request #5696 from oterral/time
Browse files Browse the repository at this point in the history
Allow custom parameters in the template url of an UrlTemplateImageryP…
  • Loading branch information
Hannah authored Oct 20, 2017
2 parents 63b7486 + d6abaf1 commit 5d499c5
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log
* Added support for the layer.json `parentUrl` property in `CesiumTerrainProvider` to allow for compositing of tilesets.
* Fixed a bug that caused KML ground overlays to appear distorted when rotation was applied. [#5914](https://github.com/AnalyticalGraphicsInc/cesium/issues/5914)
* Adds `invertClassification` and `invertClassificationColor` to `Scene`. When `invertClassification` is `true`, any 3D Tiles geometry that is not classified by a `ClassificationPrimitive` or `GroundPrimitive` will have its color multiplied by `invertClassificationColor`. [#5836](https://github.com/AnalyticalGraphicsInc/cesium/pull/5836)
* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696)

### 1.38 - 2017-10-02

Expand Down
103 changes: 69 additions & 34 deletions Source/Scene/UrlTemplateImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,38 @@ define([
ImageryProvider) {
'use strict';

var tags = {
'{x}': xTag,
'{y}': yTag,
'{z}': zTag,
'{s}': sTag,
'{reverseX}': reverseXTag,
'{reverseY}': reverseYTag,
'{reverseZ}': reverseZTag,
'{westDegrees}': westDegreesTag,
'{southDegrees}': southDegreesTag,
'{eastDegrees}': eastDegreesTag,
'{northDegrees}': northDegreesTag,
'{westProjected}': westProjectedTag,
'{southProjected}': southProjectedTag,
'{eastProjected}': eastProjectedTag,
'{northProjected}': northProjectedTag,
'{width}': widthTag,
'{height}': heightTag
};

var pickFeaturesTags = combine(tags, {
'{i}' : iTag,
'{j}' : jTag,
'{reverseI}' : reverseITag,
'{reverseJ}' : reverseJTag,
'{longitudeDegrees}' : longitudeDegreesTag,
'{latitudeDegrees}' : latitudeDegreesTag,
'{longitudeProjected}' : longitudeProjectedTag,
'{latitudeProjected}' : latitudeProjectedTag,
'{format}' : formatTag
});

/**
* Provides imagery by requesting tiles using a specified URL template.
*
Expand Down Expand Up @@ -132,6 +164,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 +190,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,8 +610,33 @@ define([
}
that._credit = credit;

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
var tag;
var allTags = {};
var allPickFeaturesTags = {};
for (tag in tags) {
if (tags.hasOwnProperty(tag)) {
allTags[tag] = tags[tag];
}
}
for (tag in pickFeaturesTags) {
if (pickFeaturesTags.hasOwnProperty(tag)) {
allPickFeaturesTags[tag] = pickFeaturesTags[tag];
}
}

var customTags = properties.customTags;
if (defined(customTags)) {
for (tag in customTags) {
if (customTags.hasOwnProperty(tag)) {
var targetTag = '{' + tag + '}';
allTags[targetTag] = customTags[tag];
allPickFeaturesTags[targetTag] = customTags[tag];
}
}
}

that._urlParts = urlTemplateToParts(that._url, allTags);
that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, allPickFeaturesTags);
return true;
});
};
Expand Down Expand Up @@ -963,37 +1030,5 @@ define([
return format;
}

var tags = {
'{x}': xTag,
'{y}': yTag,
'{z}': zTag,
'{s}': sTag,
'{reverseX}': reverseXTag,
'{reverseY}': reverseYTag,
'{reverseZ}': reverseZTag,
'{westDegrees}': westDegreesTag,
'{southDegrees}': southDegreesTag,
'{eastDegrees}': eastDegreesTag,
'{northDegrees}': northDegreesTag,
'{westProjected}': westProjectedTag,
'{southProjected}': southProjectedTag,
'{eastProjected}': eastProjectedTag,
'{northProjected}': northProjectedTag,
'{width}': widthTag,
'{height}': heightTag
};

var pickFeaturesTags = combine(tags, {
'{i}' : iTag,
'{j}' : jTag,
'{reverseI}' : reverseITag,
'{reverseJ}' : reverseJTag,
'{longitudeDegrees}' : longitudeDegreesTag,
'{latitudeDegrees}' : latitudeDegreesTag,
'{longitudeProjected}' : longitudeProjectedTag,
'{latitudeProjected}' : latitudeProjectedTag,
'{format}' : formatTag
});

return UrlTemplateImageryProvider;
});
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() {
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 5d499c5

Please sign in to comment.