2019-01-17 12:04:09 +03:00
|
|
|
package tilerenderer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
2019-01-18 11:13:37 +03:00
|
|
|
"mapserver/coords"
|
2019-02-05 15:13:34 +03:00
|
|
|
"mapserver/db/sqlite"
|
2019-01-21 13:13:00 +03:00
|
|
|
"mapserver/layer"
|
2019-01-18 11:13:37 +03:00
|
|
|
"mapserver/mapblockaccessor"
|
|
|
|
"mapserver/mapblockrenderer"
|
2019-01-21 18:27:31 +03:00
|
|
|
"mapserver/testutils"
|
2019-02-09 20:05:40 +03:00
|
|
|
"mapserver/tiledb"
|
2019-01-17 12:04:09 +03:00
|
|
|
"os"
|
|
|
|
"testing"
|
2019-02-25 09:23:27 +03:00
|
|
|
"time"
|
2019-06-19 22:19:53 +03:00
|
|
|
|
2023-01-20 19:44:59 +03:00
|
|
|
"github.com/minetest-go/colormapping"
|
|
|
|
|
2019-06-19 22:19:53 +03:00
|
|
|
"github.com/sirupsen/logrus"
|
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())
|
|
|
|
|
2019-02-05 15:13:34 +03:00
|
|
|
a, err := sqlite.New(tmpfile.Name())
|
2019-01-17 12:04:09 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = a.Migrate()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:08:30 +03:00
|
|
|
cache := mapblockaccessor.NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond, 1000)
|
2019-01-17 12:04:09 +03:00
|
|
|
c := colormapping.NewColorMapping()
|
2023-01-20 20:02:37 +03:00
|
|
|
err = c.LoadDefaults()
|
2019-01-17 12:04:09 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-06-20 08:14:14 +03:00
|
|
|
r := mapblockrenderer.NewMapBlockRenderer(cache, c)
|
2019-01-17 12:04:09 +03:00
|
|
|
|
2021-04-12 14:03:10 +03:00
|
|
|
tiletmpdir, _ := ioutil.TempDir("", "TestTileRenderTiles.*.sqlite")
|
2019-02-09 20:05:40 +03:00
|
|
|
defer os.RemoveAll(tiletmpdir)
|
2019-01-17 13:20:03 +03:00
|
|
|
|
2019-02-09 20:05:40 +03:00
|
|
|
tdb, _ := tiledb.New(tiletmpdir)
|
2019-01-17 13:20:03 +03:00
|
|
|
|
2019-02-14 10:50:54 +03:00
|
|
|
layers := []*layer.Layer{
|
2023-10-11 18:35:39 +03:00
|
|
|
{
|
2019-01-21 13:13:00 +03:00
|
|
|
Id: 0,
|
|
|
|
Name: "Base",
|
|
|
|
From: -16,
|
|
|
|
To: 160,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
tr := NewTileRenderer(r, tdb, a, layers)
|
2019-01-17 12:04:09 +03:00
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
if tr == nil {
|
|
|
|
panic("no renderer")
|
|
|
|
}
|
2019-01-17 12:04:09 +03:00
|
|
|
|
2019-01-18 11:13:37 +03:00
|
|
|
coord := coords.NewTileCoords(0, 0, 12, 0)
|
2019-10-01 09:13:55 +03:00
|
|
|
err = tr.Render(coord)
|
2019-01-22 14:53:36 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-17 12:04:09 +03:00
|
|
|
|
2019-01-22 14:53:36 +03:00
|
|
|
coord1 := coord.GetZoomedOutTile()
|
|
|
|
|
2019-10-01 09:13:55 +03:00
|
|
|
err = tr.Render(coord1)
|
2019-01-18 11:13:37 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-17 12:04:09 +03:00
|
|
|
|
|
|
|
}
|