From eeaa772e30fa3ec7bcb8bd5e02b60b5a26eb5e5b Mon Sep 17 00:00:00 2001 From: flopp Date: Tue, 6 Dec 2016 20:01:52 +0100 Subject: [PATCH] fixed tile url --- README.md | 7 +++++++ context.go | 3 +++ tile_fetcher.go | 4 ++-- tile_provider.go | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 836af67..cd46401 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,13 @@ Installing go-staticmaps is as easy as go get -u github.com/flopp/go-staticmaps ``` +For the command line tool, use +```bash +go get -u github.com/flopp/go-staticmaps/create-static-map +``` + +Of course, your local Go installation must be setup up properly. + ### Library Usage Create a 400x300 pixel map with a red marker: diff --git a/context.go b/context.go index db6f9c2..288184f 100644 --- a/context.go +++ b/context.go @@ -10,6 +10,7 @@ import ( "errors" "image" "image/draw" + "log" "math" "github.com/fogleman/gg" @@ -242,6 +243,8 @@ func (m *Context) Render() (image.Image, error) { y := trans.tOriginY + yy if tileImg, err := t.Fetch(zoom, x, y); err == nil { gc.DrawImage(tileImg, xx*tileSize, yy*tileSize) + } else { + log.Printf("Error downloading tile file: %s", err) } } } diff --git a/tile_fetcher.go b/tile_fetcher.go index e02a71f..53a8c99 100644 --- a/tile_fetcher.go +++ b/tile_fetcher.go @@ -89,12 +89,12 @@ func (t *TileFetcher) Fetch(zoom, x, y int) (image.Image, error) { func (t *TileFetcher) download(url string) ([]byte, error) { resp, err := http.Get(url) - defer resp.Body.Close() - if err != nil { return nil, err } + defer resp.Body.Close() + contents, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err diff --git a/tile_provider.go b/tile_provider.go index 2848e28..dd29b22 100644 --- a/tile_provider.go +++ b/tile_provider.go @@ -24,9 +24,9 @@ func (t *TileProvider) getURL(shard string, zoom, x, y int) string { func NewTileProviderOpenStreetMaps() *TileProvider { t := new(TileProvider) t.Name = "osm" - t.Attribution = "Maps and Data (c) openstreetmaps.org and contributors, ODbL" + t.Attribution = "Maps and Data (c) openstreetmap.org and contributors, ODbL" t.TileSize = 256 - t.URLPattern = "http://%[1]s.tile.openstreemaps.org/%[2]d/%[3]d/%[4]d.png" + t.URLPattern = "http://%[1]s.tile.openstreetmap.org/%[2]d/%[3]d/%[4]d.png" t.Shards = []string{"a", "b", "c"} return t }