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:
parent
aa33543af8
commit
a37dafe18d
1 changed files with 18 additions and 2 deletions
20
map.go
20
map.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue