Merge pull request #317 from Xelio/patch-portal-limit-reach-hide-low-level-2
New Feature: (method 2)Remove lower level portal when portal render limit reached
This commit is contained in:
commit
bbe67a6573
@ -43,6 +43,8 @@ window.requestData = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset previous result of Portal Render Limit handler
|
||||||
|
portalRenderLimit.init();
|
||||||
// finally send ajax requests
|
// finally send ajax requests
|
||||||
$.each(tiles, function(ind, tls) {
|
$.each(tiles, function(ind, tls) {
|
||||||
data = { minLevelOfDetail: -1 };
|
data = { minLevelOfDetail: -1 };
|
||||||
@ -70,6 +72,8 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
|||||||
// https://github.com/Leaflet/Leaflet/issues/185
|
// https://github.com/Leaflet/Leaflet/issues/185
|
||||||
var ppp = [];
|
var ppp = [];
|
||||||
var p2f = {};
|
var p2f = {};
|
||||||
|
// Reset new portals count of Portal Render Limit handler
|
||||||
|
portalRenderLimit.resetCounting();
|
||||||
$.each(m, function(qk, val) {
|
$.each(m, function(qk, val) {
|
||||||
$.each(val.deletedGameEntityGuids, function(ind, guid) {
|
$.each(val.deletedGameEntityGuids, function(ind, guid) {
|
||||||
if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) {
|
if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) {
|
||||||
@ -98,7 +102,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
|||||||
) return;
|
) return;
|
||||||
|
|
||||||
|
|
||||||
|
portalRenderLimit.pushPortal(ent);
|
||||||
ppp.push(ent); // delay portal render
|
ppp.push(ent); // delay portal render
|
||||||
} else if(ent[2].edge !== undefined) {
|
} else if(ent[2].edge !== undefined) {
|
||||||
renderLink(ent);
|
renderLink(ent);
|
||||||
@ -147,6 +151,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
|
|||||||
|
|
||||||
if(portalUpdateAvailable) renderPortalDetails(selectedPortal);
|
if(portalUpdateAvailable) renderPortalDetails(selectedPortal);
|
||||||
resolvePlayerNames();
|
resolvePlayerNames();
|
||||||
|
renderUpdateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes entities that are still handled by Leaflet, although they
|
// removes entities that are still handled by Leaflet, although they
|
||||||
|
80
code/portal_render_limit.js
Normal file
80
code/portal_render_limit.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
|
||||||
|
// PORTAL RENDER LIMIT HANDLER ///////////////////////////////////////
|
||||||
|
// Functions to handle hiding low level portal when portal render
|
||||||
|
// limit is reached.
|
||||||
|
//
|
||||||
|
// After initialized and reset in window.requestData(), portals in
|
||||||
|
// response data will pass to function "pushPortal". Each new portal
|
||||||
|
// not on the map will add 1 to newPortalsPerLevel[portal level].
|
||||||
|
//
|
||||||
|
// "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.newPortalsPerLevel = new Array(MAX_PORTAL_LEVEL + 1);
|
||||||
|
|
||||||
|
window.portalRenderLimit.init = function () {
|
||||||
|
portalRenderLimit.initialized = true;
|
||||||
|
portalRenderLimit.minLevel = -1;
|
||||||
|
portalRenderLimit.resetCounting();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.portalRenderLimit.resetCounting = function() {
|
||||||
|
portalRenderLimit.minLevelSet = false;
|
||||||
|
for(var i = 0; i <= MAX_PORTAL_LEVEL; i++) {
|
||||||
|
portalRenderLimit.newPortalsPerLevel[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.portalRenderLimit.pushPortal = function(ent) {
|
||||||
|
var portalGuid = ent[0];
|
||||||
|
var portalLevel = parseInt(getPortalLevel(ent[2]));
|
||||||
|
var layerGroup = portalsLayers[portalLevel];
|
||||||
|
|
||||||
|
if(findEntityInLeaflet(layerGroup, window.portals, ent[0])) return;
|
||||||
|
portalRenderLimit.newPortalsPerLevel[portalLevel]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
@ -2,6 +2,14 @@
|
|||||||
|
|
||||||
// UTILS + MISC ///////////////////////////////////////////////////////
|
// 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.
|
// retrieves parameter from the URL?query=string.
|
||||||
window.getURLParam = function(param) {
|
window.getURLParam = function(param) {
|
||||||
var v = document.URL;
|
var v = document.URL;
|
||||||
@ -152,7 +160,11 @@ window.getMinPortalLevel = function() {
|
|||||||
var z = map.getZoom();
|
var z = map.getZoom();
|
||||||
if(z >= 16) return 0;
|
if(z >= 16) return 0;
|
||||||
var conv = ['impossible', 8,7,7,6,6,5,5,4,4,3,3,2,2,1,1];
|
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
|
// returns number of pixels left to scroll down before reaching the
|
||||||
|
1
main.js
1
main.js
@ -188,6 +188,7 @@ window.DESTROY_FIELD = 750; //AP for destroying field
|
|||||||
window.CAPTURE_PORTAL = 500; //AP for capturing a portal
|
window.CAPTURE_PORTAL = 500; //AP for capturing a portal
|
||||||
window.DEPLOY_RESONATOR = 125; //AP for deploying a resonator
|
window.DEPLOY_RESONATOR = 125; //AP for deploying a resonator
|
||||||
window.COMPLETION_BONUS = 250; //AP for deploying all resonators on portal
|
window.COMPLETION_BONUS = 250; //AP for deploying all resonators on portal
|
||||||
|
window.MAX_PORTAL_LEVEL = 8;
|
||||||
|
|
||||||
// OTHER MORE-OR-LESS CONSTANTS //////////////////////////////////////
|
// OTHER MORE-OR-LESS CONSTANTS //////////////////////////////////////
|
||||||
window.TEAM_NONE = 0;
|
window.TEAM_NONE = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user