Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom parameters in the template url of an UrlTemplateImageryP… #5696

Merged
merged 5 commits into from
Oct 20, 2017

Conversation

oterral
Copy link

@oterral oterral commented Jul 31, 2017

…rovider.

This is a proposal to add flexibility in the UrlTemplateImageryProvider.

This PR allows to add a custom tags in the template url.

For example with a {Time} tag in the template:

var positron = new Cesium.UrlTemplateImageryProvider({
    url : 'http://mywmt/{Time}/{x}/{y}/{z}.{format}`',
    customTags : {
        Time: function() {
            return '19381231'; 
        }
    }
});

@hpinkos
Copy link
Contributor

hpinkos commented Jul 31, 2017

Thanks @oterral! This is a great idea. Can you add unit tests?
@ggetz do you want to review this?

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @oterral! Please add unit tests and add this to CHANGES.md.

@@ -132,6 +132,13 @@ 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.
For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the Documentation guide for examples so this is formatted nicely in the reference documentation.

@ggetz
Copy link
Contributor

ggetz commented Jul 31, 2017

@oterral You also have some eslint errors that need fixing.

@oterral
Copy link
Author

oterral commented Aug 2, 2017

Thx for the review. I'm on it.

@oterral oterral force-pushed the time branch 6 times, most recently from 54f6997 to 7092a04 Compare August 2, 2017 11:35
@oterral
Copy link
Author

oterral commented Aug 2, 2017

Should be good now.

Copy link
Contributor

@ggetz ggetz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @oterral, a few more comments.

CHANGES.md Outdated
@@ -1,6 +1,10 @@
Change Log
==========

### 1.37 - 2017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be 2017-09-01


return pollToPromise(function() {
return provider.ready;
}).then(function() {console.error('spyon');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the console.error

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

@shunter
Copy link
Contributor

shunter commented Aug 2, 2017

Conventionally in templating engines, the curly braces are not specified as part of the variable name. This might be easier to use if it were like:

new Cesium.UrlTemplateImageryProvider({
    url : 'http://mywmt/{Time}/{x}/{y}/{z}.{format}`',
    customTags : {
        Time: function() {
            return '19381231'; 
        }
    }
});

@mramato
Copy link
Contributor

mramato commented Aug 2, 2017

I agree with @shunter.

Also, this needs to be carefully documented because unless the result of the supplied function is constant in regards to the rest of url, users might receive unexpected results. For example, if the result of Time changes, none of the previously fetched tiles will get automatically refreshed. Of course this might be able to tie in with @tfili's recent changes regarding dynamic images, perhaps he could chime in here.

@oterral oterral force-pushed the time branch 2 times, most recently from 78209b8 to 64ff4fa Compare August 3, 2017 07:08
@oterral
Copy link
Author

oterral commented Aug 3, 2017

@shunter good idea .

@mramato of course it will be better if the layer could refresh itself on each change. If someone can give me guidance. I can do it in another PR.

@hpinkos
Copy link
Contributor

hpinkos commented Sep 15, 2017

@oterral there is a merge conflict, please merge in master when you have a chance. Thanks!

@mramato @shunter are there other chances that need to be made in this PR?

@@ -568,6 +578,16 @@ define([
}
that._credit = credit;

if (properties.customTags) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be if(defined(properties.customTags))

for (var tag in properties.customTags) {
if (properties.customTags.hasOwnProperty(tag)) {
var targetTag = '{' + tag + '}';
tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised these eslint directives are needed. What does it thing is being used before define?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here was the messages:

/home/travis/build/AnalyticalGraphicsInc/cesium/Source/Scene/UrlTemplateImageryProvider.js
  585:25  error  'tags' was used before it was defined              no-use-before-define
  586:25  error  'pickFeaturesTags' was used before it was defined  no-use-before-define

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the directives and simple move tags and pickFeaturesTags to the top of the file.

@mramato
Copy link
Contributor

mramato commented Sep 18, 2017

@mramato of course it will be better if the layer could refresh itself on each change. If someone can give me guidance. I can do it in another PR.

I don't think this is easily possible with the current implementation because there's no way for us to know when a property has changed. We would need some sort of higher level construct that notifies us when a function would have a different value for the same input. @tfili might have some ideas here, but I think they could be added in a backwards compatible way in the future. So I have no objections to this PR going in largely as is if @hpinkos is happy with it.

@oterral
Copy link
Author

oterral commented Sep 19, 2017

@mramato use of defined() added

@@ -568,6 +578,16 @@ define([
}
that._credit = credit;

if (defined(properties.customTags)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general rule, we try to keep property access to a minimum, rather than have properties.customTags multiple times, extract a var customTags = properties.customTags variable and use it throughout.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

for (var tag in properties.customTags) {
if (properties.customTags.hasOwnProperty(tag)) {
var targetTag = '{' + tag + '}';
tags[targetTag] = properties.customTags[tag]; //eslint-disable-line no-use-before-define
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized there is a major issue here. Since tags and pickFeaturesTags used to be readonly, the same set is shared across multiple instances. However, now we are modifying tags and pickFeaturesTags which means that the modified version is used by all instances. Shouldn't these objects be per-instance now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tags and pickFeaturesTags are the same for all objects.
Maybe I can just append the customTags values to tags values in a new object and pass this new object to urlTemplateToParts.

@hpinkos
Copy link
Contributor

hpinkos commented Oct 4, 2017

@oterral is this ready? Next time make a comment after you make a commit. Otherwise we don't get notified that a pull request is ready for another look

@hpinkos
Copy link
Contributor

hpinkos commented Oct 20, 2017

Thanks for all the work you put into this @oterral! It looks good to me.

@hpinkos hpinkos merged commit 5d499c5 into CesiumGS:master Oct 20, 2017
@oterral
Copy link
Author

oterral commented Nov 7, 2017

Thx for the rebase @hpinkos

@oterral oterral deleted the time branch November 7, 2017 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants