diff --git a/coords/mapblockcoords.go b/coords/mapblockcoords.go index c1ae682..ac24fd6 100644 --- a/coords/mapblockcoords.go +++ b/coords/mapblockcoords.go @@ -9,7 +9,7 @@ func NewMapBlockCoords(x, y, z int) MapBlockCoords { } type MapBlockRange struct { - pos1, pos2 MapBlockCoords + Pos1, Pos2 MapBlockCoords } const ( diff --git a/coords/tileconvert.go b/coords/tileconvert.go index 48c63a3..f5b25bc 100644 --- a/coords/tileconvert.go +++ b/coords/tileconvert.go @@ -1,5 +1,9 @@ package coords +import ( + "math" +) + const ( MAX_ZOOM = 13 ) @@ -7,3 +11,19 @@ const ( func GetTileCoordsFromMapBlock(mbc MapBlockCoords) TileCoords { return TileCoords{X: mbc.X, Y: (mbc.Z + 1) * -1, Zoom: MAX_ZOOM} } + +func GetMapBlockRangeFromTile(tc TileCoords, y int) MapBlockRange { + scaleDiff := float64(MAX_ZOOM - tc.Zoom) + scale := int(math.Pow(2, scaleDiff)) + + mapBlockX1 := tc.X * scale + mapBlockZ1 := (tc.Y * scale * -1) - 1 + + mapBlockX2 := mapBlockX1 + scale-1 + mapBlockZ2 := (mapBlockZ1 + ((scale-1) * -1)) + + return MapBlockRange{ + Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1), + Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2), + } +} diff --git a/main.go b/main.go index 2f0d89b..1566450 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,6 @@ func main() { panic(err) } - initialrenderer.Render(&r, tdb) + initialrenderer.Render(r, tdb) } diff --git a/mapblockrenderer/renderer.go b/mapblockrenderer/renderer.go index 7aa9dac..6b4e83b 100644 --- a/mapblockrenderer/renderer.go +++ b/mapblockrenderer/renderer.go @@ -16,8 +16,8 @@ type MapBlockRenderer struct { colors *colormapping.ColorMapping } -func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping) MapBlockRenderer { - return MapBlockRenderer{accessor: accessor, colors: colors} +func NewMapBlockRenderer(accessor *mapblockaccessor.MapBlockAccessor, colors *colormapping.ColorMapping) *MapBlockRenderer { + return &MapBlockRenderer{accessor: accessor, colors: colors} } const ( diff --git a/mapblockrenderer/renderer_test.go b/mapblockrenderer/renderer_test.go index 13c8f72..c9c2b2e 100644 --- a/mapblockrenderer/renderer_test.go +++ b/mapblockrenderer/renderer_test.go @@ -46,9 +46,9 @@ func TestSimpleRender(t *testing.T) { results := make(chan JobResult, 100) jobs := make(chan JobData, 100) - go Worker(&r, jobs, results) - go Worker(&r, jobs, results) - go Worker(&r, jobs, results) + go Worker(r, jobs, results) + go Worker(r, jobs, results) + go Worker(r, jobs, results) go func() { for result := range results { diff --git a/tilerenderer/renderer.go b/tilerenderer/renderer.go index ba32d9d..e28fcba 100644 --- a/tilerenderer/renderer.go +++ b/tilerenderer/renderer.go @@ -18,5 +18,12 @@ func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer) *TileR //TODO layerConfig func (tr *TileRenderer) Render(tc coords.TileCoords) (*image.NRGBA, error) { + if tc.Zoom == 13 { + //max zoomed in on mapblock level + //mbr := coords.GetMapBlockRangeFromTile(tc, 0) + //return tr.mapblockrenderer.Render() + + } + return nil, nil } diff --git a/tilerenderer/renderer_test.go b/tilerenderer/renderer_test.go new file mode 100644 index 0000000..e704cae --- /dev/null +++ b/tilerenderer/renderer_test.go @@ -0,0 +1,62 @@ +package tilerenderer + +import ( + "github.com/sirupsen/logrus" + "io/ioutil" + "mapserver/colormapping" + "mapserver/db" + "mapserver/mapblockaccessor" + "mapserver/testutils" + "mapserver/mapblockrenderer" + "mapserver/coords" + "os" + "testing" +) + +func TestTileRender(t *testing.T) { + logrus.SetLevel(logrus.InfoLevel) + + tmpfile, err := ioutil.TempFile("", "TestTileRender.*.sqlite") + if err != nil { + panic(err) + } + 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) + + tr := NewTileRenderer(r) + + if tr == nil { + panic("no renderer") + } + + coord := coords.NewTileCoords(0,0,12,0) + + data, err := tr.Render(coord) + + if err != nil { + panic(err) + } + + if data == nil { + panic("no data") + } +}