Merge git://github.com/jonatkins/ingress-intel-total-conversion into dev

This commit is contained in:
Morgan Jones
2013-04-27 13:09:00 -05:00
13 changed files with 427 additions and 445 deletions

View File

@ -119,7 +119,7 @@ window.setupMap = function() {
//their usage policy has no limits (except required notification above 4000 tiles/sec - we're perhaps at 50 tiles/sec based on CloudMade stats)
var mqSubdomains = [ 'otile1','otile2', 'otile3', 'otile4' ];
var mqTileUrlPrefix = window.location.protocol !== 'https:' ? 'http://{s}.mqcdn.com' : 'https://{s}-s.mqcdn.com';
var mqMapOpt = {attribution: osmAttribution+', Tiles Courtesy of MapQuest', mazZoom: 18, detectRetena: true, subdomains: mqSubdomains};
var mqMapOpt = {attribution: osmAttribution+', Tiles Courtesy of MapQuest', maxZoom: 18, detectRetena: true, subdomains: mqSubdomains};
var mqMap = new L.TileLayer(mqTileUrlPrefix+'/tiles/1.0.0/map/{z}/{x}/{y}.jpg',mqMapOpt);
//MapQuest satellite coverage outside of the US is rather limited - so not really worth having as we have google as an option
//var mqSatOpt = {attribution: 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency', mazZoom: 18, detectRetena: true, subdomains: mqSubdomains};
@ -127,10 +127,11 @@ window.setupMap = function() {
var views = [
/*0*/ mqMap,
/*1*/ new L.Google('INGRESS'),
/*2*/ new L.Google('ROADMAP'),
/*1*/ new L.Google('INGRESS',{maxZoom:20}),
/*2*/ new L.Google('ROADMAP',{maxZoom:20}),
/*3*/ new L.Google('SATELLITE',{maxZoom:20}),
/*4*/ new L.Google('HYBRID',{maxZoom:20})
/*4*/ new L.Google('HYBRID',{maxZoom:20}),
/*5*/ new L.Google('TERRAIN',{maxZoom:15})
];
@ -161,7 +162,8 @@ window.setupMap = function() {
'Default Ingress Map': views[1],
'Google Roads': views[2],
'Google Satellite': views[3],
'Google Hybrid': views[4]
'Google Hybrid': views[4],
'Google Terrain': views[5]
}, addLayers);
map.addControl(window.layerChooser);

View File

@ -12,34 +12,30 @@ window.requestData = function() {
requests.abort();
cleanUp();
var magic = convertCenterLat(map.getCenter().lat);
var R = calculateR(magic);
var bounds = map.getBounds();
// convert to point values
topRight = convertLatLngToPoint(bounds.getNorthEast(), magic, R);
bottomLeft = convertLatLngToPoint(bounds.getSouthWest() , magic, R);
// how many quadrants intersect the current view?
quadsX = Math.abs(bottomLeft.x - topRight.x);
quadsY = Math.abs(bottomLeft.y - topRight.y);
var x1 = lngToTile(bounds.getNorthWest().lng, map.getZoom());
var x2 = lngToTile(bounds.getNorthEast().lng, map.getZoom());
var y1 = latToTile(bounds.getNorthWest().lat, map.getZoom());
var y2 = latToTile(bounds.getSouthWest().lat, map.getZoom());
// will group requests by second-last quad-key quadrant
tiles = {};
// walk in x-direction, starts right goes left
for(var i = 0; i <= quadsX; i++) {
var x = Math.abs(topRight.x - i);
var qk = pointToQuadKey(x, topRight.y);
var bnds = convertPointToLatLng(x, topRight.y, magic, R);
if(!tiles[qk.slice(0, -1)]) tiles[qk.slice(0, -1)] = [];
tiles[qk.slice(0, -1)].push(generateBoundsParams(qk, bnds));
// walk in y-direction, starts top, goes down
for(var j = 1; j <= quadsY; j++) {
var qk = pointToQuadKey(x, topRight.y + j);
var bnds = convertPointToLatLng(x, topRight.y + j, magic, R);
if(!tiles[qk.slice(0, -1)]) tiles[qk.slice(0, -1)] = [];
tiles[qk.slice(0, -1)].push(generateBoundsParams(qk, bnds));
for (var x = x1; x <= x2; x++) {
for (var y = y1; y <= y2; y++) {
var tile_id = pointToTileId(map.getZoom(), x, y);
var bucket = Math.floor(x / 2) + "" + Math.floor(y / 2);
if (!tiles[bucket])
tiles[bucket] = [];
tiles[bucket].push(generateBoundsParams(
tile_id,
tileToLat(y + 1, map.getZoom()),
tileToLng(x, map.getZoom()),
tileToLat(y, map.getZoom()),
tileToLng(x + 1, map.getZoom())
));
}
}
@ -78,7 +74,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
// portals can be brought to front, this costs extra time. They need
// to be in the foreground, or they cannot be clicked. See
// https://github.com/Leaflet/Leaflet/issues/185
var ppp = [];
var ppp = {};
var p2f = {};
$.each(m, function(qk, val) {
$.each(val.deletedGameEntityGuids || [], function(ind, guid) {
@ -115,7 +111,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
ent[2].imageByUrl = {'imageUrl': DEFAULT_PORTAL_IMG};
}
ppp.push(ent); // delay portal render
ppp[ent[0]] = ent; // delay portal render
} else if(ent[2].edge !== undefined) {
renderLink(ent);
} else if(ent[2].capturedRegion !== undefined) {
@ -132,6 +128,25 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
});
$.each(ppp, function(ind, portal) {
if ('portalV2' in portal[2] && 'linkedEdges' in portal[2].portalV2) {
$.each(portal[2].portalV2.linkedEdges, function (ind, edge) {
if (!ppp[edge.otherPortalGuid])
return;
renderLink([
edge.edgeGuid,
portal[1],
{
"controllingTeam": portal[2].controllingTeam,
"edge": {
"destinationPortalGuid": edge.isOrigin ? ppp[edge.otherPortalGuid][0] : portal[0],
"destinationPortalLocation": edge.isOrigin ? ppp[edge.otherPortalGuid][2].locationE6 : portal[2].locationE6,
"originPortalGuid": !edge.isOrigin ? ppp[edge.otherPortalGuid][0] : portal[0],
"originPortalLocation": !edge.isOrigin ? ppp[edge.otherPortalGuid][2].locationE6 : portal[2].locationE6
}
}
]);
});
}
if(portal[2].portalV2['linkedFields'] === undefined) {
portal[2].portalV2['linkedFields'] = [];
}

View File

@ -1,65 +1,45 @@
// 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
// is currently visible) it first calculates which tiles intersect.
// For all those tiles, it then calculates the lat/lng bounds of that
// tile and a quadkey. Both the bounds and the quadkey are “somewhat”
// required to get complete data. No idea how the projection between
// lat/lng and tiles works.
// What follows now are functions that allow conversion between tiles
// and lat/lng as well as calculating the quad key. The variable names
// may be misleading.
// The minified source for this code was in gen_dashboard.js after the
// “// input 89” line (alternatively: the class was called “Xe”).
// required to get complete data.
//
// Convertion functions courtesy of
// http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
window.convertCenterLat = function(centerLat) {
return Math.round(256 * 0.9999 * Math.abs(1 / Math.cos(centerLat * DEG2RAD)));
window.lngToTile = function(lng, zoom) {
return Math.floor((lng + 180) / 360 * Math.pow(2, zoom));
}
window.calculateR = function(convCenterLat) {
return 1 << window.map.getZoom() - (convCenterLat / 256 - 1);
window.latToTile = function(lat, zoom) {
return Math.floor((1 - Math.log(Math.tan(lat * Math.PI / 180) +
1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, zoom));
}
window.convertLatLngToPoint = function(latlng, magic, R) {
var x = (magic + latlng.lng * magic / 180)*R;
var l = Math.sin(latlng.lat * DEG2RAD);
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)};
window.tileToLng = function(x, zoom) {
return x / Math.pow(2, zoom) * 360 - 180;
}
window.convertPointToLatLng = function(x, y, magic, R) {
var e = {};
e.sw = {
// 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 - 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 - Math.PI*y/R)))/Math.PI - 90,
lng: 180*(x+1)/R-180
};
return e;
window.tileToLat = function(y, zoom) {
var n = Math.PI - 2 * Math.PI * y / Math.pow(2, zoom);
return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
}
// calculates the quad key for a given point. The point is not(!) in
// lat/lng format.
window.pointToQuadKey = function(x, y) {
return window.map.getZoom() + "_" + x + "_" + y;
window.pointToTileId = function(zoom, x, y) {
return zoom + "_" + x + "_" + y;
}
// given quadkey and bounds, returns the format as required by the
// given tile id and bounds, returns the format as required by the
// Ingress API to request map data.
window.generateBoundsParams = function(quadkey, bounds) {
window.generateBoundsParams = function(tile_id, minLat, minLng, maxLat, maxLng) {
return {
id: quadkey,
qk: quadkey,
minLatE6: Math.round(bounds.sw.lat * 1E6),
minLngE6: Math.round(bounds.sw.lng * 1E6),
maxLatE6: Math.round(bounds.ne.lat * 1E6),
maxLngE6: Math.round(bounds.ne.lng * 1E6)
id: tile_id,
qk: tile_id,
minLatE6: Math.round(minLat * 1E6),
minLngE6: Math.round(minLng * 1E6),
maxLatE6: Math.round(maxLat * 1E6),
maxLngE6: Math.round(maxLng * 1E6)
};
}

View File

@ -137,7 +137,7 @@ window.showPortalPosLinks = function(lat, lng, name) {
portal_name = encodeURIComponent(' (' + name + ')');
}
if (typeof android !== 'undefined' && android && android.intentPosLink) {
android.intentPosLink(window.location.protocol + '//maps.google.com/?q='+lat+','+lng);
android.intentPosLink(lat, lng, portal_name);
} else {
var qrcode = '<div id="qrcode"></div>';
var script = '<script>$(\'#qrcode\').qrcode({text:\'GEO:'+lat+','+lng+'\'});</script>';
@ -202,8 +202,8 @@ window.renderLimitReached = function(ratio) {
window.getMinPortalLevel = function() {
var z = map.getZoom();
if(z >= 16) return 0;
var conv = ['impossible', 8,7,7,6,6,5,5,4,4,3,3,2,2,1,1];
if(z >= 17) return 0;
var conv = ['impossible', 8,8,8,7,7,6,6,5,4,4,3,3,2,2,1,1];
var minLevelByRenderLimit = portalRenderLimit.getMinLevel();
var result = minLevelByRenderLimit > conv[z]
? minLevelByRenderLimit
@ -233,6 +233,7 @@ window.getTypeByGuid = function(guid) {
// portals end in “.11” or “.12“, links in “.9", fields in “.b”
// .11 == portals
// .12 == portals
// .16 == portals
// .9 == links
// .b == fields
// .c == player/creator
@ -246,6 +247,7 @@ window.getTypeByGuid = function(guid) {
switch(guid.slice(33)) {
case '11':
case '12':
case '16':
return TYPE_PORTAL;
case '9':