forked from MTSR/mapserver
mapblock coords to tile
This commit is contained in:
parent
f00dc6dcf4
commit
914e2cb667
@ -9,7 +9,7 @@ func NewMapBlockCoords(x, y, z int) MapBlockCoords {
|
||||
}
|
||||
|
||||
type MapBlockRange struct {
|
||||
pos1, pos2 MapBlockCoords
|
||||
Pos1, Pos2 MapBlockCoords
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -72,6 +72,6 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
initialrenderer.Render(&r, tdb)
|
||||
initialrenderer.Render(r, tdb)
|
||||
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
62
tilerenderer/renderer_test.go
Normal file
62
tilerenderer/renderer_test.go
Normal 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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user