MU counts for fields with limiting for small fields

Only at higher zoom levels will counts for small fields show.
This commit is contained in:
Kevin 2013-03-02 21:25:03 -08:00
parent 1e21bbb94d
commit 0ba8631b82
4 changed files with 37 additions and 12 deletions

View File

@ -522,17 +522,30 @@ window.renderField = function(ent) {
if(Object.keys(fields).length >= MAX_DRAWN_FIELDS) if(Object.keys(fields).length >= MAX_DRAWN_FIELDS)
return window.removeByGuid(ent[0]); return window.removeByGuid(ent[0]);
// assume that fields never change. If they do, they will have a
// different ID.
if(findEntityInLeaflet(fieldsLayer, fields, ent[0])) return;
var team = getTeam(ent[2]);
var reg = ent[2].capturedRegion; var reg = ent[2].capturedRegion;
var latlngs = [ var latlngs = [
[reg.vertexA.location.latE6/1E6, reg.vertexA.location.lngE6/1E6], new L.LatLng(reg.vertexA.location.latE6/1E6, reg.vertexA.location.lngE6/1E6),
[reg.vertexB.location.latE6/1E6, reg.vertexB.location.lngE6/1E6], new L.LatLng(reg.vertexB.location.latE6/1E6, reg.vertexB.location.lngE6/1E6),
[reg.vertexC.location.latE6/1E6, reg.vertexC.location.lngE6/1E6] new L.LatLng(reg.vertexC.location.latE6/1E6, reg.vertexC.location.lngE6/1E6)
]; ];
var areaZoomRatio = calcTriArea(latlngs)/Math.exp(14.2714860198866-1.384987247*map.getZoom())
// Do nothing if zoom did not change. We need to recheck the field if the
// zoom level is different then when the field was rendered as it could
// now be appropriate or not to show an MU count
var old = findEntityInLeaflet(fieldsLayer, window.fields, ent[0]);
if(old) {
if(map.getZoom() == old.options.creationZoom) return;
var layerCount = 0;
old.eachLayer(function(item) {
layerCount++;
});
if(areaZoomRatio > FIELD_MU_DISPLAY_AREA_ZOOM_RATIO && layerCount == 2) return;
if(areaZoomRatio <= FIELD_MU_DISPLAY_AREA_ZOOM_RATIO && layerCount == 1) return;
removeByGuid(ent[0]);
}
var team = getTeam(ent[2]);
var poly = L.polygon(latlngs, { var poly = L.polygon(latlngs, {
fillColor: COLORS[team], fillColor: COLORS[team],
@ -562,16 +575,21 @@ window.renderField = function(ent) {
var fieldMu = L.marker(centroid, { var fieldMu = L.marker(centroid, {
icon: L.divIcon({ icon: L.divIcon({
className: 'fieldmu', className: 'fieldmu',
iconSize: [100,12], iconSize: [70,12],
html: 'MU: ' + digits(ent[2].entityScore.entityScore)}), html: digits(ent[2].entityScore.entityScore)}),
clickable: false clickable: false
}); });
// put both in one group, so they can be handled by the same logic. // put both in one group, so they can be handled by the same logic.
if (areaZoomRatio > FIELD_MU_DISPLAY_AREA_ZOOM_RATIO) {
var f = L.layerGroup([poly, fieldMu]); var f = L.layerGroup([poly, fieldMu]);
} else {
var f = L.layerGroup([poly]);
}
f.options = { f.options = {
vertices: reg, vertices: reg,
lastUpdate: ent[1], lastUpdate: ent[1],
creationZoom: map.getZoom(),
guid: ent[0] guid: ent[0]
}; };

View File

@ -296,3 +296,8 @@ window.convertTextToTableMagic = function(text) {
table += '</table>'; table += '</table>';
return table; return table;
} }
// Given 3 sets of points in an array[3]{lat, lng} returns the area of the triangle
window.calcTriArea = function(p) {
return Math.abs((p[0].lat*(p[1].lng-p[2].lng)+p[1].lat*(p[2].lng-p[0].lng)+p[2].lat*(p[0].lng-p[1].lng))/2);
}

View File

@ -149,6 +149,8 @@ window.MAX_DRAWN_LINKS = 400;
window.MAX_DRAWN_FIELDS = 200; window.MAX_DRAWN_FIELDS = 200;
// Minimum zoom level resonator will display // Minimum zoom level resonator will display
window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17; window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17;
// Minimum area to zoom ratio that field MU's will display
window.FIELD_MU_DISPLAY_AREA_ZOOM_RATIO = 0.001;
window.COLOR_SELECTED_PORTAL = '#f00'; window.COLOR_SELECTED_PORTAL = '#f00';
window.COLORS = ['#FFCE00', '#0088FF', '#03DC03']; // none, res, enl window.COLORS = ['#FFCE00', '#0088FF', '#03DC03']; // none, res, enl

View File

@ -94,12 +94,12 @@ a:hover {
} }
/* field mu count */ /* field mu count */
.fieldmu { .fieldmu {
color: #FFCE00; color: #FFCE00;
font-size:13px; font-size:13px;
font-family: "coda",arial,helvetica,sans-serif; /*override leaflet-container */ font-family: "coda",arial,helvetica,sans-serif; /*override leaflet-container */
text-align: center; text-align: center;
text-shadow: 0 0 0.2em black, 0 0 0.2em black, 0 0 0.2em black;
} }