From e726b0d1811f271e23d05f25531dfedf54e04da8 Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Mon, 31 Jul 2017 16:51:49 +0200 Subject: [PATCH 1/4] Allow custom parameters in the template url of an UrlTemplateImageryProvider --- CHANGES.md | 1 + Source/Scene/UrlTemplateImageryProvider.js | 19 +++++++++++++ Specs/Scene/UrlTemplateImageryProviderSpec.js | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6a04cd71c154..f0b618d5b06e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,7 @@ Change Log * Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773) * Fixed a picking bug in the `3D Tiles Interactivity` Sandcastle demo. [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703) * Updated knockout from 3.4.0 to 3.4.2 [#5703](https://github.com/AnalyticalGraphicsInc/cesium/pull/5829) +* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. ### 1.36 - 2017-08-01 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({ From 8566cf2d680f1c37a2a0e5a9c7d0cc2da6c7940f Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Thu, 3 Aug 2017 09:03:38 +0200 Subject: [PATCH 2/4] Remove use of curly braces --- Source/Scene/UrlTemplateImageryProvider.js | 11 ++++++----- Specs/Scene/UrlTemplateImageryProviderSpec.js | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index 245a68583a2b..bfc2630ff205 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -160,9 +160,9 @@ define([ * }); * // Using custom tags in your template url. * var custom = new Cesium.UrlTemplateImageryProvider({ - * url : 'https://yoururl/{time}/{z}/{y}/{x}.png', + * url : 'https://yoururl/{Time}/{z}/{y}/{x}.png', * customTags : { - * '{time}': function(imageryProvider, x, y , level) { + * Time: function(imageryProvider, x, y , level) { * return '20171231' * } * } @@ -578,11 +578,12 @@ define([ } that._credit = credit; - if (properties.customTags) { + if (defined(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 + var targetTag = '{' + tag + '}'; + tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + pickFeaturesTags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define } } } diff --git a/Specs/Scene/UrlTemplateImageryProviderSpec.js b/Specs/Scene/UrlTemplateImageryProviderSpec.js index b166e49550b0..58b36954a391 100644 --- a/Specs/Scene/UrlTemplateImageryProviderSpec.js +++ b/Specs/Scene/UrlTemplateImageryProviderSpec.js @@ -640,14 +640,14 @@ defineSuite([ tilingScheme: new GeographicTilingScheme(), maximumLevel: 6, customTags: { - '{custom1}': function() { return 'foo';}, - '{custom2}': function() { return 'bar';} + custom1: function() { return 'foo';}, + custom2: function() { return 'bar';} } }); return pollToPromise(function() { return provider.ready; - }).then(function() {console.error('spyon'); + }).then(function() { spyOn(loadImage, 'createImage').and.callFake(function(url, crossOrigin, deferred) { expect(url).toEqual('made/up/tms/server/foo/bar/2/1/3.PNG'); From 26ec8de52e62523a4a6d91712ede37891934f511 Mon Sep 17 00:00:00 2001 From: Kogis IWI Date: Wed, 20 Sep 2017 09:27:06 +0200 Subject: [PATCH 3/4] Don't override tags and pickFeaturesTags objects --- Source/Scene/UrlTemplateImageryProvider.js | 93 +++++++++++++--------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index bfc2630ff205..94529176764a 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -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. * @@ -578,18 +610,33 @@ define([ } that._credit = credit; - if (defined(properties.customTags)) { - for (var tag in properties.customTags) { - if (properties.customTags.hasOwnProperty(tag)) { + 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 + '}'; - tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define - pickFeaturesTags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define + allTags[targetTag] = customTags[tag]; + allPickFeaturesTags[targetTag] = customTags[tag]; } } } - 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 + that._urlParts = urlTemplateToParts(that._url, allTags); + that._pickFeaturesUrlParts = urlTemplateToParts(that._pickFeaturesUrl, allPickFeaturesTags); return true; }); }; @@ -983,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; }); From d6abaf12f17ba88afa475546c0a723141fe76351 Mon Sep 17 00:00:00 2001 From: hpinkos Date: Fri, 20 Oct 2017 16:02:20 -0400 Subject: [PATCH 4/4] fix changes --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b481a09606ed..be32a8d8b62b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 @@ -52,7 +53,6 @@ Change Log * Fixed specular computation for certain models using the `KHR_materials_common` extension. [#5773](https://github.com/AnalyticalGraphicsInc/cesium/pull/5773) * Fixed a picking bug in the `3D Tiles Interactivity` Sandcastle demo. [#5703](https://github.com/AnalyticalGraphicsInc/cesium/issues/5703) * Updated knockout from 3.4.0 to 3.4.2 [#5703](https://github.com/AnalyticalGraphicsInc/cesium/pull/5829) -* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. ### 1.36 - 2017-08-01