1
0
forked from MTSR/mapserver

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

View File

@ -22,7 +22,7 @@ func Render(renderer *mapblockrenderer.MapBlockRenderer,
go func() { go func() {
for result := range results { for result := range results {
tc := coords.GetTileCoordsFromMapBlock(result.Job.Pos1) 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) tdb.SetTile(&tile)
} }
}() }()

View File

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

View File

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

View File

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

View File

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

View File

@ -4,22 +4,19 @@ import (
"image" "image"
"mapserver/coords" "mapserver/coords"
"mapserver/mapblockrenderer" "mapserver/mapblockrenderer"
"mapserver/tiledb"
) )
type TileRenderer struct { type TileRenderer struct {
mapblockrenderer *mapblockrenderer.MapBlockRenderer mapblockrenderer *mapblockrenderer.MapBlockRenderer
tiledb *tiledb.DBAccessor
} }
func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, tiledb *tiledb.DBAccessor) *TileRenderer { func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer) *TileRenderer {
return &TileRenderer{ return &TileRenderer{
mapblockrenderer: mapblockrenderer, mapblockrenderer: mapblockrenderer,
tiledb: tiledb,
} }
} }
//TODO layerConfig //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 return nil, nil
} }