Created
February 15, 2019 16:18
-
-
Save peterhellberg/b771ae289342e28c0bced8c99548e7c5 to your computer and use it in GitHub Desktop.
Stamen Watercolor tiles rendered using gfx. http://maps.stamen.com/watercolor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "github.com/peterhellberg/gfx" | |
const ( | |
zoomLevels = 19 | |
tileSize = 256 | |
tileFormat = "http://a.tile.stamen.com/watercolor/%d/%d/%d.jpg" | |
) | |
func main() { | |
pos := gfx.GP(59.270889, 18.048125) | |
dst := gfx.NewImage(tileSize*(zoomLevels+1), tileSize) | |
for zoom := 0; zoom <= zoomLevels; zoom++ { | |
gt := pos.GeoTile(zoom) | |
src, err := gfx.GetImage(gt.Rawurl(tileFormat)) | |
if err != nil { | |
panic(err) | |
} | |
r := gfx.NewRect( | |
gfx.IV(tileSize*zoom, 0), | |
gfx.IV(tileSize*zoom+tileSize, tileSize), | |
) | |
gfx.Draw(dst, r.Bounds(), src) | |
gfx.DrawLine(dst, r.Min, r.Min.AddXY(0, tileSize), 1, gfx.ColorBlack) | |
} | |
gfx.SavePNG("gfx-geo-tiles-stamen-watercolor.png", dst) | |
} |
Author
peterhellberg
commented
Feb 15, 2019
Using the Stamen Terrain tileset
package main
import "github.com/peterhellberg/gfx"
const (
zoomLevels = 18
tileSize = 256
tileFormat = "http://a.tile.stamen.com/terrain/%d/%d/%d.png"
)
func main() {
pos := gfx.GP(59.270889, 18.048125)
dst := gfx.NewImage(tileSize, tileSize*zoomLevels)
for zoom := 0; zoom < zoomLevels; zoom++ {
gt := pos.GeoTile(zoom)
src, err := gfx.GetImage(gt.Rawurl(tileFormat))
if err != nil {
continue
}
r := gfx.NewRect(
gfx.IV(0, tileSize*zoom),
gfx.IV(tileSize, tileSize*zoom+tileSize),
)
gfx.Draw(dst, r.Bounds(), src)
gfx.DrawLine(dst, r.Min, r.Min.AddXY(tileSize, 0), 1, gfx.ColorBlack)
}
gfx.SavePNG("gfx-geo-tiles-stamen-terrain.png", dst)
}
256x256 | 512x512 |
---|---|
Using the Carto Basemaps tileset
package main
import "github.com/peterhellberg/gfx"
const (
zoomLevels = 19
tileSize = 512
tileFormat = "https://a.basemaps.cartocdn.com/rastertiles/voyager/%d/%d/%d@2x.png"
)
func main() {
pos := gfx.GP(59.270889, 18.048125)
dst := gfx.NewImage(tileSize, tileSize*zoomLevels)
for zoom := 0; zoom < zoomLevels; zoom++ {
gt := pos.GeoTile(zoom)
src, err := gfx.GetImage(gt.Rawurl(tileFormat))
if err != nil {
continue
}
r := gfx.NewRect(
gfx.IV(0, tileSize*zoom),
gfx.IV(tileSize, tileSize*zoom+tileSize),
)
gfx.Draw(dst, r.Bounds(), src)
gfx.DrawLine(dst, r.Min, r.Min.AddXY(tileSize, 0), 1, gfx.ColorBlack)
}
gfx.SavePNG("gfx-geo-tiles-carto-basemaps.png", dst)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment