working zoom/scaled image

This commit is contained in:
Thomas Rudin 2019-01-20 21:03:58 +01:00
parent 876b4ac148
commit b058cb5421
4 changed files with 27 additions and 8 deletions

3
go.mod
View File

@ -1,13 +1,16 @@
module mapserver
require (
github.com/disintegration/imaging v1.5.0
github.com/google/go-cmp v0.2.0 // indirect
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 // indirect
github.com/mattn/go-sqlite3 v1.10.0
github.com/mjibson/esc v0.1.0 // indirect
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/sirupsen/logrus v1.3.0
github.com/stretchr/testify v1.2.2
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 // indirect
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 // indirect
gotest.tools v2.2.0+incompatible
)

6
go.sum
View File

@ -1,5 +1,7 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/disintegration/imaging v1.5.0 h1:uYqUhwNmLU4K1FN44vhqS4TZJRAA4RhBINgbQlKyGi0=
github.com/disintegration/imaging v1.5.0/go.mod h1:9B/deIUIrliYkyMTuXJd6OUFLcrZ2tf+3Qlwnaf/CjU=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/pprof v0.0.0-20190109223431-e84dfd68c163 h1:beB+Da4k9B1zmgag78k3k1Bx4L/fdWr5FwNa0f8RxmY=
@ -9,6 +11,8 @@ github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK86
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mjibson/esc v0.1.0 h1:5ch+murgrcwDFLOE2hwj0f7kE4xJfJhkSCAjSLY182o=
github.com/mjibson/esc v0.1.0/go.mod h1:9Hw9gxxfHulMF5OJKCyhYD7PzlSdhzXyaGEBRPH1OPs=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -22,6 +26,8 @@ golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 h1:Pn8fQdvx+z1avAi7fdM2kRYW
golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2 h1:FNSSV4jv1PrPsiM2iKGpqLPPgYACqh9Muav7Pollk1k=
golang.org/x/image v0.0.0-20190118043309-183bebdce1b2/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=

View File

@ -2,7 +2,6 @@ package mapblockrenderer
import (
"errors"
"github.com/sirupsen/logrus"
"image"
"image/color"
"image/draw"
@ -10,6 +9,8 @@ import (
"mapserver/coords"
"mapserver/mapblockaccessor"
"time"
"github.com/sirupsen/logrus"
)
type MapBlockRenderer struct {
@ -173,9 +174,12 @@ func (r *MapBlockRenderer) Render(pos1, pos2 coords.MapBlockCoords) (*image.NRGB
}
}
imgX := x * IMG_SCALE
imgY := (15 - z) * IMG_SCALE
rect := image.Rect(
x*IMG_SCALE, z*IMG_SCALE,
(x*IMG_SCALE)+IMG_SCALE, (z*IMG_SCALE)+IMG_SCALE,
imgX, imgY,
imgX+IMG_SCALE, imgY+IMG_SCALE,
)
foundBlocks++

View File

@ -3,7 +3,6 @@ package tilerenderer
import (
"bytes"
"errors"
"github.com/sirupsen/logrus"
"image"
"image/draw"
"image/png"
@ -13,6 +12,9 @@ import (
"mapserver/mapblockrenderer"
"mapserver/tiledb"
"time"
"github.com/disintegration/imaging"
"github.com/sirupsen/logrus"
)
type TileRenderer struct {
@ -180,22 +182,26 @@ func (tr *TileRenderer) RenderImage(tc coords.TileCoords) (*image.NRGBA, error)
rect := image.Rect(0, 0, 128, 128)
if upperLeft != nil {
draw.Draw(img, rect, upperLeft, image.ZP, draw.Src)
resizedImg := imaging.Resize(upperLeft, 128, 128, imaging.Lanczos)
draw.Draw(img, rect, resizedImg, image.ZP, draw.Src)
}
rect = image.Rect(128, 0, 256, 128)
if upperRight != nil {
draw.Draw(img, rect, upperRight, image.ZP, draw.Src)
resizedImg := imaging.Resize(upperRight, 128, 128, imaging.Lanczos)
draw.Draw(img, rect, resizedImg, image.ZP, draw.Src)
}
rect = image.Rect(0, 128, 128, 256)
if lowerLeft != nil {
draw.Draw(img, rect, lowerLeft, image.ZP, draw.Src)
resizedImg := imaging.Resize(lowerLeft, 128, 128, imaging.Lanczos)
draw.Draw(img, rect, resizedImg, image.ZP, draw.Src)
}
rect = image.Rect(128, 128, 256, 256)
if lowerRight != nil {
draw.Draw(img, rect, lowerRight, image.ZP, draw.Src)
resizedImg := imaging.Resize(lowerRight, 128, 128, imaging.Lanczos)
draw.Draw(img, rect, resizedImg, image.ZP, draw.Src)
}
buf := new(bytes.Buffer)