1
0
forked from MTSR/mapserver

mapblock coords to tile

This commit is contained in:
NatureFreshMilk 2019-01-17 10:04:09 +01:00
parent f00dc6dcf4
commit 914e2cb667
7 changed files with 96 additions and 7 deletions

View File

@ -9,7 +9,7 @@ func NewMapBlockCoords(x, y, z int) MapBlockCoords {
}
type MapBlockRange struct {
pos1, pos2 MapBlockCoords
Pos1, Pos2 MapBlockCoords
}
const (

View File

@ -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),
}
}

View File

@ -72,6 +72,6 @@ func main() {
panic(err)
}
initialrenderer.Render(&r, tdb)
initialrenderer.Render(r, tdb)
}

View File

@ -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 (

View File

@ -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 {

View File

@ -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
}

View File

@ -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")
}
}