Merge branch 'gh-pages' into scoreboard
This commit is contained in:
31
code/boot.js
31
code/boot.js
@ -23,6 +23,25 @@ window.setupLargeImagePreview = function() {
|
||||
});
|
||||
}
|
||||
|
||||
// adds listeners to the layer chooser such that a long press hides
|
||||
// all custom layers except the long pressed one.
|
||||
window.setupLayerChooserSelectOne = function() {
|
||||
$('.leaflet-control-layers-overlays').on('click', 'label', function(e) {
|
||||
if(!e || !(e.metaKey || e.ctrlKey || e.shiftKey || e.altKey)) return;
|
||||
|
||||
var isChecked = $(this).find('input').is(':checked');
|
||||
var checkSize = $('.leaflet-control-layers-overlays input:checked').length;
|
||||
if((isChecked && checkSize === 1) || checkSize === 0) {
|
||||
// if nothing is selected or the users long-clicks the only
|
||||
// selected element, assume all boxes should be checked again
|
||||
$('.leaflet-control-layers-overlays input:not(:checked)').click();
|
||||
} else {
|
||||
// uncheck all
|
||||
$('.leaflet-control-layers-overlays input:checked').click();
|
||||
$(this).find('input').click();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.setupStyles = function() {
|
||||
$('head').append('<style>' +
|
||||
@ -167,13 +186,22 @@ window.setupPlayerStat = function() {
|
||||
|
||||
$('#playerstat').html(''
|
||||
+ '<h2 title="'+t+'">'+level+' '
|
||||
+ '<div id="name">'
|
||||
+ '<span class="'+cls+'">'+PLAYER.nickname+'</span>'
|
||||
+ '<div>'
|
||||
+ '<a href="https://www.ingress.com/_ah/logout?continue=https://www.google.com/accounts/Logout%3Fcontinue%3Dhttps://appengine.google.com/_ah/logout%253Fcontinue%253Dhttps://www.ingress.com/intel%26service%3Dah" id="signout">sign out</a>'
|
||||
+ '</div>'
|
||||
+ '<div id="stats">'
|
||||
+ '<sup>XM: '+xmRatio+'%</sup>'
|
||||
+ '<sub>' + (level < 8 ? 'level: '+lvlApProg+'%' : 'max level') + '</sub>'
|
||||
+ '</div>'
|
||||
+ '</h2>'
|
||||
);
|
||||
|
||||
$('#name').mouseenter(function() {
|
||||
$('#signout').show();
|
||||
}).mouseleave(function() {
|
||||
$('#signout').hide();
|
||||
});
|
||||
}
|
||||
|
||||
window.setupSidebarToggle = function() {
|
||||
@ -264,6 +292,7 @@ function boot() {
|
||||
window.setupTooltips();
|
||||
window.chat.setup();
|
||||
window.setupQRLoadLib();
|
||||
window.setupLayerChooserSelectOne();
|
||||
// read here ONCE, so the URL is only evaluated one time after the
|
||||
// necessary data has been loaded.
|
||||
urlPortal = getURLParam('pguid');
|
||||
|
12
code/chat.js
12
code/chat.js
@ -279,8 +279,14 @@ window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) {
|
||||
|
||||
case 'PORTAL':
|
||||
var latlng = [markup[1].latE6/1E6, markup[1].lngE6/1E6];
|
||||
var js = 'window.zoomToAndShowPortal(\''+markup[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])';
|
||||
msg += '<a onclick="'+js+'" title="'+markup[1].address+'" class="help">'+markup[1].name+'</a>';
|
||||
var perma = 'https://ingress.com/intel?latE6='+markup[1].latE6+'&lngE6='+markup[1].lngE6+'&z=17&pguid='+markup[1].guid;
|
||||
var js = 'window.zoomToAndShowPortal(\''+markup[1].guid+'\', ['+latlng[0]+', '+latlng[1]+']);return false';
|
||||
|
||||
msg += '<a onclick="'+js+'"'
|
||||
+ ' title="'+markup[1].address+'"'
|
||||
+ ' href="'+perma+'" class="help">'
|
||||
+ markup[1].name
|
||||
+ '</a>';
|
||||
break;
|
||||
|
||||
case 'SECURE':
|
||||
@ -341,7 +347,7 @@ window.chat.renderMsg = function(msg, nick, time, team) {
|
||||
var s = 'style="color:'+COLORS[team]+'"';
|
||||
var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : '';
|
||||
var i = ['<span class="invisep"><</span>', '<span class="invisep">></span>'];
|
||||
return '<tr><td>'+t+'</td><td>'+i[0]+'<mark '+s+'>'+nick+'</mark>'+i[1]+'</td><td>'+msg+'</td></tr>';
|
||||
return '<tr><td>'+t+'</td><td>'+i[0]+'<mark class="nickname" '+s+'>'+nick+'</mark>'+i[1]+'</td><td>'+msg+'</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,25 +43,34 @@ window.requestData = function() {
|
||||
}
|
||||
}
|
||||
|
||||
// Reset previous result of Portal Render Limit handler
|
||||
portalRenderLimit.init();
|
||||
// finally send ajax requests
|
||||
$.each(tiles, function(ind, tls) {
|
||||
data = { minLevelOfDetail: -1 };
|
||||
data.boundsParamsList = tls;
|
||||
window.requests.add(window.postAjax('getThinnedEntitiesV2', data, window.handleDataResponse));
|
||||
window.requests.add(window.postAjax('getThinnedEntitiesV2', data, window.handleDataResponse, window.handleFailedRequest));
|
||||
});
|
||||
}
|
||||
|
||||
// Handle failed map data request
|
||||
window.handleFailedRequest = function() {
|
||||
if(requests.isLastRequest('getThinnedEntitiesV2')) {
|
||||
var leftOverPortals = portalRenderLimit.mergeLowLevelPortals(null);
|
||||
handlePortalsRender(leftOverPortals);
|
||||
}
|
||||
}
|
||||
|
||||
// works on map data response and ensures entities are drawn/updated.
|
||||
window.handleDataResponse = function(data, textStatus, jqXHR) {
|
||||
// remove from active ajax queries list
|
||||
if(!data || !data.result) {
|
||||
window.failedRequestCount++;
|
||||
console.warn(data);
|
||||
handleFailedRequest();
|
||||
return;
|
||||
}
|
||||
|
||||
var portalUpdateAvailable = false;
|
||||
var portalInUrlAvailable = false;
|
||||
var m = data.result.map;
|
||||
// defer rendering of portals because there is no z-index in SVG.
|
||||
// this means that what’s rendered last ends up on top. While the
|
||||
@ -88,8 +97,6 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
||||
// format for portals: { controllingTeam, turret }
|
||||
|
||||
if(ent[2].turret !== undefined) {
|
||||
if(selectedPortal === ent[0]) portalUpdateAvailable = true;
|
||||
if(urlPortal && ent[0] == urlPortal) portalInUrlAvailable = true;
|
||||
|
||||
var latlng = [ent[2].locationE6.latE6/1E6, ent[2].locationE6.lngE6/1E6];
|
||||
if(!window.getPaddedBounds().contains(latlng)
|
||||
@ -114,7 +121,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$.each(ppp, function(ind, portal) {
|
||||
if(portal[2].portalV2['linkedFields'] === undefined) {
|
||||
portal[2].portalV2['linkedFields'] = [];
|
||||
@ -124,12 +131,29 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
||||
portal[2].portalV2['linkedFields'] = uniqueArray(p2f[portal[0]]);
|
||||
}
|
||||
});
|
||||
|
||||
// Process the portals with portal render limit handler first
|
||||
// Low level portal will hold until last request
|
||||
var newPpp = portalRenderLimit.splitOrMergeLowLevelPortals(ppp);
|
||||
handlePortalsRender(newPpp);
|
||||
|
||||
resolvePlayerNames();
|
||||
renderUpdateStatus();
|
||||
}
|
||||
|
||||
window.handlePortalsRender = function(portals) {
|
||||
var portalUpdateAvailable = false;
|
||||
var portalInUrlAvailable = false;
|
||||
|
||||
// Preserve and restore "selectedPortal" between portal re-render
|
||||
if(portalUpdateAvailable) var oldSelectedPortal = selectedPortal;
|
||||
|
||||
runHooks('portalDataLoaded', {portals : ppp});
|
||||
$.each(ppp, function(ind, portal) { renderPortal(portal); });
|
||||
runHooks('portalDataLoaded', {portals : portals});
|
||||
$.each(portals, function(ind, portal) {
|
||||
if(selectedPortal === portal[0]) portalUpdateAvailable = true;
|
||||
if(urlPortal && portal[0] == urlPortal) portalInUrlAvailable = true;
|
||||
renderPortal(portal);
|
||||
});
|
||||
|
||||
var selectedPortalLayer = portals[oldSelectedPortal];
|
||||
if(portalUpdateAvailable && selectedPortalLayer) selectedPortal = oldSelectedPortal;
|
||||
@ -146,7 +170,6 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
||||
}
|
||||
|
||||
if(portalUpdateAvailable) renderPortalDetails(selectedPortal);
|
||||
resolvePlayerNames();
|
||||
}
|
||||
|
||||
// removes entities that are still handled by Leaflet, although they
|
||||
|
@ -24,6 +24,7 @@ window.renderPortalDetails = function(guid) {
|
||||
var player = d.captured && d.captured.capturingPlayerId
|
||||
? getPlayerName(d.captured.capturingPlayerId)
|
||||
: null;
|
||||
player = '<span class="nickname">'+player+'</span>';
|
||||
var playerText = player ? ['owner', player] : null;
|
||||
|
||||
var time = d.captured
|
||||
@ -45,12 +46,12 @@ window.renderPortalDetails = function(guid) {
|
||||
|
||||
setPortalIndicators(d);
|
||||
var img = d.imageByUrl && d.imageByUrl.imageUrl
|
||||
? d.imageByUrl.imageUrl.replace(/^http:/, 'https:')
|
||||
? d.imageByUrl.imageUrl
|
||||
: DEFAULT_PORTAL_IMG;
|
||||
|
||||
var lat = d.locationE6.latE6;
|
||||
var lng = d.locationE6.lngE6;
|
||||
var perma = 'http://ingress.com/intel?latE6='+lat+'&lngE6='+lng+'&z=17&pguid='+guid;
|
||||
var perma = 'https://ingress.com/intel?latE6='+lat+'&lngE6='+lng+'&z=17&pguid='+guid;
|
||||
var imgTitle = 'title="'+getPortalDescriptionFromDetails(d)+'\n\nClick to show full image."';
|
||||
var poslinks = 'window.showPortalPosLinks('+lat/1E6+','+lng/1E6+')';
|
||||
var postcard = 'Send in a postcard. Will put it online after receiving. Address:\\n\\nStefan Breunig\\nINF 305 – R045\\n69120 Heidelberg\\nGermany';
|
||||
|
@ -132,6 +132,7 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick) {
|
||||
|
||||
var meter = '<span class="meter" title="'+inf+'">' + fill + lbar + '</span>';
|
||||
}
|
||||
nick = '<span class="nickname">'+nick+'</span>';
|
||||
return [meter, nick || ''];
|
||||
}
|
||||
|
||||
|
155
code/portal_render_limit.js
Normal file
155
code/portal_render_limit.js
Normal file
@ -0,0 +1,155 @@
|
||||
|
||||
// PORTAL RENDER LIMIT HANDLER ///////////////////////////////////////
|
||||
// Functions to handle hiding low level portal when portal render
|
||||
// limit is reached.
|
||||
//
|
||||
// On initialization, previous minLevel will preserve to previousMinLevel
|
||||
// with zoom level difference.
|
||||
//
|
||||
// After initialized and reset in window.requestData(), "processPortals"
|
||||
// intercept all portals data in "handleDataResponse". Put the count of
|
||||
// new portals to newPortalsPerLevel[portal level]. And split portals
|
||||
// into two parts base on previousMinLevel. Portals with level >=
|
||||
// previousMinLevel will return as result and continue to render.
|
||||
// Others will save to portalsPreviousMinLevel. If there is no more
|
||||
// active request of map data, portals will not split and
|
||||
// portalsPreviousMinLevel will add back to result and render base on
|
||||
// current minLevel.
|
||||
//
|
||||
// "handleFailRequest" is added to handle the case when the last request
|
||||
// failed and "processPortals" didn't get called. It will get
|
||||
// portalsPreviousMinLevel base on current minLevel and render them.
|
||||
//
|
||||
// "getMinLevel" will be called by "getMinPortalLevel" in utils_misc.js
|
||||
// to determine min portal level to draw on map.
|
||||
//
|
||||
// "getMinLevel" will return minLevel and call "setMinLevel" if
|
||||
// minLevel hasn't set yet.
|
||||
//
|
||||
// In "setMinLevel", it will loop through all portal level from
|
||||
// high to low, and sum total portal count (old + new) to check
|
||||
// minLevel.
|
||||
//
|
||||
// In each call of window.handleDataResponse(), it will call
|
||||
// "resetCounting" to reset previous response data. But minLevel
|
||||
// is preserved and only replaced when render limit reached in
|
||||
// higher level, until next window.requestData() called and reset.
|
||||
//
|
||||
|
||||
window.portalRenderLimit = function() {}
|
||||
|
||||
window.portalRenderLimit.initialized = false;
|
||||
window.portalRenderLimit.minLevelSet = false;
|
||||
window.portalRenderLimit.minLevel = -1;
|
||||
window.portalRenderLimit.previousMinLevel = -1;
|
||||
window.portalRenderLimit.previousZoomLevel;
|
||||
window.portalRenderLimit.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL + 1);
|
||||
window.portalRenderLimit.portalsPreviousMinLevel = new Array(MAX_PORTAL_LEVEL + 1);
|
||||
|
||||
window.portalRenderLimit.init = function () {
|
||||
var currentZoomLevel = map.getZoom();
|
||||
portalRenderLimit.previousZoomLevel = portalRenderLimit.previousZoomLevel || currentZoomLevel;
|
||||
|
||||
// If there is a minLevel set in previous run, calculate previousMinLevel with it.
|
||||
if(portalRenderLimit.minLevelSet) {
|
||||
var zoomDiff = currentZoomLevel - portalRenderLimit.previousZoomLevel;
|
||||
portalRenderLimit.previousMinLevel = Math.max(portalRenderLimit.minLevel - zoomDiff, -1);
|
||||
portalRenderLimit.previousMinLevel = Math.min(portalRenderLimit.previousMinLevel, MAX_PORTAL_LEVEL);
|
||||
}
|
||||
|
||||
portalRenderLimit.previousZoomLevel = currentZoomLevel;
|
||||
|
||||
portalRenderLimit.initialized = true;
|
||||
portalRenderLimit.minLevel = -1;
|
||||
portalRenderLimit.resetCounting();
|
||||
portalRenderLimit.resetPortalsPreviousMinLevel();
|
||||
}
|
||||
|
||||
window.portalRenderLimit.resetCounting = function() {
|
||||
portalRenderLimit.minLevelSet = false;
|
||||
for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) {
|
||||
portalRenderLimit.newPortalsPerLevel[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
window.portalRenderLimit.resetPortalsPreviousMinLevel = function() {
|
||||
for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) {
|
||||
portalRenderLimit.portalsPreviousMinLevel[i] = new Array();
|
||||
}
|
||||
}
|
||||
|
||||
window.portalRenderLimit.splitOrMergeLowLevelPortals = function(originPortals) {
|
||||
portalRenderLimit.resetCounting();
|
||||
portalRenderLimit.countingPortals(originPortals);
|
||||
|
||||
var resultPortals = requests.isLastRequest('getThinnedEntitiesV2')
|
||||
? portalRenderLimit.mergeLowLevelPortals(originPortals)
|
||||
: portalRenderLimit.splitLowLevelPortals(originPortals);
|
||||
|
||||
return resultPortals;
|
||||
}
|
||||
|
||||
window.portalRenderLimit.countingPortals = function(portals) {
|
||||
$.each(portals, function(ind, portal) {
|
||||
var portalGuid = portal[0];
|
||||
var portalLevel = parseInt(getPortalLevel(portal[2]));
|
||||
var layerGroup = portalsLayers[portalLevel];
|
||||
|
||||
if(findEntityInLeaflet(layerGroup, window.portals, portalGuid)) return true;
|
||||
|
||||
portalRenderLimit.newPortalsPerLevel[portalLevel]++;
|
||||
});
|
||||
}
|
||||
|
||||
window.portalRenderLimit.splitLowLevelPortals = function(portals) {
|
||||
var resultPortals = new Array();
|
||||
$.each(portals, function(ind, portal) {
|
||||
var portalLevel = parseInt(getPortalLevel(portal[2]));
|
||||
if(portalLevel < portalRenderLimit.previousMinLevel) {
|
||||
portalRenderLimit.portalsPreviousMinLevel[portalLevel].push(portal);
|
||||
}else{
|
||||
resultPortals.push(portal);
|
||||
}
|
||||
});
|
||||
return resultPortals;
|
||||
}
|
||||
|
||||
window.portalRenderLimit.mergeLowLevelPortals = function(appendTo) {
|
||||
var resultPortals = appendTo ? appendTo : new Array();
|
||||
for(var i = portalRenderLimit.getMinLevel();
|
||||
i < portalRenderLimit.previousMinLevel;
|
||||
i++) {
|
||||
$.merge(resultPortals, portalRenderLimit.portalsPreviousMinLevel[i]);
|
||||
}
|
||||
|
||||
// Reset portalsPreviousMinLevel, ensure they return only once
|
||||
portalRenderLimit.resetPortalsPreviousMinLevel();
|
||||
return resultPortals;
|
||||
}
|
||||
|
||||
window.portalRenderLimit.getMinLevel = function() {
|
||||
if(!portalRenderLimit.initialized) return -1;
|
||||
if(!portalRenderLimit.minLevelSet) portalRenderLimit.setMinLevel();
|
||||
return portalRenderLimit.minLevel;
|
||||
}
|
||||
|
||||
window.portalRenderLimit.setMinLevel = function() {
|
||||
var totalPortalsCount = 0;
|
||||
var newMinLevel = MAX_PORTAL_LEVEL + 1;
|
||||
|
||||
// Find the min portal level under render limit
|
||||
while(newMinLevel > 0) {
|
||||
var oldPortalCount = layerGroupLength(portalsLayers[newMinLevel - 1]);
|
||||
var newPortalCount = portalRenderLimit.newPortalsPerLevel[newMinLevel - 1];
|
||||
totalPortalsCount += oldPortalCount + newPortalCount;
|
||||
if(totalPortalsCount >= MAX_DRAWN_PORTALS)
|
||||
break;
|
||||
newMinLevel--;
|
||||
}
|
||||
|
||||
// If render limit reached at max portal level, still let portal at max level render
|
||||
newMinLevel = Math.min(newMinLevel, MAX_PORTAL_LEVEL);
|
||||
|
||||
portalRenderLimit.minLevel = Math.max(newMinLevel, portalRenderLimit.minLevel);
|
||||
portalRenderLimit.minLevelSet = true;
|
||||
}
|
@ -111,3 +111,14 @@ window.requests._callOnRefreshFunctions = function() {
|
||||
window.requests.addRefreshFunction = function(f) {
|
||||
window.requests._onRefreshFunctions.push(f);
|
||||
}
|
||||
|
||||
window.requests.isLastRequest = function(action) {
|
||||
var result = true;
|
||||
$.each(window.activeRequests, function(ind, req) {
|
||||
if(req.action === action) {
|
||||
result = false;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
@ -2,6 +2,14 @@
|
||||
|
||||
// UTILS + MISC ///////////////////////////////////////////////////////
|
||||
|
||||
window.layerGroupLength = function(layerGroup) {
|
||||
var layersCount = 0;
|
||||
var layers = layerGroup._layers;
|
||||
if (layers)
|
||||
layersCount = Object.keys(layers).length;
|
||||
return layersCount;
|
||||
}
|
||||
|
||||
// retrieves parameter from the URL?query=string.
|
||||
window.getURLParam = function(param) {
|
||||
var v = document.URL;
|
||||
@ -50,7 +58,7 @@ window.postAjax = function(action, data, success, error) {
|
||||
data = JSON.stringify($.extend({method: 'dashboard.'+action}, data));
|
||||
var remove = function(data, textStatus, jqXHR) { window.requests.remove(jqXHR); };
|
||||
var errCnt = function(jqXHR) { window.failedRequestCount++; window.requests.remove(jqXHR); };
|
||||
return $.ajax({
|
||||
var result = $.ajax({
|
||||
// use full URL to avoid issues depending on how people set their
|
||||
// slash. See:
|
||||
// https://github.com/breunigs/ingress-intel-total-conversion/issues/56
|
||||
@ -65,6 +73,8 @@ window.postAjax = function(action, data, success, error) {
|
||||
req.setRequestHeader('X-CSRFToken', readCookie('csrftoken'));
|
||||
}
|
||||
});
|
||||
result.action = action;
|
||||
return result;
|
||||
}
|
||||
|
||||
// converts unix timestamps to HH:mm:ss format if it was today;
|
||||
@ -152,7 +162,11 @@ 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];
|
||||
return conv[z];
|
||||
var minLevelByRenderLimit = portalRenderLimit.getMinLevel();
|
||||
var result = minLevelByRenderLimit > conv[z]
|
||||
? minLevelByRenderLimit
|
||||
: conv[z];
|
||||
return result;
|
||||
}
|
||||
|
||||
// returns number of pixels left to scroll down before reaching the
|
||||
|
Reference in New Issue
Block a user