summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2016-11-22 00:07:08 +0000
committerFelix Hanley <felix@userspace.com.au>2016-11-22 00:07:08 +0000
commitd316cbfea1597146882274ce63f79777c02d0197 (patch)
treefb61b0858a11b2dc3ec7a5e24d675abb93d82f1d
parent411565dc3c87851017376545383d4afa65d9f833 (diff)
downloadcrjw-maps-d316cbfea1597146882274ce63f79777c02d0197.tar.gz
crjw-maps-d316cbfea1597146882274ce63f79777c02d0197.tar.bz2
Add force flag
-rw-r--r--location.go27
-rw-r--r--main.go38
2 files changed, 41 insertions, 24 deletions
diff --git a/location.go b/location.go
index a9cc351..23df871 100644
--- a/location.go
+++ b/location.go
@@ -22,23 +22,25 @@ type Location struct {
}
func (l *Location) getQRCode() string {
- log.Printf("Getting QR code for %s", l.Number)
path := filepath.Join(c.cache, fmt.Sprintf("%s-qrc.png", l.Number))
old := true
fi, err := os.Stat(path)
if err == nil && fi.ModTime().After(c.cDate) {
old = false
if c.debug {
- log.Printf("Using existing map file %s", path)
+ log.Printf("Using existing QR code %s", path)
}
}
- if old {
- url := fmt.Sprintf("geo://%s,%s", l.Latitude, l.Longitude)
- qrcode, err := qrcode.New(url, qrcode.Medium)
+ if old || c.force {
+ if c.debug {
+ log.Printf("Creating new QR code %s", path)
+ }
+ url := fmt.Sprintf("geo:%f,%f", l.Latitude, l.Longitude)
+ qrcode, err := qrcode.New(url, qrcode.High)
if err != nil {
log.Fatal("Failed to create QR code: %s", err)
}
- err = qrcode.WriteFile(100, path)
+ err = qrcode.WriteFile(110, path)
if err != nil {
log.Fatal("Failed to write QR code: %s", err)
}
@@ -47,7 +49,6 @@ func (l *Location) getQRCode() string {
}
func (l *Location) getMap() string {
- log.Printf("Getting map for %s", l.Number)
// Flag
old := true
path := filepath.Join(c.cache, fmt.Sprintf("%s-map.png", l.Number))
@@ -64,17 +65,17 @@ func (l *Location) getMap() string {
log.Printf("Creating new map file %s", path)
}
ctx := sm.NewContext()
- ctx.SetSize(640, 513)
- // ctx.SetSize(1280, 1026)
+ // ctx.SetSize(640, 513)
+ ctx.SetSize(960, 770)
pos := s2.LatLngFromDegrees(l.Latitude, l.Longitude)
kh := s2.LatLngFromDegrees(19.89830, 99.81805)
- ctx.AddMarker(sm.NewMarker(pos, color.RGBA{0xff, 0, 0, 0xff}, 16.0))
- ctx.AddMarker(sm.NewMarker(kh, color.RGBA{0, 0, 0xff, 0xff}, 16.0))
+ ctx.AddMarker(sm.NewMarker(pos, color.RGBA{0xff, 0, 0, 0xff}, 32.0))
+ ctx.AddMarker(sm.NewMarker(kh, color.RGBA{0, 0, 0xff, 0xff}, 32.0))
// ctx.SetCenter(s2.LatLngFromDegrees(19.89830, 99.81805))
// ctx.SetCenter(pos)
// ctx.SetTileProvider(sm.NewTileProviderOpenTopoMap())
- ctx.SetTileProvider(sm.NewTileProviderThunderforestOutdoors())
- // ctx.SetTileProvider(sm.NewTileProviderThunderforestLandscape())
+ // ctx.SetTileProvider(sm.NewTileProviderThunderforestOutdoors())
+ ctx.SetTileProvider(sm.NewTileProviderThunderforestLandscape())
if c.debug {
log.Printf("Rendering map for %s", l.Number)
diff --git a/main.go b/main.go
index 9aa8517..c6d61a7 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"flag"
+ "fmt"
"github.com/gocarina/gocsv"
"github.com/jung-kurt/gofpdf"
"log"
@@ -20,6 +21,7 @@ var c struct {
cache string
cDate time.Time
debug bool
+ force bool
}
func main() {
@@ -27,6 +29,7 @@ func main() {
flag.StringVar(&c.out, "out", "", "Output PDF file")
flag.StringVar(&c.cache, "cache", "cache", "Cache path")
flag.BoolVar(&c.debug, "debug", false, "Debug output")
+ flag.BoolVar(&c.force, "force", false, "No cache usage")
// flag.StringVar(&c.outPrefix, "outPrefix", "", "Output file prefix")
flag.Parse()
@@ -79,7 +82,9 @@ func main() {
// Generate the PDF
for i := range locations {
loc := locations[i]
- log.Printf("Processing map number %s %s", loc.Number, loc.Name)
+ if !c.debug {
+ log.Printf("Processing map number %s %s", loc.Number, loc.Name)
+ }
pdf.AddPage()
imageOpts := gofpdf.ImageOptions{"PNG", true}
@@ -92,18 +97,29 @@ func main() {
smPath := loc.getMap()
// mapInfo := pdf.RegisterImageOptions(smPath, imageOpts)
+ pdf.TransformBegin()
+ pdf.TransformRotate(90, 5, pHeight-5)
+ pdf.SetFontSize(40)
+ pdf.SetTextColor(0, 0, 0)
+
+ // Number
+ pdf.Text(5, pHeight+5, loc.Number)
+ numW := pdf.GetStringWidth(loc.Number)
+
// Name
- if loc.Name != "" {
- pdf.TransformBegin()
- pdf.TransformRotate(90, 5, pHeight-5)
- pdf.SetFontSize(40)
- pdf.Text(5, pHeight+5, loc.Number)
- pdf.SetFontSize(20)
- pdf.Text(5, pHeight+5+7, tr(loc.Name))
- pdf.ImageOptions(qrPath, pHeight-27, pHeight-10, 0, 0, false, imageOpts, 0, "")
- pdf.TransformEnd()
- }
+ pdf.SetFontSize(20)
+ pdf.Text(5+numW+4, pHeight+5, tr(loc.Name))
+
+ // Coords
+ pdf.SetFontSize(15)
+ pdf.SetTextColor(150, 150, 150)
+ coords := fmt.Sprintf("%f N, %f E", loc.Latitude, loc.Longitude)
+ pdf.Text(5, pHeight+5+7, coords)
+
+ pdf.ImageOptions(qrPath, pHeight-27, pHeight-11, 0, 0, false, imageOpts, 0, "")
+ pdf.TransformEnd()
+ // Add this last to clip QR code
pdf.ImageOptions(smPath, 25, 5, 0, pHeight-10, false, imageOpts, 0, "")
if c.debug {
log.Printf("Added map %s", smPath)