Use LineUtil.simplify, rearange some code
This commit is contained in:
parent
898f0c37ce
commit
01f7b7099d
@ -540,6 +540,11 @@ 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]);
|
||||||
|
|
||||||
|
var old = findEntityInLeaflet(fieldsLayer, window.fields, ent[0]);
|
||||||
|
// If this already exists and the zoom level has not changed, we don't need to do anything
|
||||||
|
if(old && map.getZoom() === old.options.creationZoom) return;
|
||||||
|
|
||||||
|
var team = getTeam(ent[2]);
|
||||||
var reg = ent[2].capturedRegion;
|
var reg = ent[2].capturedRegion;
|
||||||
var latlngs = [
|
var latlngs = [
|
||||||
L.latLng(reg.vertexA.location.latE6/1E6, reg.vertexA.location.lngE6/1E6),
|
L.latLng(reg.vertexA.location.latE6/1E6, reg.vertexA.location.lngE6/1E6),
|
||||||
@ -547,26 +552,6 @@ window.renderField = function(ent) {
|
|||||||
L.latLng(reg.vertexC.location.latE6/1E6, reg.vertexC.location.lngE6/1E6)
|
L.latLng(reg.vertexC.location.latE6/1E6, reg.vertexC.location.lngE6/1E6)
|
||||||
];
|
];
|
||||||
|
|
||||||
// Curve fit equation to normalize zoom window area
|
|
||||||
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],
|
||||||
fillOpacity: 0.25,
|
fillOpacity: 0.25,
|
||||||
@ -587,22 +572,41 @@ window.renderField = function(ent) {
|
|||||||
|
|
||||||
if(!getPaddedBounds().intersects(poly.getBounds())) return;
|
if(!getPaddedBounds().intersects(poly.getBounds())) return;
|
||||||
|
|
||||||
var centroid = [
|
// Curve fit equation to normalize zoom window area
|
||||||
(latlngs[0].lat + latlngs[1].lat + latlngs[2].lat)/3,
|
var areaZoomRatio = calcTriArea(latlngs)/Math.exp(14.2714860198866-1.384987247*map.getZoom());
|
||||||
(latlngs[0].lng + latlngs[1].lng + latlngs[2].lng)/3
|
var countForMUDisplay = L.LineUtil.simplify(poly._originalPoints, FIELD_MU_DISPLAY_POINT_TOLERANCE).length
|
||||||
];
|
|
||||||
|
|
||||||
var fieldMu = L.marker(centroid, {
|
// Do nothing if zoom did not change. We need to recheck the field if the
|
||||||
icon: L.divIcon({
|
// zoom level is different then when the field was rendered as it could
|
||||||
className: 'fieldmu',
|
// now be appropriate or not to show an MU count
|
||||||
iconSize: [70,12],
|
if(old) {
|
||||||
html: digits(ent[2].entityScore.entityScore)
|
var layerCount = 0;
|
||||||
}),
|
old.eachLayer(function(item) {
|
||||||
clickable: false
|
layerCount++;
|
||||||
});
|
});
|
||||||
|
// Don't do anything since we already have an MU display and we still want to
|
||||||
|
if(areaZoomRatio > FIELD_MU_DISPLAY_AREA_ZOOM_RATIO && countForMUDisplay > 2 && layerCount === 2) return;
|
||||||
|
// Don't do anything since we don't have an MU display and don't want to
|
||||||
|
if(areaZoomRatio <= FIELD_MU_DISPLAY_AREA_ZOOM_RATIO && countForMUDisplay <= 2 && layerCount === 1) return;
|
||||||
|
removeByGuid(ent[0]);
|
||||||
|
}
|
||||||
|
|
||||||
// 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) {
|
if (areaZoomRatio > FIELD_MU_DISPLAY_AREA_ZOOM_RATIO && countForMUDisplay > 2) {
|
||||||
|
// centroid of field for placing MU count at
|
||||||
|
var centroid = [
|
||||||
|
(latlngs[0].lat + latlngs[1].lat + latlngs[2].lat)/3,
|
||||||
|
(latlngs[0].lng + latlngs[1].lng + latlngs[2].lng)/3
|
||||||
|
];
|
||||||
|
|
||||||
|
var fieldMu = L.marker(centroid, {
|
||||||
|
icon: L.divIcon({
|
||||||
|
className: 'fieldmu',
|
||||||
|
iconSize: [70,12],
|
||||||
|
html: digits(ent[2].entityScore.entityScore)
|
||||||
|
}),
|
||||||
|
clickable: false
|
||||||
|
});
|
||||||
var f = L.layerGroup([poly, fieldMu]);
|
var f = L.layerGroup([poly, fieldMu]);
|
||||||
} else {
|
} else {
|
||||||
var f = L.layerGroup([poly]);
|
var f = L.layerGroup([poly]);
|
||||||
|
2
main.js
2
main.js
@ -151,6 +151,8 @@ window.MAX_DRAWN_FIELDS = 200;
|
|||||||
window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17;
|
window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17;
|
||||||
// Minimum area to zoom ratio that field MU's will display
|
// Minimum area to zoom ratio that field MU's will display
|
||||||
window.FIELD_MU_DISPLAY_AREA_ZOOM_RATIO = 0.001;
|
window.FIELD_MU_DISPLAY_AREA_ZOOM_RATIO = 0.001;
|
||||||
|
// Point tolerance for displaying MU's
|
||||||
|
window.FIELD_MU_DISPLAY_POINT_TOLERANCE = 60
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user