1
0
Fork 0
mirror of https://github.com/Luzifer/staticmap.git synced 2024-12-20 12:51:18 +00:00

Add overlay support

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-06-17 15:30:32 +02:00
parent aa33543af8
commit a37dafe18d
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

20
map.go
View file

@ -52,6 +52,7 @@ type generateMapConfig struct {
Width int
Height int
DisableAttribution bool
Overlays []*staticMap.TileProvider
}
func (g generateMapConfig) getCacheKey() string {
@ -59,13 +60,22 @@ func (g generateMapConfig) getCacheKey() string {
for _, m := range g.Markers {
markerString = append(markerString, m.String())
}
hashString := fmt.Sprintf("%s|%d|%s|%dx%d|%v",
overlayString := []string{}
for _, o := range g.Overlays {
overlayString = append(overlayString, o.URLPattern)
}
hashString := fmt.Sprintf("%s:::%s|%d|%s|%dx%d|%v|%s",
version,
g.Center.String(),
g.Zoom,
strings.Join(markerString, "+"),
g.Width,
g.Height,
g.DisableAttribution)
g.DisableAttribution,
fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join(overlayString, "::")))),
)
return fmt.Sprintf("%x", sha256.Sum256([]byte(hashString)))
}
@ -88,6 +98,12 @@ func generateMap(opts generateMapConfig) (io.Reader, error) {
}
}
if opts.Overlays != nil {
for _, o := range opts.Overlays {
ctx.AddOverlay(o)
}
}
img, err := ctx.Render()
if err != nil {
return nil, err