2019-01-17 12:04:09 +03:00
|
|
|
package tilerenderer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"io/ioutil"
|
|
|
|
"mapserver/colormapping"
|
|
|
|
"mapserver/db"
|
|
|
|
"mapserver/mapblockaccessor"
|
|
|
|
"mapserver/testutils"
|
|
|
|
"mapserver/mapblockrenderer"
|
|
|
|
"mapserver/coords"
|
2019-01-17 13:20:03 +03:00
|
|
|
"mapserver/layerconfig"
|
|
|
|
"mapserver/tiledb"
|
2019-01-17 12:04:09 +03:00
|
|
|
"os"
|
|
|
|
"testing"
|
2019-01-17 13:20:03 +03:00
|
|
|
"bytes"
|
2019-01-17 12:04:09 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestTileRender(t *testing.T) {
|
2019-01-17 13:27:31 +03:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2019-01-17 12:04:09 +03:00
|
|
|
|
|
|
|
tmpfile, err := ioutil.TempFile("", "TestTileRender.*.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-17 13:20:03 +03:00
|
|
|
|
2019-01-17 12:04:09 +03:00
|
|
|
defer os.Remove(tmpfile.Name())
|
|
|
|
testutils.CreateTestDatabase(tmpfile.Name())
|
|
|
|
|
|
|
|
a, err := db.NewSqliteAccessor(tmpfile.Name())
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = a.Migrate()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cache := mapblockaccessor.NewMapBlockAccessor(a)
|
|
|
|
c := colormapping.NewColorMapping()
|
|
|
|
err = c.LoadVFSColors(false, "/colors.txt")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
r := mapblockrenderer.NewMapBlockRenderer(cache, c)
|
|
|
|
|
2019-01-17 13:20:03 +03:00
|
|
|
tiletmpfile, err := ioutil.TempFile("", "TestTileRenderTiles.*.sqlite")
|
|
|
|
defer os.Remove(tiletmpfile.Name())
|
|
|
|
|
|
|
|
tdb, _ := tiledb.NewSqliteAccessor(tiletmpfile.Name())
|
|
|
|
tdb.Migrate()
|
|
|
|
|
|
|
|
tr := NewTileRenderer(r, tdb, layerconfig.DefaultLayers)
|
2019-01-17 12:04:09 +03:00
|
|
|
|
|
|
|
if tr == nil {
|
|
|
|
panic("no renderer")
|
|
|
|
}
|
|
|
|
|
2019-01-17 13:27:31 +03:00
|
|
|
coord := coords.NewTileCoords(0,0,11,0)
|
2019-01-17 12:04:09 +03:00
|
|
|
|
|
|
|
data, err := tr.Render(coord)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if data == nil {
|
|
|
|
panic("no data")
|
|
|
|
}
|
2019-01-17 13:20:03 +03:00
|
|
|
|
|
|
|
f, _ := os.Create("../output/0_0_12.png")
|
|
|
|
bytes.NewReader(data).WriteTo(f)
|
2019-01-17 12:04:09 +03:00
|
|
|
}
|