summaryrefslogtreecommitdiff
path: root/vendor/github.com/felix/go-staticmaps/tile_provider.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/felix/go-staticmaps/tile_provider.go')
-rw-r--r--vendor/github.com/felix/go-staticmaps/tile_provider.go142
1 files changed, 142 insertions, 0 deletions
diff --git a/vendor/github.com/felix/go-staticmaps/tile_provider.go b/vendor/github.com/felix/go-staticmaps/tile_provider.go
new file mode 100644
index 0000000..2848e28
--- /dev/null
+++ b/vendor/github.com/felix/go-staticmaps/tile_provider.go
@@ -0,0 +1,142 @@
+// Copyright 2016 Florian Pigorsch. All rights reserved.
+//
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package sm
+
+import "fmt"
+
+// TileProvider encapsulates all infos about a map tile provider service (name, url scheme, attribution, etc.)
+type TileProvider struct {
+ Name string
+ Attribution string
+ TileSize int
+ URLPattern string // "%[1]s" => shard, "%[2]d" => zoom, "%[3]d" => x, "%[4]d" => y
+ Shards []string
+}
+
+func (t *TileProvider) getURL(shard string, zoom, x, y int) string {
+ return fmt.Sprintf(t.URLPattern, shard, zoom, x, y)
+}
+
+// NewTileProviderOpenStreetMaps creates a TileProvider struct for OSM's tile service
+func NewTileProviderOpenStreetMaps() *TileProvider {
+ t := new(TileProvider)
+ t.Name = "osm"
+ t.Attribution = "Maps and Data (c) openstreetmaps.org and contributors, ODbL"
+ t.TileSize = 256
+ t.URLPattern = "http://%[1]s.tile.openstreemaps.org/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b", "c"}
+ return t
+}
+
+func newTileProviderThunderforest(name string) *TileProvider {
+ t := new(TileProvider)
+ t.Name = fmt.Sprintf("thunderforest-%s", name)
+ t.Attribution = "Maps (c) Thundeforest; Data (c) OSM and contributors, ODbL"
+ t.TileSize = 256
+ t.URLPattern = "https://%[1]s.tile.thunderforest.com/" + name + "/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b", "c"}
+ return t
+}
+
+// NewTileProviderThunderforestLandscape creates a TileProvider struct for thundeforests's 'landscape' tile service
+func NewTileProviderThunderforestLandscape() *TileProvider {
+ return newTileProviderThunderforest("landscape")
+}
+
+// NewTileProviderThunderforestOutdoors creates a TileProvider struct for thundeforests's 'outdoors' tile service
+func NewTileProviderThunderforestOutdoors() *TileProvider {
+ return newTileProviderThunderforest("outdoors")
+}
+
+// NewTileProviderThunderforestTransport creates a TileProvider struct for thundeforests's 'transport' tile service
+func NewTileProviderThunderforestTransport() *TileProvider {
+ return newTileProviderThunderforest("transport")
+}
+
+// NewTileProviderStamenToner creates a TileProvider struct for stamens' 'toner' tile service
+func NewTileProviderStamenToner() *TileProvider {
+ t := new(TileProvider)
+ t.Name = "stamen-toner"
+ t.Attribution = "Maps (c) Stamen; Data (c) OSM and contributors, ODbL"
+ t.TileSize = 256
+ t.URLPattern = "http://%[1]s.tile.stamen.com/toner/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b", "c", "d"}
+ return t
+}
+
+// NewTileProviderOpenTopoMap creates a TileProvider struct for opentopomaps's tile service
+func NewTileProviderOpenTopoMap() *TileProvider {
+ t := new(TileProvider)
+ t.Name = "opentopomap"
+ t.Attribution = "Maps (c) OpenTopoMap [CC-BY-SA]; Data (c) OSM and contributors [ODbL]; Data (c) SRTM"
+ t.TileSize = 256
+ t.URLPattern = "http://%[1]s.tile.opentopomap.org/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b", "c"}
+ return t
+}
+
+func NewTileProviderWikimedia() *TileProvider {
+ t := new(TileProvider)
+ t.Name = "wikimedia"
+ t.Attribution = "Map (c) Wikimedia; Data (c) OSM and contributers, ODbL."
+ t.TileSize = 256
+ t.URLPattern = "https://maps.wikimedia.org/osm-intl/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{}
+ return t
+}
+
+func NewTileProviderOpenCycleMap() *TileProvider {
+ t := new(TileProvider)
+ t.Name = "cycle"
+ t.Attribution = "Maps and Data (c) openstreetmaps.org and contributors, ODbL"
+ t.TileSize = 256
+ t.URLPattern = "http://%[1]s.tile.opencyclemap.org/cycle/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b"}
+ return t
+}
+
+func newTileProviderCarto(name string) *TileProvider {
+ t := new(TileProvider)
+ t.Name = fmt.Sprintf("carto-%s", name)
+ t.Attribution = "Map (c) Carto [CC BY 3.0] Data (c) OSM and contributers, ODbL."
+ t.TileSize = 256
+ t.URLPattern = "https://cartodb-basemaps-%[1]s.global.ssl.fastly.net/" + name + "_all/%[2]d/%[3]d/%[4]d.png"
+ t.Shards = []string{"a", "b", "c", "d"}
+ return t
+}
+
+func NewTileProviderCartoLight() *TileProvider {
+ return newTileProviderCarto("light")
+}
+
+func NewTileProviderCartoDark() *TileProvider {
+ return newTileProviderCarto("dark")
+}
+
+// GetTileProviders returns a map of all available TileProviders
+func GetTileProviders() map[string]*TileProvider {
+ m := make(map[string]*TileProvider)
+
+ list := []*TileProvider{
+ NewTileProviderOpenStreetMaps(),
+ NewTileProviderOpenCycleMap(),
+ NewTileProviderThunderforestLandscape(),
+ NewTileProviderThunderforestOutdoors(),
+ NewTileProviderThunderforestTransport(),
+ NewTileProviderStamenToner(),
+ NewTileProviderOpenTopoMap(),
+ NewTileProviderOpenStreetMaps(),
+ NewTileProviderOpenCycleMap(),
+ NewTileProviderCartoLight(),
+ NewTileProviderCartoDark(),
+ }
+
+ for _, tp := range list {
+ m[tp.Name] = tp
+ }
+
+ return m
+}