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://myip.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?
How can I do this?