Compare commits

..

No commits in common. "e5d0cc30d640e3704ba1898b6c730d8d00ef6285" and "b8b869f981aa97bf03059c27147877e564bc092f" have entirely different histories.

3 changed files with 11 additions and 29 deletions

1
.gitignore vendored
View File

@ -1,6 +1,5 @@
.env
map-dots
*.png
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore

View File

@ -8,7 +8,6 @@ import (
"git.fjla.uk/fred.boniface/map-dots/data"
"git.fjla.uk/fred.boniface/map-dots/log"
"github.com/fogleman/gg"
"go.uber.org/zap"
)
func mapCirclesToCanvas(img *image.RGBA, locations []data.LocationData) {
@ -16,14 +15,13 @@ func mapCirclesToCanvas(img *image.RGBA, locations []data.LocationData) {
dc := gg.NewContextForRGBA(img)
dc.SetRGB(1, 1, 1) // Set canvas background color (white in this case)
//circleRadius := 4 // Replace with your desired fixed radius
circleRadius := 4 // Replace with your desired fixed radius
bounds := img.Bounds()
canvasWidth := bounds.Max.X - bounds.Min.X
canvasHeight := bounds.Max.Y - bounds.Min.Y
margin := 0.1
var minLat, maxLat, minLon, maxLon = math.MaxFloat64, -math.MaxFloat64, math.MaxFloat64, -math.MaxFloat64
var minLat, maxLat, minLon, maxLon float64
for _, loc := range locations {
if loc.Latitude < minLat {
minLat = loc.Latitude
@ -39,29 +37,22 @@ func mapCirclesToCanvas(img *image.RGBA, locations []data.LocationData) {
}
}
centerLat := (maxLat + minLat) / 2.0
centerLon := (maxLon + minLon) / 2.0
latRange := maxLat - minLat
lonRange := maxLon - minLon
minLat -= latRange * margin
maxLat += latRange * margin
minLon -= lonRange * margin
maxLon += lonRange * margin
minLatEqui := equirectangularProjection(minLat)
maxLatEqui := equirectangularProjection(maxLat)
latScale := float64(canvasHeight) / (maxLatEqui - minLatEqui)
longScale := float64(canvasWidth) / (maxLon - minLon)
for _, loc := range locations {
x := int((loc.Longitude - minLon) * longScale)
// Invert the Y-axis calculation
y := canvasHeight - int((equirectangularProjection(loc.Latitude)-minLatEqui)*latScale)
// Draw a dot (circle) at (x, y)
dc.DrawCircle(float64(x), float64(y), 2)
dc.SetRGBA(1, 1, 1, 0.3333333333) // Set dot color (black)
pixelX, pixelY := convertCoordinatesToPixels(loc.Latitude, loc.Longitude, centerLat, centerLon, latRange, lonRange, canvasWidth, canvasHeight)
// Draw the circle on the canvas using gg
dc.DrawCircle(float64(pixelX), float64(pixelY), float64(circleRadius))
dc.SetRGBA(1, 1, 1, 0.5) // Circle fill color (white with 50% opacity)
dc.Fill()
}
dc.Clip() // Apply clipping
// Optional: Save the canvas as an image file
err := dc.SavePNG("output.png")
if err != nil {
@ -69,9 +60,6 @@ func mapCirclesToCanvas(img *image.RGBA, locations []data.LocationData) {
} else {
fmt.Println("Canvas saves to file")
}
fmt.Println(minLat)
fmt.Println(minLon)
}
func convertCoordinatesToPixels(latitude, longitude float64, centerLat, centerLon, latRange, lonRange float64, canvasWidth, canvasHeight int) (int, int) {
@ -92,8 +80,3 @@ func convertCoordinatesToPixels(latitude, longitude float64, centerLat, centerLo
return pixelX, pixelY
}
func equirectangularProjection(lat float64) float64 {
log.Msg.Debug("Running equirectangular calculation", zap.Float64("lat", lat))
return lat * (math.Pi / 180) // Convert degrees to radians
}

BIN
output.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB