-
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
Upend resource loading approach #6035
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.
I think this is a good start and fits what I had imagined. I see there is still a lot of cleanup to go through. Hopefully in the end a lot of this code will seem simpler than it previously did.
Source/Core/Resource.js
Outdated
uri.query = undefined; | ||
} | ||
|
||
if (defined(uri.fragment)) { |
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.
Fragment is an interesting case, since it's not actually sent to the server, so technically it's can't affect a remote resource in any way. I suppose it makes sense since this encapsulates an URI, though. I would be curious if any of the existing functionality actually makes use of fragments (I suspect not).
Source/Core/Resource.js
Outdated
|
||
this._url = ''; | ||
this._queryParameters = defaultValue(options.queryParameters, {}); | ||
this._hash = defaultValue(options.hash, ''); |
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.
Probably prefer the term "fragment" to "hash".
Source/Core/Resource.js
Outdated
this.url = options.url; | ||
|
||
this.headers = options.headers; | ||
this.request = options.request; |
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 suspect we can continue further and inline the contents of Request
into Resource
as well.
Source/Core/CesiumTerrainProvider.js
Outdated
@@ -629,7 +635,13 @@ define([ | |||
extensionList.push('watermask'); | |||
} | |||
|
|||
var promise = loadArrayBuffer(url, getRequestHeader(extensionList), request); | |||
var resource = this._resource.getDerivedResource({ | |||
url: urlTemplates[(x + tmsY + level) % urlTemplates.length].replace('{z}', level).replace('{x}', x).replace('{y}', tmsY), |
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.
URL template interpolation might be another good candidate to move into Resource
, since we do this in a number of places. Basically it could accept a templated URL and a dictionary of key-value parameters.
I know that this is early stage code looking for feedback, but I was wondering whether any thought had gone into what I have recently been working on implementing refreshing tokens for ArcGisMapServerImageryProvider and being able to detect and update the token specifically when the token expires is quite essential (to make sure that the token refresh code can specifically renew the token only when this is known or likely to be the underlying cause): It seems that the structure in this branch/PR allows much more scope for |
Would this solution also support the loading of Billboard images? |
@a-stacey The goal is to definitely provide the status code where possible. (any time the browser returns it) @samherrmann Yes, the goal of this approach is that anywhere Cesium currently takes a string url/uri will now be able to take a Resource object as well. Glad to see we already have two people interested in this PR, I think it will fix a lot of long-standing issues with how Cesium handles external requests. |
Copying my comment which I accidentally left on the old PR: Also consider the differences in how images are requested by imagery providers - See discussion thread: https://groups.google.com/d/topic/cesium-dev/3NxyEFmMzDM/discussion |
… all working with resources.
…eoJson/CZML datasources.
Source/Core/loadJsonp.js
Outdated
callbackParameterName = options.callbackParameterName; | ||
} | ||
if (defined(request)) { | ||
//TODO deprecate |
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.
TODO
Source/Core/loadText.js
Outdated
}); | ||
function loadText(urlOrResource, headers, request) { | ||
if (typeof urlOrResource === 'string') { | ||
urlOrResource = new Resource({ |
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.
Missing deprecation if headers
or request
is provided?
@@ -87,7 +89,7 @@ define([ | |||
that._isReady = true; | |||
} | |||
|
|||
when(loadImageViaBlob(options.missingImageUrl), success, failure); | |||
when(loadImageViaBlob(new Resource({url: options.missingImageUrl})), success, failure); |
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 file can be reverted.
Source/Scene/ImageryProvider.js
Outdated
}); | ||
} | ||
if (defined(request)) { | ||
//TODO deprecation warning |
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.
TODO
Phew, I started to run out of steam at the end there, but I think that's everything I have for my first pass. Awesome work @tfili (and thank you @hpinkos for getting the ball rolling). My main concern is the whole race condition/modification of resource issue I brought up in #6035 (comment) I would really appreciate another full set of eyeballs on this (particular your @shunter) so let me know what bribes you are currently accepting 😄 |
Added workaround for broken tilesets.
Ok, I think this is ready for another look. |
Thanks @tfili, I'll do another pass ASAP. |
@tfili is that last checkbox done, or is that still TODO? |
@tfili I'm getting 161 failures running the tests locally, do they pass for you? (I'm on Linux, I'll check the Windows side and see if it happens there too). I'm surprised travis is passing. |
@tfili never mind, false alarm. Looks like a GPU driver update was causing the issues. |
Source/Core/Request.js
Outdated
* | ||
* @returns {Request} The modified result parameter or a new Resource instance if one was not provided. | ||
*/ | ||
Request.prototype.clone = function(result) { |
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.
Looks like you have a comment in Resource.clone
about purposefully not cloning the request
, so is this still used or should this file be reverted?
I think that's the only other comments I have. Does anyone else want to look at this? At the very least it would be good if someone hammered on it some more in case there was any breaking I missed. (but it will also have 2 weeks in master to settle down before release, so we'll be fine either way). |
@mramato I reverted |
Congratulations on closing the issue! I found these Cesium forum links in the comments above: https://groups.google.com/d/topic/cesium-dev/3NxyEFmMzDM/discussion If this issue affects any of these threads, please post a comment like the following:
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
}); | ||
|
||
urlResource.addQueryParameters({ | ||
key: this._key |
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.
Adding the key here results in it being sent with every tile request, which is not correct. The key is only supposed to be sent with the metadata request, as it was in the previous code. I'll open a PR.
Not ready to merge, looking for early feedback on this approach.
An alternate solution for #6019 (based on #6019 (comment))
Instead of adding yet another argument to
loadWithXhr
, this creates aResource
class that handles all the arguments used byloadWithXhr
and methods for getting a derived resource with a modified url from the parent resource.Resource
will also help us replace all thejoinUrl
s and crazy url string concatenation we do all over the code base. Instead of building a url with a query string by appending them together, it has separateurl
,queryParameter
andhash
properties so we can make changes to them separately. The getter forurl
builds the final url from all of these pieces.@mramato @shunter what do you think of this approach vs #6019? Is this what you had in mind?
The changes I made thus far were fairly painless. I left the more complicated ones for the end:
Other TODOs:
Resource
object that a class may have taken separately (usuallyproxy
,headers
orquery
) Deprecation for resources #6120joinUrls
.loadImage
allowCrossOrigin
is used properly.loadWithXhr
andloadImage
Resource
for the above classesResource
class