Updated quadkey calculations for new protocol

This commit is contained in:
goodsoft 2013-04-24 03:40:53 +03:00
parent 59094e48bc
commit d58306ec06

View File

@ -1,5 +1,4 @@
// MAP DATA REQUEST CALCULATORS //////////////////////////////////////
// Ingress Intel splits up requests for map data (portals, links,
// fields) into tiles. To get data for the current viewport (i.e. what
@ -23,9 +22,9 @@ window.calculateR = function(convCenterLat) {
}
window.convertLatLngToPoint = function(latlng, magic, R) {
var x = (magic/2 + latlng.lng * magic / 360)*R;
var x = (magic + latlng.lng * magic / 180)*R;
var l = Math.sin(latlng.lat * DEG2RAD);
var y = (magic/2 + 0.5*Math.log((1+l)/(1-l)) * -(magic / (2*Math.PI)))*R;
var y = (magic + Math.log((1+l)/(1-l)) * -(magic / (2*Math.PI)))*R;
return {x: Math.floor(x/magic), y: Math.floor(y/magic)};
}
@ -35,13 +34,13 @@ window.convertPointToLatLng = function(x, y, magic, R) {
// orig function put together from all over the place
// lat: (2 * Math.atan(Math.exp((((y + 1) * magic / R) - (magic/ 2)) / (-1*(magic / (2 * Math.PI))))) - Math.PI / 2) / (Math.PI / 180),
// shortened version by your favorite algebra program.
lat: (360*Math.atan(Math.exp(Math.PI - 2*Math.PI*(y+1)/R)))/Math.PI - 90,
lng: 360*x/R-180
lat: (360*Math.atan(Math.exp(Math.PI - Math.PI*(y+1)/R)))/Math.PI - 90,
lng: 180*x/R-180
};
e.ne = {
//lat: (2 * Math.atan(Math.exp(((y * magic / R) - (magic/ 2)) / (-1*(magic / (2 * Math.PI))))) - Math.PI / 2) / (Math.PI / 180),
lat: (360*Math.atan(Math.exp(Math.PI - 2*Math.PI*y/R)))/Math.PI - 90,
lng: 360*(x+1)/R-180
lat: (360*Math.atan(Math.exp(Math.PI - Math.PI*y/R)))/Math.PI - 90,
lng: 180*(x+1)/R-180
};
return e;
}
@ -49,7 +48,8 @@ window.convertPointToLatLng = function(x, y, magic, R) {
// calculates the quad key for a given point. The point is not(!) in
// lat/lng format.
window.pointToQuadKey = function(x, y) {
var quadkey = [];
return window.map.getZoom() + "_" + x + "_" + y;
/*var quadkey = [];
for(var c = window.map.getZoom(); c > 0; c--) {
// +-------+ quadrants are probably ordered like this
// | 0 | 1 |
@ -62,7 +62,7 @@ window.pointToQuadKey = function(x, y) {
(y & e) != 0 && (quadrant++, quadrant++); // push down
quadkey.push(quadrant);
}
return quadkey.join("");
return quadkey.join("");*/
}
// given quadkey and bounds, returns the format as required by the