Skip to content

Add source option to TileDebug #16279

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

Merged
merged 5 commits into from
Nov 30, 2024

Conversation

mike-000
Copy link
Contributor

@mike-000 mike-000 commented Oct 12, 2024

Adds a source option to TileDebug to allow easy use of settings from another tile source.
Adds a non-API getter to GeoTIFF to obtain to the transform matrix for any ModelTransformation.
Updates the COG with ModelTransformation example to show tile coordinates.

The PR currently uses one commit cherry picked from #16280 to enable correct reprojection of TileDebug.

Browser tests added, and one ModelTransformation rendering test updated to include TileDebug.

Copy link

📦 Preview the website for this branch here: https://deploy-preview-16279--ol-site.netlify.app/.

@mike-000 mike-000 marked this pull request as ready for review October 12, 2024 10:42
@mike-000 mike-000 changed the title Support GeoTIFF ModelTransformation transformMatrrix in TileDebug Support GeoTIFF ModelTransformation transformMatrix in TileDebug Oct 12, 2024
@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch from 5cfb105 to b6a91ff Compare October 12, 2024 12:17
@ahocevar
Copy link
Member

I'm not in favour of exposing the transform matrix to the public API for now. It's good to have it internally, but let's wait a few release cycles and see if there's really a need for it to be used externally.

@mike-000
Copy link
Contributor Author

Yes, without the matrix the debug tiles would still appear, just not in the same place as the GeoTIFF. The code setting tile (texture) sizes to integer values is still needed as many GeoTIFFs (including the one in the example) return a tile grid with fractional sizes which don't work with reprojection. However any integer values should be valid, not just the rounded down sizes set here, so that could be moved to one fix for #16278 (which looks like two separate bugs).

@mike-000 mike-000 marked this pull request as draft October 12, 2024 20:32
@mike-000
Copy link
Contributor Author

I think a better way would be for TileDebug to take a source option. projection, tileGrid, wrapX, zDirection and transformMatrix could be obtained from that without exposing any additional getters to the API. The existing options, if set, could be used to override those obtained from source. If not ready source would be disregarded, or an error thrown.

@ahocevar
Copy link
Member

Yes, that would make for a nice API. And it could also work when the source is not yet ready, by waiting until the source is ready before the TileDebug source is configured.

@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch 2 times, most recently from 4342cd8 to 6c51fc2 Compare October 14, 2024 20:17
@mike-000 mike-000 changed the title Support GeoTIFF ModelTransformation transformMatrix in TileDebug Add source option to TileDebug Oct 14, 2024
@mike-000 mike-000 marked this pull request as ready for review October 14, 2024 20:30
@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch 2 times, most recently from c769ea0 to 3f746f6 Compare October 17, 2024 13:26
@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch 3 times, most recently from 6153f70 to af5b777 Compare November 3, 2024 14:49
@mike-000
Copy link
Contributor Author

mike-000 commented Nov 7, 2024

Yes, that would make for a nice API. And it could also work when the source is not yet ready, by waiting until the source is ready before the TileDebug source is configured.

Done, and ready for another review.

Comment on lines 1025 to 1027
getTransformMatrix() {
return this.transformMatrix?.slice() || null;
}
Copy link
Member

Choose a reason for hiding this comment

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

Since this is only used internally, it would be better to remove the @protected flag from ol/source/DataTile#transformMatrix, and get rid of this getter. On a related note, a getter returning a copy of something is not really a getter.

Comment on lines 78 to 80
if (source instanceof GeoTIFF) {
this.transformMatrix = source.getTransformMatrix();
}
Copy link
Member

Choose a reason for hiding this comment

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

The instanceof check should check for DataTile instead of GeoTIFF, and a copy of the member property instead of the getter should be used when assigning this.transformMatrix.

<form>
<div class="form-check">
<input class="form-check-input" type="checkbox" id="show-tiles" checked />
<label class="form-check-label" for="show-tiles">Show tile coordinates</label><br>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<label class="form-check-label" for="show-tiles">Show tile coordinates</label><br>
<label class="form-check-label" for="show-tiles">Show source tile coordinates</label><br>

Set integer tile sizes (avoid increasing pixel ratio)
@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch from e1f1389 to 8c11d7e Compare November 30, 2024 11:52
Comment on lines 23 to 27
const invert = (band, power) => ['-', 1, ['^', ['band', band], power]];
const showTilesCheckbox = document.getElementById('show-tiles');
const debugLayer = new TileLayer({
source: new TileDebug({source: cogSource}),
style: {
color: ['array', invert(1, 4), invert(2, 4), 0, ['band', 4]],
},
visible: showTilesCheckbox.checked,
});
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const invert = (band, power) => ['-', 1, ['^', ['band', band], power]];
const showTilesCheckbox = document.getElementById('show-tiles');
const debugLayer = new TileLayer({
source: new TileDebug({source: cogSource}),
style: {
color: ['array', invert(1, 4), invert(2, 4), 0, ['band', 4]],
},
visible: showTilesCheckbox.checked,
});
const showTilesCheckbox = document.getElementById('show-tiles');
const debugLayer = new TileLayer({
source: new TileDebug({source: cogSource}),
visible: showTilesCheckbox.checked,
});

Nice way to change the colors, but let's try to keep the example's focus on what's in the title and description.

@mike-000 mike-000 force-pushed the TileDebug-transformMatrix branch from d1adce0 to ba500b2 Compare November 30, 2024 20:48
Copy link
Member

@ahocevar ahocevar left a comment

Choose a reason for hiding this comment

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

Thanks, @mike-000

@ahocevar ahocevar merged commit 4b86823 into openlayers:main Nov 30, 2024
8 checks passed
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.

2 participants