109 lines
3.7 KiB
Go
109 lines
3.7 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.fjla.uk/fred.boniface/map-dot/log"
|
|
"git.fjla.uk/fred.boniface/map-dot/run"
|
|
)
|
|
|
|
var (
|
|
showHelp bool
|
|
)
|
|
|
|
func main() {
|
|
flag.BoolVar(&showHelp, "help", false, "Show extended help")
|
|
flag.Usage = customUsage
|
|
serverMode := flag.Bool("server", false, "Run as an API server - Omit all other flags if running as server")
|
|
height := flag.Uint64("height", 600, "Output image height")
|
|
width := flag.Uint64("width", 800, "Output image width")
|
|
style := flag.String("style", "circles", "Output image style")
|
|
format := flag.String("format", "png", "Output image format")
|
|
input := flag.String("in", "traccar", "Input source - can be 'filepath' or 'traccar'")
|
|
flag.Parse()
|
|
|
|
if showHelp {
|
|
flag.Usage()
|
|
return
|
|
}
|
|
|
|
if *serverMode {
|
|
run.Server()
|
|
} else {
|
|
run.CLI(*height, *width, *style, *format, *input)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
log.Msg.Info("Starting map-dot")
|
|
fmt.Println("\n" + ascii)
|
|
fmt.Println("Creating art from location data")
|
|
}
|
|
|
|
const ascii string = `███╗ ███╗ █████╗ ██████╗ ██████╗ ██████╗ ████████╗
|
|
████╗ ████║██╔══██╗██╔══██╗██╔══██╗██╔═══██╗╚══██╔══╝
|
|
██╔████╔██║███████║██████╔╝██║ ██║██║ ██║ ██║
|
|
██║╚██╔╝██║██╔══██║██╔═══╝ ██║ ██║██║ ██║ ██║
|
|
██║ ╚═╝ ██║██║ ██║██║ ██████╔╝╚██████╔╝ ██║
|
|
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═════╝ ╚═╝ `
|
|
|
|
func customUsage() {
|
|
extendedHelp := `
|
|
map-dot - Transform location data into artistic heat-map style images
|
|
|
|
Usage:
|
|
map-dot [--server] [--height=HEIGHT] [--width=WIDTH] [--style=STYLE] [--format=FORMAT] [--input=INPUT] [--id=ID]
|
|
|
|
Options:
|
|
--server Run in server mode
|
|
--height=HEIGHT Output image height
|
|
--width=WIDTH Output image width
|
|
--style=STYLE Output image style
|
|
--format=FORMAT Output image format
|
|
--input=INPUT Input source
|
|
--id=ID Traccar device ID
|
|
|
|
More detailed help information:
|
|
-- server (Omit to run in CLI Mode):
|
|
Runs a web API on localhost:8198
|
|
Note that there is no authentication built in and the service could expose
|
|
personal location data if access is allowed from the internet.
|
|
|
|
-- height (Only in CLI Mode): DEFAULT: 1080
|
|
The height of the output image in pixels (Max: 7680)
|
|
|
|
-- width (Only in CLI Mode): DEFAULT: 1920
|
|
The width of the output image in pixels (Max: 4320)
|
|
|
|
-- style (Only in CLI Mode): DEFAULT: circles
|
|
The style of the output image - currently only 'circles' is available
|
|
|
|
-- format (Only in CLI Mode): DEFAULT: png
|
|
The image format of the output image. Options are:
|
|
png, jpeg, gif, bmp, tiff, webp
|
|
|
|
-- input (Only in CLI Mode): DEFAULT: traccar
|
|
The input source for data. Options are:
|
|
traccar, a valid file path in a supported format (See below for formats)
|
|
|
|
-- id (Only in CLI Mode): REQUIRED for CLI in 'traccar' mode
|
|
The Traccar device ID to fetch data for
|
|
|
|
If you want to fetch data from Traccar, you must ensure the following environment variables are set
|
|
This applies to Server and CLI modes:
|
|
TRACCAR_USER : Traccar Username
|
|
TRACCAR_PASS : Traccar Password
|
|
TRACCAR_URL : Traccar URL (Including port if not 80/443)
|
|
|
|
Input Formats:
|
|
Supported input file formats are:
|
|
xml+gpx, xml+kml, traccar-Api-JSON
|
|
|
|
For Web API usage information start the server and go to localhost:8198/help
|
|
`
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", extendedHelp)
|
|
}
|