fixed tile url

This commit is contained in:
flopp 2016-12-06 20:01:52 +01:00
parent 4609e63ef9
commit eeaa772e30
4 changed files with 14 additions and 4 deletions

View File

@ -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:

View File

@ -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)
}
}
}

View File

@ -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

View File

@ -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
}