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
feat: add collections option to OGCVectorTile source #15792
Conversation
📦 Preview the website for this branch here: https://deploy-preview-15792--ol-site.netlify.app/. |
Co-authored-by: Andreas Hocevar <andreas.hocevar@gmail.com>
Good points @ahocevar. Applied the suggestions. |
While having another look at it, it looks like the suggested approach does change the semantics a little in the sense that previously we did not add a domain for the case that So I think the initial approach should be used instead. |
@jansule Can you elaborate on what the difference would be? If The reason for the failing test is that Node does not have a |
If
The url should always be resolved to Resolving urls without a domain in relation to its service will already be done by https://github.com/openlayers/openlayers/blob/main/src/ol/source/ogcTileUtil.js#L341. So using |
Got it, thanks for the explanation. Then instead of One more thing: isn't the collections option also specified for OGCMapTile? |
But you're right, @jansule. Looking at the rest of the OGC API code, this should also work with local files, so using the URL constructor like in my suggestion indeed isn't the best thing to do. |
Yes it is. I thought it would be better to do separate PRs for that.
So should I just revert the last commit, or should I check again to see if I can simplify the code a little? |
I think you should at least get rid of the try/catch. Maybe not using the URL constructor at all would yield simpler code. Regarding OGCMapTile: since it's the same code, you might add that in this pull request, and create a common function instead of duplicating the code there. |
This reverts commit 73853e5.
@jansule I think something like this might be a good solution: if (collections && collections.length) {
// According to conformance class
// http://www.opengis.net/spec/ogcapi-tiles-1/1.0/conf/collections-selection
// commata in the identifiers of the `collections` query parameter
// need to be URLEncoded, while the commata separating the identifiers
// should not.
const url = new URL(tileUrlTemplate, 'file:/');
if (url.pathname.split('/').includes('collections')) {
logError(
'The "collections" query parameter cannot be added to collection endpoints',
);
return tileUrlTemplate;
}
const encodedCollections = collections
.map((c) => encodeURIComponent(c))
.join(',');
url.searchParams.append('collections', encodedCollections);
const baseUrl = tileUrlTemplate.split('?')[0];
const queryParams = decodeURIComponent(url.searchParams.toString());
return `${baseUrl}?${queryParams}`;
} It does use the URL constructor, but takes the |
Yes, came to the same solution 😀 Do you know any example service that provides dataset tilesets ( |
ee49a2e
to
f93b83a
Compare
Thanks for your continued effort, @jansule. Unfortunately I don't have an example for an OGCMapTile data set with collections. |
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, @jansule !
} | ||
|
||
// making sure we can always construct a URL instance. | ||
const url = new URL(tileUrlTemplate, 'file://'); |
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.
Minor but one slash is enough:
const url = new URL(tileUrlTemplate, 'file://'); | |
const url = new URL(tileUrlTemplate, 'file:/'); |
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.
Oops. I forgot to wait for this. Maybe something for a quick follow-up fix.
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.
Created a follow up PR: #15809
This adds support for the OGC API Tiles Part 1 - Core "Collections Selection" conformance class for the OGCVectorTile source.
This solves #15791