Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created February 15, 2019 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterhellberg/b771ae289342e28c0bced8c99548e7c5 to your computer and use it in GitHub Desktop.
Save peterhellberg/b771ae289342e28c0bced8c99548e7c5 to your computer and use it in GitHub Desktop.
Stamen Watercolor tiles rendered using gfx. http://maps.stamen.com/watercolor
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)
}
@peterhellberg
Copy link
Author

gfx-geo-tiles-stamen-watercolor

@peterhellberg
Copy link
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

@peterhellberg
Copy link
Author

peterhellberg commented Feb 15, 2019

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

gfx-geo-tiles-carto-basemaps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment