use of de.fhpotsdam.unfolding.utils.MapPosition in project constellation by constellation-app.
the class DayNightLayer method update.
@Override
public PImage update() {
final int width = renderer.width - 5;
final int height = renderer.height - 5;
final PGraphics dayNightImage = renderer.createGraphics(width, height, PConstants.JAVA2D);
dayNightImage.beginDraw();
final long currentTime = System.currentTimeMillis();
final Location sunLocation = getSunPosition(currentTime);
final ScreenPosition sunPosition = map.getScreenPosition(sunLocation);
final Location leftShadowLocation = getShadowPosition(sunLocation, ShadowOrientation.LEFT);
final Location rightShadowLocation = getShadowPosition(sunLocation, ShadowOrientation.RIGHT);
// draw the sun
dayNightImage.stroke(STROKE_COLOR);
dayNightImage.fill(SUN_COLOR);
dayNightImage.ellipse(sunPosition.x, sunPosition.y, 10, 10);
// calculate shadow radius
final float twighlightCivilRadiusMeters = getShadowRadiusFromAngle(0.566666);
final float twighlightNauticalRadiusMeters = getShadowRadiusFromAngle(6.0);
final float twighlightAstronomicalRadiusMeters = getShadowRadiusFromAngle(12.0);
final float nightRadiusMeters = getShadowRadiusFromAngle(18.0);
// left twilight civil
final Location leftTwighlightCivilRadiusLocation = new Location(leftShadowLocation.getLat() - Distance.Haversine.kilometersToDecimalDegrees(twighlightCivilRadiusMeters / 1000), leftShadowLocation.getLon() - Distance.Haversine.kilometersToDecimalDegrees(twighlightCivilRadiusMeters / 1000));
final List<Location> leftTwighlightCivilLocations = MarkerUtilities.generateCircle(leftShadowLocation, leftTwighlightCivilRadiusLocation);
final List<MapPosition> leftTwighlightCivilPositions = leftTwighlightCivilLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_CIVIL_COLOR);
dayNightImage.beginShape();
leftTwighlightCivilPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// left twilight nautical
final Location leftTwighlightNauticalRadiusLocation = new Location(leftShadowLocation.getLat() - Distance.Haversine.kilometersToDecimalDegrees(twighlightNauticalRadiusMeters / 1000), leftShadowLocation.getLon() - Distance.Haversine.kilometersToDecimalDegrees(twighlightNauticalRadiusMeters / 1000));
final List<Location> leftTwighlightNauticalLocations = MarkerUtilities.generateCircle(leftShadowLocation, leftTwighlightNauticalRadiusLocation);
final List<MapPosition> leftTwighlightNauticalPositions = leftTwighlightNauticalLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_NAUTICAL_COLOR);
dayNightImage.beginShape();
leftTwighlightNauticalPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// left twilight astronomical
final Location leftTwighlightAstronomicalRadiusLocation = new Location(leftShadowLocation.getLat() + Distance.Haversine.kilometersToDecimalDegrees(twighlightAstronomicalRadiusMeters / 1000), leftShadowLocation.getLon() + Distance.Haversine.kilometersToDecimalDegrees(twighlightAstronomicalRadiusMeters / 1000));
final List<Location> leftTwighlightAstronomicalLocations = MarkerUtilities.generateCircle(leftShadowLocation, leftTwighlightAstronomicalRadiusLocation);
final List<MapPosition> leftTwighlightAstronomicalPositions = leftTwighlightAstronomicalLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_ASTRONOMICAL_COLOR);
dayNightImage.beginShape();
leftTwighlightAstronomicalPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// left night
final Location leftNightRadiusLocation = new Location(leftShadowLocation.getLat() + Distance.Haversine.kilometersToDecimalDegrees(nightRadiusMeters / 1000), leftShadowLocation.getLon() + Distance.Haversine.kilometersToDecimalDegrees(nightRadiusMeters / 1000));
final List<Location> leftNightLocations = MarkerUtilities.generateCircle(leftShadowLocation, leftNightRadiusLocation);
final List<MapPosition> leftNightPositions = leftNightLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(NIGHT_COLOR);
dayNightImage.beginShape();
leftNightPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// right twilight civil
final Location rightTwighlightCivilRadiusLocation = new Location(rightShadowLocation.getLat() - Distance.Haversine.kilometersToDecimalDegrees(twighlightCivilRadiusMeters / 1000), rightShadowLocation.getLon() - Distance.Haversine.kilometersToDecimalDegrees(twighlightCivilRadiusMeters / 1000));
final List<Location> rightTwighlightCivilLocations = MarkerUtilities.generateCircle(rightShadowLocation, rightTwighlightCivilRadiusLocation);
final List<MapPosition> rightTwighlightCivilPositions = rightTwighlightCivilLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_CIVIL_COLOR);
dayNightImage.beginShape();
rightTwighlightCivilPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// right twilight nautical
final Location rightTwighlightNauticalRadiusLocation = new Location(rightShadowLocation.getLat() - Distance.Haversine.kilometersToDecimalDegrees(twighlightNauticalRadiusMeters / 1000), rightShadowLocation.getLon() - Distance.Haversine.kilometersToDecimalDegrees(twighlightNauticalRadiusMeters / 1000));
final List<Location> rightTwighlightNauticalLocations = MarkerUtilities.generateCircle(rightShadowLocation, rightTwighlightNauticalRadiusLocation);
final List<MapPosition> rightTwighlightNauticalPositions = rightTwighlightNauticalLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_NAUTICAL_COLOR);
dayNightImage.beginShape();
rightTwighlightNauticalPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// right twilight astronomical
final Location rightTwighlightAstronomicalRadiusLocation = new Location(rightShadowLocation.getLat() + Distance.Haversine.kilometersToDecimalDegrees(twighlightAstronomicalRadiusMeters / 1000), rightShadowLocation.getLon() + Distance.Haversine.kilometersToDecimalDegrees(twighlightAstronomicalRadiusMeters / 1000));
final List<Location> rightTwighlightAstronomicalLocations = MarkerUtilities.generateCircle(rightShadowLocation, rightTwighlightAstronomicalRadiusLocation);
final List<MapPosition> rightTwighlightAstronomicalPositions = rightTwighlightAstronomicalLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(TWIGHLIGHT_ASTRONOMICAL_COLOR);
dayNightImage.beginShape();
rightTwighlightAstronomicalPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
// right night
final Location rightNightRadiusLocation = new Location(rightShadowLocation.getLat() + Distance.Haversine.kilometersToDecimalDegrees(nightRadiusMeters / 1000), rightShadowLocation.getLon() + Distance.Haversine.kilometersToDecimalDegrees(nightRadiusMeters / 1000));
final List<Location> rightNightLocations = MarkerUtilities.generateCircle(rightShadowLocation, rightNightRadiusLocation);
final List<MapPosition> rightNightPositions = rightNightLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
dayNightImage.noStroke();
dayNightImage.fill(NIGHT_COLOR);
dayNightImage.beginShape();
rightNightPositions.forEach(position -> dayNightImage.vertex(position.x, position.y));
dayNightImage.endShape(PConstants.CLOSE);
dayNightImage.endDraw();
return dayNightImage;
}
use of de.fhpotsdam.unfolding.utils.MapPosition in project constellation by constellation-app.
the class PointMarkerErrorLayer method update.
@Override
public PImage update() {
if (map.getMarkers().isEmpty()) {
return null;
}
markerCount = map.getMarkers().size();
final int width = renderer.width - 5;
final int height = renderer.height - 5;
// get on screen markers
final ScreenPosition topLeft = map.getScreenPosition(map.getTopLeftBorder());
final ScreenPosition bottomRight = map.getScreenPosition(map.getBottomRightBorder());
final List<ConstellationAbstractMarker> markers = renderer.getMarkerCache().getAllMarkers().stream().filter(marker -> {
final ScreenPosition markerPosition = map.getScreenPosition(marker.getLocation());
return markerPosition != null && markerPosition.x > topLeft.x && markerPosition.y > topLeft.y && markerPosition.x < bottomRight.x && markerPosition.y < bottomRight.y;
}).collect(Collectors.toList());
// create error region data from markers
final PGraphics errorRegionImage = renderer.createGraphics(width, height, PConstants.JAVA2D);
errorRegionImage.beginDraw();
errorRegionImage.stroke(STROKE_COLOR);
errorRegionImage.fill(ERROR_REGION_COLOR);
if (graph != null) {
final ReadableGraph readableGraph = graph.getReadableGraph();
try {
final int vertexPrecisionAttributeId = SpatialConcept.VertexAttribute.PRECISION.get(readableGraph);
final int transactionPrecisionAttributeId = SpatialConcept.TransactionAttribute.PRECISION.get(readableGraph);
for (final ConstellationAbstractMarker marker : markers) {
if (!(marker instanceof ConstellationPointMarker)) {
continue;
}
float minimumPrecision = DEFAULT_PRECISION;
final Set<GraphElement> elements = renderer.getMarkerCache().get(marker);
for (final GraphElement element : elements) {
final float elementPrecision;
switch(element.getType()) {
case VERTEX:
if (vertexPrecisionAttributeId != Graph.NOT_FOUND) {
elementPrecision = readableGraph.getFloatValue(vertexPrecisionAttributeId, element.getId());
minimumPrecision = Math.max(elementPrecision, minimumPrecision);
} else {
elementPrecision = DEFAULT_PRECISION;
minimumPrecision = DEFAULT_PRECISION;
}
break;
case TRANSACTION:
elementPrecision = transactionPrecisionAttributeId != Graph.NOT_FOUND ? readableGraph.getFloatValue(transactionPrecisionAttributeId, element.getId()) : DEFAULT_PRECISION;
break;
default:
elementPrecision = DEFAULT_PRECISION;
break;
}
minimumPrecision = Math.max(elementPrecision, minimumPrecision);
}
// don't bother drawing if there isn't a precision
if (minimumPrecision == 0) {
continue;
}
final Location errorRegionRadiusLocation = new Location(marker.getLocation().getLat() - Haversine.kilometersToDecimalDegrees(minimumPrecision), marker.getLocation().getLon() - Haversine.kilometersToDecimalDegrees(minimumPrecision));
final List<Location> errorRegionLocations = MarkerUtilities.generateCircle(marker.getLocation(), errorRegionRadiusLocation);
final List<MapPosition> errorRegionPositions = errorRegionLocations.stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
errorRegionImage.beginShape();
errorRegionPositions.forEach(position -> errorRegionImage.vertex(position.x, position.y));
errorRegionImage.endShape(PConstants.CLOSE);
}
} finally {
readableGraph.release();
}
}
errorRegionImage.endDraw();
return errorRegionImage;
}
use of de.fhpotsdam.unfolding.utils.MapPosition in project constellation by constellation-app.
the class ConstellationClusterMarker method draw.
@Override
public void draw(final UnfoldingMap map) {
clusterSize = getCentroidLocations().size();
final PGraphics graphics = map.mapDisplay.getOuterPG();
final List<MapPosition> positions = getLocations().stream().map(location -> new MapPosition(map.mapDisplay.getObjectFromLocation(location))).collect(Collectors.toList());
draw(graphics, positions, map);
}
use of de.fhpotsdam.unfolding.utils.MapPosition in project constellation by constellation-app.
the class ConstellationClusterMarker method draw.
@Override
protected boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) {
if (positions.isEmpty() || isHidden()) {
return false;
}
clusterCenter = new MapPosition();
positions.forEach(position -> {
clusterCenter.add(position);
});
clusterCenter.div(positions.size());
double diameter = 0;
if (positions.size() > 1) {
final MapPosition minPosition = new MapPosition(new float[] { Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE });
final MapPosition maxPosition = new MapPosition(new float[] { Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE });
positions.forEach(position -> {
minPosition.x = Math.min(position.x, minPosition.x);
minPosition.y = Math.min(position.y, minPosition.y);
maxPosition.x = Math.max(position.x, maxPosition.x);
maxPosition.y = Math.max(position.y, maxPosition.y);
});
diameter = Math.sqrt(Math.pow((maxPosition.x - minPosition.x), 2) + Math.pow((maxPosition.y - minPosition.y), 2));
}
clusterRadius = Math.max((float) diameter / 2, MIN_RADIUS);
graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
graphics.stroke(strokeColor);
graphics.fill(getFillColor());
graphics.ellipseMode(PConstants.RADIUS);
graphics.ellipse(clusterCenter.x, clusterCenter.y, clusterRadius, clusterRadius);
final String clusterLabel = String.valueOf(clusterSize);
graphics.fill(FONT_COLOR);
graphics.textSize(FONT_SIZE);
graphics.text(clusterLabel, clusterCenter.x - (CHAR_WIDTH * clusterLabel.length() * 0.6F), clusterCenter.y + (FONT_SIZE * 0.35F));
return true;
}
use of de.fhpotsdam.unfolding.utils.MapPosition in project constellation by constellation-app.
the class ConstellationLineMarker method draw.
@Override
public boolean draw(final PGraphics graphics, final List<MapPosition> positions, final UnfoldingMap map) {
if (positions.isEmpty() || isHidden()) {
return false;
}
graphics.pushStyle();
graphics.noFill();
graphics.strokeWeight(size == MarkerUtilities.DEFAULT_SIZE ? strokeWeight : size);
graphics.stroke(getFillColor());
graphics.smooth();
graphics.beginShape(PConstants.LINES);
for (int i = 0; i < positions.size() - 1; ++i) {
final MapPosition lastPosition = positions.get(i);
final MapPosition currentPosition = positions.get(i + 1);
graphics.vertex(lastPosition.x, lastPosition.y);
graphics.vertex(currentPosition.x, currentPosition.y);
}
graphics.endShape();
graphics.popStyle();
return true;
}
Aggregations