How to transform EPSG:3857 to tile pixel coordinates at zoom factor 0?
This is the answer. Sometimes you have to go through all the process of asking a question to understand the solution. JavaScript:
/**
* Converts spherical web mercator to tile pixel X/Y at zoom level 0
* for 256x256 tile size and inverts y coordinates.
*
* @param {L.point} p Leaflet point in EPSG:3857
* @return {L.point} Leaflet point with tile pixel x and y corrdinates.
*/
function mercatorToPixels(p) {
var equator = 40075016.68557849;
var pixelX = (p.x + (equator / 2.0)) / (equator / 256.0);
var pixelY = ((p.y - (equator / 2.0)) / (equator / -256.0));
return L.point(pixelX, pixelY);
}
Explanation
The tile at zoom level 0 has a size of 40,075,016m * 40,075,016m. The tile size is 256px * 256px. The center of the web mercator is (0, 0).
- Translate the X-coordinate by a positiv half equator.
- Divide the X-result by the positive pixel size in meter.
- Translate the Y-coordinate by a negative half equator.
- Divide the Y-result by the negative pixel size in meter.
That's it.