layerid on tile-pos

This commit is contained in:
NatureFreshMilk 2019-01-17 08:53:07 +01:00
parent 39263d3e7f
commit f00dc6dcf4
7 changed files with 20 additions and 24 deletions

View File

@ -7,21 +7,23 @@ import (
type TileCoords struct {
X, Y int
Zoom int
LayerId int
}
type TileQuadrants struct {
UpperLeft, UpperRight, LowerLeft, LowerRight TileCoords
}
func NewTileCoords(x, y, zoom int) TileCoords {
return TileCoords{X: x, Y: y, Zoom: zoom}
func NewTileCoords(x, y, zoom int, layerId int) TileCoords {
return TileCoords{X: x, Y: y, Zoom: zoom, LayerId: layerId}
}
func (tc TileCoords) GetZoomedOutTile() TileCoords {
return TileCoords{
X: int(math.Floor(float64(tc.X) / 2.0)),
Y: int(math.Floor(float64(tc.Y) / 2.0)),
Zoom: tc.Zoom - 1}
Zoom: tc.Zoom - 1,
LayerId: tc.LayerId}
}
func (tc TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
@ -30,10 +32,10 @@ func (tc TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
nextZoomX := tc.X * 2
nextZoomY := tc.Y * 2
upperLeft := TileCoords{X: nextZoomX, Y: nextZoomY, Zoom: nextZoom}
upperRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom: nextZoom}
lowerLeft := TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom: nextZoom}
lowerRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom: nextZoom}
upperLeft := TileCoords{X: nextZoomX, Y: nextZoomY, Zoom: nextZoom, LayerId: tc.LayerId}
upperRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY, Zoom: nextZoom, LayerId: tc.LayerId}
lowerLeft := TileCoords{X: nextZoomX, Y: nextZoomY + 1, Zoom: nextZoom, LayerId: tc.LayerId}
lowerRight := TileCoords{X: nextZoomX + 1, Y: nextZoomY + 1, Zoom: nextZoom, LayerId: tc.LayerId}
return TileQuadrants{
UpperLeft: upperLeft,

View File

@ -22,7 +22,7 @@ func Render(renderer *mapblockrenderer.MapBlockRenderer,
go func() {
for result := range results {
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1)
tile := tiledb.Tile{Pos: tc, LayerId: 0, Data: result.Data.Bytes(), Mtime: time.Now().Unix()}
tile := tiledb.Tile{Pos: tc, Data: result.Data.Bytes(), Mtime: time.Now().Unix()}
tdb.SetTile(&tile)
}
}()

View File

@ -76,6 +76,5 @@ func TestSimpleRender(t *testing.T) {
}
close(jobs)
defer close(results)
}

View File

@ -6,13 +6,12 @@ import (
type Tile struct {
Pos coords.TileCoords
LayerId int
Data []byte
Mtime int64
}
type DBAccessor interface {
Migrate() error
GetTile(layerId int, pos coords.TileCoords) (*Tile, error)
GetTile(pos coords.TileCoords) (*Tile, error)
SetTile(tile *Tile) error
}

View File

@ -47,8 +47,8 @@ and t.y = ?
and t.zoom = ?
`
func (db *Sqlite3Accessor) GetTile(layerId int, pos coords.TileCoords) (*Tile, error) {
rows, err := db.db.Query(getTileQuery, layerId, pos.X, pos.Y, pos.Zoom)
func (db *Sqlite3Accessor) GetTile(pos coords.TileCoords) (*Tile, error) {
rows, err := db.db.Query(getTileQuery, pos.LayerId, pos.X, pos.Y, pos.Zoom)
if err != nil {
return nil, err
}
@ -70,7 +70,6 @@ func (db *Sqlite3Accessor) GetTile(layerId int, pos coords.TileCoords) (*Tile, e
mb := Tile{
Pos: pos,
LayerId: layerId,
Data: data,
Mtime: mtime,
}
@ -87,7 +86,7 @@ values(?, ?, ?, ?, ?, ?)
`
func (db *Sqlite3Accessor) SetTile(tile *Tile) error {
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.LayerId, tile.Data, tile.Mtime)
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.Pos.LayerId, tile.Data, tile.Mtime)
return err
}

View File

@ -24,8 +24,8 @@ func TestMigrate(t *testing.T) {
panic(err)
}
pos := coords.NewTileCoords(0, 0, 13)
tile, err := db.GetTile(0, pos)
pos := coords.NewTileCoords(0, 0, 13, 0)
tile, err := db.GetTile(pos)
if err != nil {
panic(err)
}
@ -35,14 +35,14 @@ func TestMigrate(t *testing.T) {
}
data := []byte{0x01, 0x02}
tile2 := Tile{LayerId: 0, Pos: pos, Data: data}
tile2 := Tile{Pos: pos, Data: data}
err = db.SetTile(&tile2)
if err != nil {
panic(err)
}
tile3, err := db.GetTile(0, pos)
tile3, err := db.GetTile(pos)
if err != nil {
panic(err)

View File

@ -4,22 +4,19 @@ import (
"image"
"mapserver/coords"
"mapserver/mapblockrenderer"
"mapserver/tiledb"
)
type TileRenderer struct {
mapblockrenderer *mapblockrenderer.MapBlockRenderer
tiledb *tiledb.DBAccessor
}
func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, tiledb *tiledb.DBAccessor) *TileRenderer {
func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer) *TileRenderer {
return &TileRenderer{
mapblockrenderer: mapblockrenderer,
tiledb: tiledb,
}
}
//TODO layerConfig
func (tr *TileRenderer) Render(tc coords.TileCoords, layerId int) (*image.NRGBA, error) {
func (tr *TileRenderer) Render(tc coords.TileCoords) (*image.NRGBA, error) {
return nil, nil
}