I am trying to load tiles from WMS server, which are in WGS84 projection. I'm modifying the
MakeImageUrl(MapType type, Point pos, int zoom, string language)
function. I succeed getting some coordinates from the tile number through this code:
Point tilePoint = new Point(pos.X * 256, pos.Y * 256);
int pixelsPerRow = 256 * (int)Math.Pow((double)2.0, (double)zoom);
double resX = (double)(360 / (double)pixelsPerRow);
double resY = (double)(180 / (double)pixelsPerRow);
PointLatLng pntLatLng1 = new PointLatLng(tilePoint.X * resX - 180, 90 - ((tilePoint.Y * resY) + (256 * resY)));
PointLatLng pntLatLng2 = new PointLatLng(tilePoint.X * resX - 180 + 256 * resX, 90 - tilePoint.Y * resY);
I'll try to explain. First, we have 256x256px tiles and through tilePoint we get the top-left position of the tile. After that, we get the overall number of pixels according to the Zoom level (pixelsPerRow = pixelsPerColumn, because it's map 256x256px tiles
and the number of tiles are (4^zoom) for each zoom level, (2^zoom) number of tiles on a row/column, starting from 0).
Then we make resolution doubles, resX, resY and we get the number of degrees for each pixel.
Then, for WMS (official documentation) we need bottom-left and top-right points of the tile, to extract the information from the server, in Lat/Lng. So, we make pntLatLng1 (bottom-left) and pntLatLng2 (top-right) points. I'm sure the code is generating right
points, but the tile I get is not very "well-shaped". I mean, it is a little "elongated" to the poles. I think it's something to do with the "geoidic"
shape of the earth. =]
Am I correct, and can someone give directions, how to make the code "right".
These are the WGS84 settings:
radius a = 6,378,137 m at the equator
minor (conjugate) radius b = 6,356,752.314 245 m at the poles
flattening of 21.384 685 755 km, or 1/298.257 223 563 ≈ 0.335%
Thanks in advance!
Many thanks for the great project! =]