mirror of
https://github.com/flopp/go-staticmaps.git
synced 2025-12-08 18:26:36 +00:00
fixed tile url
This commit is contained in:
parent
4609e63ef9
commit
eeaa772e30
@ -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:
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user