I want to implement a tile server and I'm following the code in the repo node-mapnik-sample-code.
When a request is sent with the parameters x, y, z (longitude, latitude, zoom), those parameters are used to create a bounding-box, with the following code:
/**
* Convert tile xyz value to Mapnik envelope
*
* @param {Number} x latitude number.
* @param {Number} y longitude number.
* @param {Number} zoom zoom.
* @param {Boolean} tms_style whether to compute a tms tile.
* @return Object Mapnik envelope.
*/
SphericalMercator.prototype.xyz_to_envelope = function(x, y, zoom, TMS_SCHEME) {
if (TMS_SCHEME) {
y = (Math.pow(2, zoom) - 1) - y;
}
var ll = [x * this.size, (y + 1) * this.size];
var ur = [(x + 1) * this.size, y * this.size];
var bbox = this.px_to_ll(ll, zoom).concat(this.px_to_ll(ur, zoom));
return mercator.forward(bbox);
};
(full code here: https://github.com/mapnik/node-mapnik-sample-code/blob/master/utils/sphericalmercator.js)
Why the longitude and latitude have to be multiplied by the tile size (256) here:
var ll = [x * this.size, (y + 1) * this.size];
I'm getting lost between pixels and geographic coordinates.