-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
@oterral You also have some eslint errors that need fixing. |
Thx for the review. I'm on it. |
54f6997
to
7092a04
Compare
Should be good now. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the console.error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch
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';
}
}
}); |
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 |
78209b8
to
64ff4fa
Compare
@@ -568,6 +578,16 @@ define([ | |||
} | |||
that._credit = credit; | |||
|
|||
if (properties.customTags) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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. |
@mramato use of |
@@ -568,6 +578,16 @@ define([ | |||
} | |||
that._credit = credit; | |||
|
|||
if (defined(properties.customTags)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
@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 |
Thanks for all the work you put into this @oterral! It looks good to me. |
Thx for the rebase @hpinkos |
…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: