Merge branch 'master' into highlighter
This commit is contained in:
		| @@ -12,34 +12,30 @@ window.requestData = function() { | |||||||
|   requests.abort(); |   requests.abort(); | ||||||
|   cleanUp(); |   cleanUp(); | ||||||
|  |  | ||||||
|   var magic = convertCenterLat(map.getCenter().lat); |  | ||||||
|   var R = calculateR(magic); |  | ||||||
|  |  | ||||||
|   var bounds = map.getBounds(); |   var bounds = map.getBounds(); | ||||||
|   // convert to point values |  | ||||||
|   topRight = convertLatLngToPoint(bounds.getNorthEast(), magic, R); |   var x1 = lngToTile(bounds.getNorthWest().lng, map.getZoom()); | ||||||
|   bottomLeft = convertLatLngToPoint(bounds.getSouthWest() , magic, R); |   var x2 = lngToTile(bounds.getNorthEast().lng, map.getZoom()); | ||||||
|   // how many quadrants intersect the current view? |   var y1 = latToTile(bounds.getNorthWest().lat, map.getZoom()); | ||||||
|   quadsX = Math.abs(bottomLeft.x - topRight.x); |   var y2 = latToTile(bounds.getSouthWest().lat, map.getZoom()); | ||||||
|   quadsY = Math.abs(bottomLeft.y - topRight.y); |  | ||||||
|  |  | ||||||
|   // will group requests by second-last quad-key quadrant |   // will group requests by second-last quad-key quadrant | ||||||
|   tiles = {}; |   tiles = {}; | ||||||
|  |  | ||||||
|   // walk in x-direction, starts right goes left |   // walk in x-direction, starts right goes left | ||||||
|   for(var i = 0; i <= quadsX; i++) { |   for (var x = x1; x <= x2; x++) { | ||||||
|     var x = Math.abs(topRight.x - i); |     for (var y = y1; y <= y2; y++) { | ||||||
|     var qk = pointToQuadKey(x, topRight.y); |       var tile_id = pointToTileId(map.getZoom(), x, y); | ||||||
|     var bnds = convertPointToLatLng(x, topRight.y, magic, R); |       var bucket = Math.floor(x / 2) + "" + Math.floor(y / 2); | ||||||
|     if(!tiles[qk.slice(0, -1)]) tiles[qk.slice(0, -1)] = []; |       if (!tiles[bucket]) | ||||||
|     tiles[qk.slice(0, -1)].push(generateBoundsParams(qk, bnds)); |         tiles[bucket] = []; | ||||||
|  |       tiles[bucket].push(generateBoundsParams( | ||||||
|     // walk in y-direction, starts top, goes down |         tile_id, | ||||||
|     for(var j = 1; j <= quadsY; j++) { |         tileToLat(y + 1, map.getZoom()), | ||||||
|       var qk = pointToQuadKey(x, topRight.y + j); |         tileToLng(x, map.getZoom()), | ||||||
|       var bnds = convertPointToLatLng(x, topRight.y + j, magic, R); |         tileToLat(y, map.getZoom()), | ||||||
|       if(!tiles[qk.slice(0, -1)]) tiles[qk.slice(0, -1)] = []; |         tileToLng(x + 1, map.getZoom()) | ||||||
|       tiles[qk.slice(0, -1)].push(generateBoundsParams(qk, bnds)); |       )); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -78,7 +74,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { | |||||||
|   // portals can be brought to front, this costs extra time. They need |   // portals can be brought to front, this costs extra time. They need | ||||||
|   // to be in the foreground, or they cannot be clicked. See |   // to be in the foreground, or they cannot be clicked. See | ||||||
|   // https://github.com/Leaflet/Leaflet/issues/185 |   // https://github.com/Leaflet/Leaflet/issues/185 | ||||||
|   var ppp = []; |   var ppp = {}; | ||||||
|   var p2f = {}; |   var p2f = {}; | ||||||
|   $.each(m, function(qk, val) { |   $.each(m, function(qk, val) { | ||||||
|     $.each(val.deletedGameEntityGuids || [], function(ind, guid) { |     $.each(val.deletedGameEntityGuids || [], function(ind, guid) { | ||||||
| @@ -115,7 +111,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { | |||||||
|           ent[2].imageByUrl = {'imageUrl': DEFAULT_PORTAL_IMG}; |           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) { |       } else if(ent[2].edge !== undefined) { | ||||||
|         renderLink(ent); |         renderLink(ent); | ||||||
|       } else if(ent[2].capturedRegion !== undefined) { |       } else if(ent[2].capturedRegion !== undefined) { | ||||||
| @@ -132,6 +128,25 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { | |||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   $.each(ppp, function(ind, portal) { |   $.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) { |     if(portal[2].portalV2['linkedFields'] === undefined) { | ||||||
|       portal[2].portalV2['linkedFields'] = []; |       portal[2].portalV2['linkedFields'] = []; | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,65 +1,45 @@ | |||||||
|  |  | ||||||
| // MAP DATA REQUEST CALCULATORS ////////////////////////////////////// | // MAP DATA REQUEST CALCULATORS ////////////////////////////////////// | ||||||
| // Ingress Intel splits up requests for map data (portals, links, | // Ingress Intel splits up requests for map data (portals, links, | ||||||
| // fields) into tiles. To get data for the current viewport (i.e. what | // fields) into tiles. To get data for the current viewport (i.e. what | ||||||
| // is currently visible) it first calculates which tiles intersect. | // is currently visible) it first calculates which tiles intersect. | ||||||
| // For all those tiles, it then calculates the lat/lng bounds of that | // 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” | // tile and a quadkey. Both the bounds and the quadkey are “somewhat” | ||||||
| // required to get complete data. No idea how the projection between | // required to get complete data. | ||||||
| // lat/lng and tiles works. | // | ||||||
| // What follows now are functions that allow conversion between tiles | // Convertion functions courtesy of | ||||||
| // and lat/lng as well as calculating the quad key. The variable names | // http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames | ||||||
| // 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”). |  | ||||||
|  |  | ||||||
| window.convertCenterLat = function(centerLat) { | window.lngToTile = function(lng, zoom) { | ||||||
|   return Math.round(256 * 0.9999 * Math.abs(1 / Math.cos(centerLat * DEG2RAD))); |   return Math.floor((lng + 180) / 360 * Math.pow(2, zoom)); | ||||||
| } | } | ||||||
|  |  | ||||||
| window.calculateR = function(convCenterLat) { | window.latToTile = function(lat, zoom) { | ||||||
|   return 1 << window.map.getZoom() - (convCenterLat / 256 - 1); |   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) { | window.tileToLng = function(x, zoom) { | ||||||
|   var x = (magic + latlng.lng * magic / 180)*R; |   return x / Math.pow(2, zoom) * 360 - 180; | ||||||
|   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.convertPointToLatLng = function(x, y, magic, R) { | window.tileToLat = function(y, zoom) { | ||||||
|   var e = {}; |   var n = Math.PI - 2 * Math.PI * y / Math.pow(2, zoom); | ||||||
|   e.sw = { |   return 180 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n))); | ||||||
|     // 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; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| // calculates the quad key for a given point. The point is not(!) in | window.pointToTileId = function(zoom, x, y) { | ||||||
| // lat/lng format. |   return zoom + "_" + x + "_" + y; | ||||||
| window.pointToQuadKey = function(x, y) { |  | ||||||
|   return window.map.getZoom() + "_" + 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. | // Ingress API to request map data. | ||||||
| window.generateBoundsParams = function(quadkey, bounds) { | window.generateBoundsParams = function(tile_id, minLat, minLng, maxLat, maxLng) { | ||||||
|   return { |   return { | ||||||
|     id: quadkey, |     id: tile_id, | ||||||
|     qk: quadkey, |     qk: tile_id, | ||||||
|     minLatE6: Math.round(bounds.sw.lat * 1E6), |     minLatE6: Math.round(minLat * 1E6), | ||||||
|     minLngE6: Math.round(bounds.sw.lng * 1E6), |     minLngE6: Math.round(minLng * 1E6), | ||||||
|     maxLatE6: Math.round(bounds.ne.lat * 1E6), |     maxLatE6: Math.round(maxLat * 1E6), | ||||||
|     maxLngE6: Math.round(bounds.ne.lng * 1E6) |     maxLngE6: Math.round(maxLng * 1E6) | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -201,8 +201,8 @@ window.renderLimitReached = function(ratio) { | |||||||
|  |  | ||||||
| window.getMinPortalLevel = function() { | window.getMinPortalLevel = function() { | ||||||
|   var z = map.getZoom(); |   var z = map.getZoom(); | ||||||
|   if(z >= 16) return 0; |   if(z >= 17) return 0; | ||||||
|   var conv = ['impossible', 8,7,7,6,6,5,5,4,4,3,3,2,2,1,1]; |   var conv = ['impossible', 8,8,8,7,7,6,6,5,4,4,3,3,2,2,1,1]; | ||||||
|   var minLevelByRenderLimit = portalRenderLimit.getMinLevel(); |   var minLevelByRenderLimit = portalRenderLimit.getMinLevel(); | ||||||
|   var result = minLevelByRenderLimit > conv[z] |   var result = minLevelByRenderLimit > conv[z] | ||||||
|     ? minLevelByRenderLimit |     ? minLevelByRenderLimit | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.js
									
									
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| // ==UserScript== | // ==UserScript== | ||||||
| // @id             ingress-intel-total-conversion@jonatkins | // @id             ingress-intel-total-conversion@jonatkins | ||||||
| // @name           IITC: Ingress intel map total conversion | // @name           IITC: Ingress intel map total conversion | ||||||
| // @version        0.11.0.@@DATETIMEVERSION@@ | // @version        0.11.2.@@DATETIMEVERSION@@ | ||||||
| // @namespace      https://github.com/jonatkins/ingress-intel-total-conversion | // @namespace      https://github.com/jonatkins/ingress-intel-total-conversion | ||||||
| // @updateURL      @@UPDATEURL@@ | // @updateURL      @@UPDATEURL@@ | ||||||
| // @downloadURL    @@DOWNLOADURL@@ | // @downloadURL    @@DOWNLOADURL@@ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user