Permalink
Browse files

render: support for forced bgcolor in mapnik

  • Loading branch information...
olt committed Apr 5, 2018
1 parent 39b3cd9 commit 652dee53cfacf4273be71bd8c363dcedfd465faa
Showing with 26 additions and 1 deletion.
  1. +22 −1 render/magnacarto-mapnik/mapnik.go
  2. +1 −0 render/mapserver.go
  3. +3 −0 render/request.go
@@ -2,6 +2,8 @@ package main
import (
"fmt"
"image"
"image/draw"
"log"
"github.com/natefinch/pie"
@@ -30,7 +32,26 @@ func renderReq(mapfile string, mapReq render.Request) ([]byte, error) {
renderOpts.Format = mapReq.Format
renderOpts.ScaleFactor = mapReq.ScaleFactor
b, err := m.Render(renderOpts)
if mapReq.BGColor == nil {
b, err := m.Render(renderOpts)
if err != nil {
return nil, err
}
return b, nil
}
// draw image on requested bgcolor
img, err := m.RenderImage(renderOpts)
if err != nil {
return nil, err
}
result := image.NewNRGBA(img.Bounds())
bg := image.NewUniform(mapReq.BGColor)
draw.Draw(result, img.Bounds(), bg, image.ZP, draw.Src)
draw.Draw(result, img.Bounds(), img, image.ZP, draw.Over)
b, err := mapnik.Encode(result, mapReq.Format)
if err != nil {
return nil, err
}
@@ -46,6 +46,7 @@ func (m *MapServer) Render(mapfile string, dst io.Writer, mapReq Request) ([]str
q.Set("HEIGHT", fmt.Sprintf("%d", mapReq.Height))
q.Set("SRS", fmt.Sprintf("EPSG:%d", mapReq.EPSGCode))
q.Set("FORMAT", mapReq.Format)
// TODO: pass mapReq.BGColor to mapserver
if mapReq.ScaleFactor != 0 {
// mapserver default resolution is 72 dpi
@@ -1,10 +1,13 @@
package render
import "image/color"
type Request struct {
Width int
Height int
BBOX [4]float64
EPSGCode int
Format string
ScaleFactor float64
BGColor *color.RGBA
}

0 comments on commit 652dee5

Please sign in to comment.