Display control field count

This commit is contained in:
Eashwar Ranganathan 2013-02-08 03:11:30 -08:00
parent d09e59049c
commit dc4cea2ed7
3 changed files with 57 additions and 8 deletions

View File

@ -69,8 +69,17 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
// 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 = {};
$.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) {
if(window.fields[guid] === undefined) return true;
$.each(window.fields[guid].options.vertices, function(ind, vertex) {
if(window.portals[vertex.guid] === undefined) return true;
fieldArray = window.portals[vertex.guid].options.portalV2.linkedFields;
fieldArray.splice($.inArray(guid, fieldArray), 1);
});
}
window.removeByGuid(guid); window.removeByGuid(guid);
}); });
@ -92,13 +101,26 @@ window.handleDataResponse = function(data, textStatus, jqXHR) {
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);
else if(ent[2].capturedRegion !== undefined) } else if(ent[2].capturedRegion !== undefined) {
renderField(ent); $.each(ent[2].capturedRegion, function(ind, vertex) {
else if(p2f[vertex.guid] === undefined)
throw('Unknown entity: ' + JSON.stringify(ent)); p2f[vertex.guid] = new Array();
p2f[vertex.guid].push(ent[0]);
}); });
renderField(ent);
} else {
throw('Unknown entity: ' + JSON.stringify(ent));
}
});
});
$.each(ppp, function(ind, portal) {
if(p2f[portal[0]] === undefined)
portal[2].portalV2['linkedFields'] = [];
else
portal[2].portalV2['linkedFields'] = $.unique(p2f[portal[0]]);
}); });
$.each(ppp, function(ind, portal) { renderPortal(portal); }); $.each(ppp, function(ind, portal) { renderPortal(portal); });
@ -143,8 +165,8 @@ window.cleanUp = function() {
console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields'); console.log('removed out-of-bounds: '+cnt[0]+' portals, '+cnt[1]+' links, '+cnt[2]+' fields');
} }
// removes given entity from map // translates guids to entity types
window.removeByGuid = function(guid) { window.getTypeByGuid = function(guid) {
// portals end in “.11” or “.12“, links in “.9", fields in “.b” // portals end in “.11” or “.12“, links in “.9", fields in “.b”
// .11 == portals // .11 == portals
// .12 == portals // .12 == portals
@ -155,16 +177,39 @@ window.removeByGuid = function(guid) {
switch(guid.slice(33)) { switch(guid.slice(33)) {
case '11': case '11':
case '12': case '12':
return TYPE_PORTAL;
break;
case '9':
return TYPE_LINK;
break;
case 'b':
return TYPE_FIELD;
break;
case 'c':
return TYPE_PLAYER;
break;
case 'd':
return TYPE_CHAT;
break;
default:
return TYPE_UNKNOWN;
}
}
// removes given entity from map
window.removeByGuid = function(guid) {
switch(getTypeByGuid(guid)) {
case TYPE_PORTAL:
if(!window.portals[guid]) return; if(!window.portals[guid]) return;
var p = window.portals[guid]; var p = window.portals[guid];
for(var i = 0; i < portalsLayers.length; i++) for(var i = 0; i < portalsLayers.length; i++)
portalsLayers[i].removeLayer(p); portalsLayers[i].removeLayer(p);
break; break;
case '9': case TYPE_LINK:
if(!window.links[guid]) return; if(!window.links[guid]) return;
linksLayer.removeLayer(window.links[guid]); linksLayer.removeLayer(window.links[guid]);
break; break;
case 'b': case TYPE_FIELD:
if(!window.fields[guid]) return; if(!window.fields[guid]) return;
fieldsLayer.removeLayer(window.fields[guid]); fieldsLayer.removeLayer(window.fields[guid]);
break; break;
@ -282,6 +327,7 @@ window.renderField = function(ent) {
stroke: false, stroke: false,
clickable: false, clickable: false,
smoothFactor: 10, smoothFactor: 10,
vertices: ent[2].capturedRegion,
guid: ent[0]}); guid: ent[0]});
if(!getPaddedBounds().intersects(poly.getBounds())) return; if(!getPaddedBounds().intersects(poly.getBounds())) return;

View File

@ -29,8 +29,10 @@ window.renderPortalDetails = function(guid) {
var time = d.captured ? unixTimeToString(d.captured.capturedTime) : null; var time = d.captured ? unixTimeToString(d.captured.capturedTime) : null;
var sinceText = time ? 'since: ' + time : null; var sinceText = time ? 'since: ' + time : null;
var linkedFields = 'fields: ' + d.portalV2.linkedFields.length;
// collect and html-ify random data // collect and html-ify random data
var randDetails = [playerText, sinceText, getRangeText(d), getEnergyText(d), linksText, getAvgResoDistText(d)]; var randDetails = [playerText, sinceText, linkedFields, getRangeText(d), getEnergyText(d), linksText, getAvgResoDistText(d)];
randDetails = randDetails.map(function(detail) { randDetails = randDetails.map(function(detail) {
if(!detail) return ''; if(!detail) return '';
detail = detail.split(':'); detail = detail.split(':');

View File

@ -134,6 +134,7 @@ var NOMINATIM = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q
var DEG2RAD = Math.PI / 180; var DEG2RAD = Math.PI / 180;
var TEAM_NONE = 0, TEAM_RES = 1, TEAM_ENL = 2; var TEAM_NONE = 0, TEAM_RES = 1, TEAM_ENL = 2;
var TEAM_TO_CSS = ['none', 'res', 'enl']; var TEAM_TO_CSS = ['none', 'res', 'enl'];
var TYPE_UNKNOWN = 0, TYPE_PORTAL = 1, TYPE_LINK = 2, TYPE_FIELD = 3, TYPE_PLAYER = 4, TYPE_CHAT = 5;
// make PLAYER variable available in site context // make PLAYER variable available in site context
var PLAYER = window.PLAYER; var PLAYER = window.PLAYER;
var CHAT_SHRINKED = 60; var CHAT_SHRINKED = 60;