// Основной рассчет QuadKey
// h - судя по всему, гуглокарта
var b = this.h, c = b.getBounds(), d = c.getNorthEast();
Math.round(d.lat() * 1E6);
Math.round(d.lng() * 1E6);
c = c.getSouthWest();
Math.round(c.lat() * 1E6);
Math.round(c.lng() * 1E6);
for(
var b = b.getCenter().lat(),
b = Math.round(256 * 0.9999 * Math.abs(1 / Math.cos(Ye(b)))),
b = new Ze(b),
d = b.fromLatLngToPoint(d, l),
d = new google.maps.Point(d.x * b.R, d.y * b.R),
d = cf(b, d),
c = b.fromLatLngToPoint(c, l),
c = new google.maps.Point(c.x * b.R, c.y * b.R),
e = cf(b, c),
c = Math.abs(e.x - d.x),
e = Math.abs(e.y - d.y),
f = [], g = 0
;g <= c
;g++) {
var h = Math.abs(d.x - g), i = d.y, p = {}, i = new google.maps.Point(h, i), q = $e(i);
...
// Q - искомый QuadKey
}
Функции
Ze.prototype.fromLatLngToPoint = function(a, b) {
var c = b || new google.maps.Point(0, 0), d = this.Ob;
c.x = d.x + a.lng() * this.Pb;
var e;
e = Math.sin(Ye(a.lat()));
-0.9999 != l && (e = Math.max(e, -0.9999));
0.9999 != l && (e = Math.min(e, 0.9999));
c.y = d.y + 0.5 * Math.log((1 + e) / (1 - e)) * -this.Qb;
return c
};
var Xe = 256;
function Ze(a) {
this.z = a;
this.Ob = new google.maps.Point(this.z / 2, this.z / 2);
this.Pb = this.z / 360;
this.Qb = this.z / (2 * Math.PI);
this.R = 1 << ZOOM_LEVEL - (this.z / Xe - 1)
}
function cf(a, b) {
return new google.maps.Point(Math.floor(b.x / a.z), Math.floor(b.y / a.z))
}
function bf(a, b) {
var c = new google.maps.Point(b.x, b.y + 1), d = new google.maps.Point(b.x + 1, b.y), c = a.fromPointToLatLng(af(a, c)), d = a.fromPointToLatLng(af(a, d)), e = {};
e.sw = c;
e.ne = d;
return e
}
function af(a, b) {
return new google.maps.Point(b.x * a.z / a.R, b.y * a.z / a.R)
}
function $e(a) {
for(var b = [], c = ZOOM_LEVEL;c > 0;c--) {
var d = 0, e = 1 << c - 1;
(a.x & e) != 0 && d++;
(a.y & e) != 0 && (d++, d++);
b.push(d)
}
return b.join("")
}
function Ye(a) {
return a * (Math.PI / 180)
}