Moar federation
This commit is contained in:
parent
63ef2fa5c4
commit
c84697edc7
2 changed files with 39 additions and 11 deletions
BIN
img.png
Normal file
BIN
img.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 852 KiB |
|
|
@ -150,11 +150,16 @@ public class ActivityImageService {
|
||||||
int trackWidth = (int) (width * 0.6);
|
int trackWidth = (int) (width * 0.6);
|
||||||
int trackHeight = height;
|
int trackHeight = height;
|
||||||
|
|
||||||
// The OSM tile renderer already scales the image to fit trackWidth x trackHeight
|
// Convert bounds to Web Mercator normalized coordinates (0-1)
|
||||||
// So we can use simple linear mapping from geographic bounds to pixel coordinates
|
// This matches the projection used by OSM tiles
|
||||||
double scaleX = trackWidth / (bounds.maxLon - bounds.minLon);
|
double minX = longitudeToWebMercatorX(bounds.minLon);
|
||||||
double scaleY = trackHeight / (bounds.maxLat - bounds.minLat);
|
double maxX = longitudeToWebMercatorX(bounds.maxLon);
|
||||||
double scale = Math.min(scaleX, scaleY);
|
double minY = latitudeToWebMercatorY(bounds.maxLat); // Note: maxLat -> minY (inverted)
|
||||||
|
double maxY = latitudeToWebMercatorY(bounds.minLat); // Note: minLat -> maxY (inverted)
|
||||||
|
|
||||||
|
// Calculate scale to map Web Mercator coordinates to pixels
|
||||||
|
double scaleX = trackWidth / (maxX - minX);
|
||||||
|
double scaleY = trackHeight / (maxY - minY);
|
||||||
|
|
||||||
// Draw track segments with privacy fade
|
// Draw track segments with privacy fade
|
||||||
g2d.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
g2d.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
|
||||||
|
|
@ -172,12 +177,17 @@ public class ActivityImageService {
|
||||||
Double lon2 = getDouble(point2, "longitude");
|
Double lon2 = getDouble(point2, "longitude");
|
||||||
|
|
||||||
if (lat1 != null && lon1 != null && lat2 != null && lon2 != null) {
|
if (lat1 != null && lon1 != null && lat2 != null && lon2 != null) {
|
||||||
// Convert geographic coordinates to pixel coordinates
|
// Convert lat/lon to Web Mercator coordinates (same projection as OSM tiles)
|
||||||
// The OSM renderer already handles the projection, so we use linear mapping
|
double mercatorX1 = longitudeToWebMercatorX(lon1);
|
||||||
double x1 = (lon1 - bounds.minLon) * scale;
|
double mercatorY1 = latitudeToWebMercatorY(lat1);
|
||||||
double y1 = trackHeight - (lat1 - bounds.minLat) * scale;
|
double mercatorX2 = longitudeToWebMercatorX(lon2);
|
||||||
double x2 = (lon2 - bounds.minLon) * scale;
|
double mercatorY2 = latitudeToWebMercatorY(lat2);
|
||||||
double y2 = trackHeight - (lat2 - bounds.minLat) * scale;
|
|
||||||
|
// Map Web Mercator coordinates to pixel coordinates
|
||||||
|
double x1 = (mercatorX1 - minX) * scaleX;
|
||||||
|
double y1 = (mercatorY1 - minY) * scaleY;
|
||||||
|
double x2 = (mercatorX2 - minX) * scaleX;
|
||||||
|
double y2 = (mercatorY2 - minY) * scaleY;
|
||||||
|
|
||||||
// Calculate opacity based on distance from start/end
|
// Calculate opacity based on distance from start/end
|
||||||
double distanceFromStart = cumulativeDistances[i];
|
double distanceFromStart = cumulativeDistances[i];
|
||||||
|
|
@ -434,6 +444,24 @@ public class ActivityImageService {
|
||||||
return new TrackBounds(minLat, maxLat, minLon, maxLon);
|
return new TrackBounds(minLat, maxLat, minLon, maxLon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert longitude to Web Mercator X coordinate (normalized 0-1).
|
||||||
|
* This must match the projection used by OsmTileRenderer.
|
||||||
|
*/
|
||||||
|
private double longitudeToWebMercatorX(double lon) {
|
||||||
|
return (lon + 180.0) / 360.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert latitude to Web Mercator Y coordinate (normalized 0-1).
|
||||||
|
* This must match the projection used by OsmTileRenderer.
|
||||||
|
* Uses the same logarithmic transformation as OSM tiles.
|
||||||
|
*/
|
||||||
|
private double latitudeToWebMercatorY(double lat) {
|
||||||
|
return (1.0 - Math.log(Math.tan(Math.toRadians(lat)) +
|
||||||
|
1.0 / Math.cos(Math.toRadians(lat))) / Math.PI) / 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to store track geographic bounds.
|
* Helper class to store track geographic bounds.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue