I use gdal2tiles to create tiles from a referenced image (with profile parameter set to "raster"). Then I use Proj4Leaflet to display the results. In order to do that I need to specify parameters of CRS such as resoultions, bounds and origin. After processing i get tilemapresource.xml that seems to contain all the information needed:
<?xml version="1.0" encoding="utf-8"?> <TileMap version="1.0.0" tilemapservice="http://tms.osgeo.org/1.0.0"> <Title>OUTPUT.tif</Title> <Abstract></Abstract> <SRS>+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs</SRS> <BoundingBox minx="4081867.72157528297976" miny="-2321600.04517470393330" maxx="6014219.16503371112049" maxy="477065.79241934354650"/> <Origin x="4081867.72157528297976" y="-2321600.04517470393330"/> <TileFormat width="256" height="256" mime-type="image/png" extension="png"/> <TileSets profile="raster"> <TileSet href="0" units-per-pixel="14828.59620879369504" order="0"/> <TileSet href="1" units-per-pixel="7414.29810439684752" order="1"/> <TileSet href="2" units-per-pixel="3707.14905219842376" order="2"/> <TileSet href="3" units-per-pixel="1853.57452609921188" order="3"/> <TileSet href="4" units-per-pixel="926.78726304960594" order="4"/> <TileSet href="5" units-per-pixel="463.39363152480297" order="5"/> <TileSet href="6" units-per-pixel="231.69681576240149" order="6"/> </TileSets> </TileMap> Assuming
- origin = XML.Origin
- resolutions = XML.untis-per-pixel array
- bounds = XML.BoundingBox
I get correct Leaflet map - image sits where it should, coordinates returned by events are correct as well.
But bounds parameter actually stands for "Bounds of the CRS, in projected coordinates" according to the documentation (https://kartena.github.io/Proj4Leaflet/api/#l-proj-crs). And BoundingBox attribute in the .xml shows bounds of the tile layer, but not the whole CRS.
Docs and many tutorials also set resolutions parameter as array [... 2^(n+3), 2^(n+2), 2^(n+1), 2^n].
resolutions: [8192, 4096, 2048] // from the docs However resolutions in the .xml file are never 2^n. Again, using them is fine as the result is correct.
I seek explanations for such behaviour:
- Why resolutions of zoom levels are usually set to 2^n while in fact they are equal to some random numbers?
- Should I really use extent of the image as bounds (extent of the CRS)?