Render transparent tiles if command line flag is set.

This commit is contained in:
Sascha L. Teichmann
2014-10-26 18:36:47 +01:00
parent 2aa9ee0e24
commit 8452a26fcd
8 changed files with 198 additions and 77 deletions

View File

@ -17,14 +17,15 @@ import (
func main() {
var (
webPort int
webHost string
webDir string
mapDir string
redisPort int
redisHost string
colorsFile string
workers int
webPort int
webHost string
webDir string
mapDir string
redisPort int
redisHost string
colorsFile string
workers int
transparent bool
)
flag.IntVar(&webPort, "web-port", 8808, "port of the web server")
flag.IntVar(&webPort, "p", 8808, "port of the web server (shorthand)")
@ -41,6 +42,8 @@ func main() {
flag.IntVar(&workers, "workers", 1, "number of workers to render tiles")
flag.StringVar(&colorsFile, "colors", "colors.txt", "colors used to render map tiles.")
flag.StringVar(&colorsFile, "c", "colors.txt", "colors used to render map tiles (shorthand).")
flag.BoolVar(&transparent, "transparent", false, "Render transparent blocks.")
flag.BoolVar(&transparent, "t", false, "Render transparent blocks (shorthand).")
flag.Parse()
@ -56,7 +59,7 @@ func main() {
log.Fatalf("ERROR: problem loading colors: %s", err)
}
redisAddress := fmt.Sprintf("%s:%d", redisHost, redisPort)
tu := newTileUpdater(mapDir, redisAddress, colors, workers)
tu := newTileUpdater(mapDir, redisAddress, colors, transparent, workers)
go tu.doUpdates()
router.Path("/update").Methods("POST").Handler(tu)
}

View File

@ -26,6 +26,7 @@ type tileUpdater struct {
redisAddress string
colors *common.Colors
workers int
transparent bool
cond *sync.Cond
mu sync.Mutex
}
@ -56,12 +57,18 @@ func (c xz) parent() xzm {
Mask: 1 << (zr<<1 | xr)}
}
func newTileUpdater(mapDir, redisAddress string, colors *common.Colors, workers int) *tileUpdater {
func newTileUpdater(
mapDir, redisAddress string,
colors *common.Colors,
transparent bool,
workers int) *tileUpdater {
tu := tileUpdater{
mapDir: mapDir,
redisAddress: redisAddress,
changes: map[xz]bool{},
colors: colors,
transparent: transparent,
workers: workers}
tu.cond = sync.NewCond(&tu.mu)
return &tu
@ -113,7 +120,7 @@ func (tu *tileUpdater) doUpdates() {
log.Printf("WARN: Cannot connect to redis server: %s", err)
continue
}
btc := common.NewBaseTileCreator(client, tu.colors, baseDir, true)
btc := common.NewBaseTileCreator(client, tu.colors, tu.transparent, baseDir, true)
done.Add(1)
go updateBaseTiles(jobs, btc, &done)
}