Reputation: 912
I am setting up a WMTS client to consume tiles from tileserver.php.
To request a tile I need to pass in the identifier/layer, the zoom height, the col and row to the WMTS RESTful server and it will return the tile.
e.g. http://my ip.com/tileserver/tileserver.php?/index.json?/identifier/{z}/{x}/{y}.png
In my test environment I can manually choose a zoom level and my test code will correctly calculate the col(x) and row(y). I then can use this information to request the image.
This all works as expected.
However, now I need to workout how to programmatically determine the zoom height(z). E.g. as the user zooms in or out of an area, I will need to workout the appropriate zoom level to, in turn, request an image from the tile server at the zoom level that approximates what the user is expecting.
I assume, to workout the correct zoom level:
Determine the current bounding box for the user (this will be model space in a cad program). I will use the bounding box to get the linear width / height of the location they are located (in CAD).
Use the screen pixel size of the monitor to workout pixel per meter? Am I going in the right direction?
Can anyone help me sort out how to do this please?
Upvotes: 2
Views: 660
Reputation: 912
Ok, it has finally soaked in as to what the answer is.
I will note it here encase someone else needs to work this out and they don't want to waste days of their life and their employers money in trying to sort this.
TileSpan is what I was after. The TileSpan is the width of the image (tile) that is returned from the tileserver.
I will include the basic calculations below.
I need to use the zoom level that generates a tile with a TileSpan that is just larger than the width of the target area.
I will iterate the tile matrices to discover the correct tile matrix to use.
Here are the Tile Matrix calculations for TileSpan to clarify:
See page 22: https://portal.ogc.org/files/?artifact_id=35326[OpenGIS Web Map Tile Service Implementation Standard][1]
pixelSpan = scaleDenominator × 0.00028 / metersPerUnit(crs);
tileSpanX = tileWidth × pixelSpan;
tileSpanY = tileHeight × pixelSpan;
tileMatrixMaxX = tileMatrixMinX + tileSpanX × matrixWidth;
tileMatrixMinY = tileMatrixMaxY - tileSpanY × matrixHeight;
I will update this answer as I improve my understanding.
Upvotes: 1