protected void determineLabelLocation(DrawContext dc)
{
// Reuse the current label location if its inside the view frustum and the label is completely visible when
// placed there. Otherwise we find a new location that maximizes the label's visible area and is closest to the
// current location.
Vec4 lastPoint = this.getLabelPoint(dc);
if (lastPoint != null && dc.getView().getFrustumInModelCoordinates().contains(lastPoint))
{
// Project the current location's model point into screen coordinates, and place the label at the
// projected point. We do this to measure the label's visible area when placed at that point.
Vec4 screenPoint = dc.getView().project(lastPoint);
this.setLabelLocation(dc, screenPoint);
// If the label is completely visible, just reuse its current location.
if (this.isLabelCompletelyVisible(dc))
return;
}
this.labelLocationIndex = -1;
if (this.getLocations() == null)
return;
double maxArea = 0;
double minDistance = Double.MAX_VALUE;
int locationIndex = -1;
for (LatLon ll : this.getLocations())
{
++locationIndex;
if (ll == null)
continue;
// Compute the specified location's point in model coordinates. Ignore locations who's model coordinate
// point cannot be computed for any reason, or are outside the view frustum.
Vec4 point = this.computePoint(dc, ll);
if (point == null || !dc.getView().getFrustumInModelCoordinates().contains(point))
continue;
// Project the specified location's model point into screen coordinates, and place the label at the
// projected point. We do this to measure the label's visible area when placed at that point.
Vec4 screenPoint = dc.getView().project(point);
this.setLabelLocation(dc, screenPoint);
// Find the location that maximizes the label's visible area.
double area = this.getLabelVisibleArea(dc);
if (maxArea < area)