mtsatellite/cmd/mtwebmapper/main.go
2014-09-17 17:20:07 +02:00

47 lines
1.3 KiB
Go

// Copyright 2014 by Sascha L. Teichmann
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
var (
port int
host string
webDir string
mapDir string
)
flag.IntVar(&port, "port", 8808, "port of the web server")
flag.IntVar(&port, "p", 8808, "port of the web server (shorthand)")
flag.StringVar(&host, "host", "localhost", "address to bind")
flag.StringVar(&host, "h", "localhost", "address to bind (shorthand)")
flag.StringVar(&webDir, "web", "web", "static served web files.")
flag.StringVar(&webDir, "w", "web", "static served web files (shorthand)")
flag.StringVar(&mapDir, "map", "map", "directory of prerendered tiles")
flag.StringVar(&mapDir, "m", "map", "directory of prerendered tiles (shorthand)")
flag.Parse()
r := mux.NewRouter()
r.HandleFunc("/map/{z:[0-9]+}/{x:[0-9]+}/{y:[0-9]+}.png",
func(rw http.ResponseWriter, r *http.Request) {
createTiles(rw, r, mapDir)
})
r.PathPrefix("/").Handler(http.FileServer(http.Dir(webDir)))
http.Handle("/", r)
addr := fmt.Sprintf("%s:%d", host, port)
if err := http.ListenAndServe(addr, nil); err != nil {
log.Fatalf("Starting server failed: %s\n", err)
}
}