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

Simplify tilegrid API and internals #3815

Merged
merged 10 commits into from
Jun 19, 2015

Conversation

ahocevar
Copy link
Member

From talking clients through all iterations of the tilegrid API when using custom tile url functions, and from experiences with the ol3-cesium integration of tile layers, it became clear that things are still not straightforward:

  • Tile coordinates for WMS and ArcGISRest increase from bottom to top, but those used by XYZ tile grids increase from top to bottom. This requires different code paths when using the tile url function. The fix from this pull request is to remove tile coord transforms altogether, so application developers always know that ol.TileCoord has y values increasing from bottom to top.
  • XYZ tile grids use a top-left origin, all other tile grids use a bottom-left origin. With tile coord transforms removed, this means that custom tile url functions get different tile coordinates for different sources and tile grids. This pull request changes all tile grids that OpenLayers creates to use the top-left corner of the extent as origin.

With these API simplifications, it is also possible to simplify tile grid handling internally. The Zoomify tile grid can finally be removed, because ol.tilegrid.TileGrid now provides everything that the Zoomify tile source needs.

@ahocevar ahocevar force-pushed the tilegrid-no-surprises branch 5 times, most recently from e8f32dc to 240e683 Compare June 18, 2015 16:41
@bjornharrtell
Copy link
Contributor

Nice!


The first `tileCoord` argument of `ol.TileUrlFunctionType` now expects transformed tile coordinates instead of internal OpenLayers tile coordinates. Accordingly, `ol.tilegrid.TileGrid#getTileCoordForCoordAndZ` and `ol.tilegrid.TileGrid#getTileCoordForCoordAndResolution` now return transformed tile coordinates.
Previously, tile grids created by OpenLayers either had their origin at the top-left or at the bottom-left corner of the tile grid. To make it easier to for application developers to transform tile coordinates to the common XYZ tiling scheme, all tile grids that OpenLayers creates internally have their origin now at the top-left corner.
Copy link
Member

Choose a reason for hiding this comment

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

Don't you mean bottom-left here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's the top-left corner of the extent now. But the tile coordinates increase upwards.

Copy link
Member

Choose a reason for hiding this comment

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

"of the extent" was what I was missing. I got it.

Copy link
Contributor

Choose a reason for hiding this comment

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

/easier to for/easier for/

var adjustX = reverseIntersectionPolicy ? 0.5 : 0;
var adjustY = reverseIntersectionPolicy ? 0 : 0.5;
var xFromOrigin = Math.floor((x - origin[0]) / resolution + adjustX);
var yFromOrigin = Math.floor((y - origin[1]) / resolution + adjustY);
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Two reasons:

  1. The change from (whatever) | 0 to Math.floor(whatever) was necessary because (Infinity) | 0 is 0, but we need the result of Math.floor(Infinity), which is Infinity.
  2. The yadjustment for snapping to screen pixels was previously incorrect, because screen coordinates increase downwards, but map coordinates increase upwards. The tests caught this problem after changing the origin to the top-left corner of the extent.

@elemoine
Copy link
Member

I just added questions for me to understand. I think this no-surprises branch is just great. Please merge.

@ahocevar
Copy link
Member Author

Thanks for the review @elemoine. I'll add 'of the extent' to the upgrade notes, so it will be easier for others to understand the change too. I'll also change the wording 'from bottom to top' to 'upwards' and 'from top to bottom' to downwards, as @tschaub suggested yesterday. Then I'll merge.

ahocevar added a commit that referenced this pull request Jun 19, 2015
Simplify tilegrid API and internals
@ahocevar ahocevar merged commit 5c5364b into openlayers:master Jun 19, 2015
@ahocevar ahocevar deleted the tilegrid-no-surprises branch June 19, 2015 17:05

The first `tileCoord` argument of `ol.TileUrlFunctionType` now expects transformed tile coordinates instead of internal OpenLayers tile coordinates. Accordingly, `ol.tilegrid.TileGrid#getTileCoordForCoordAndZ` and `ol.tilegrid.TileGrid#getTileCoordForCoordAndResolution` now return transformed tile coordinates.
Previously, tile grids created by OpenLayers either had their origin at the top-left or at the bottom-left corner of the extent. To make it easier to for application developers to transform tile coordinates to the common XYZ tiling scheme, all tile grids that OpenLayers creates internally have their origin now at the top-left corner of the extent.
Copy link
Contributor

Choose a reason for hiding this comment

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

/easier to for/easier for/

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.

4 participants