diff --git a/coords/tilecoords.go b/coords/tilecoords.go index 12ce9b7..5b50ec1 100644 --- a/coords/tilecoords.go +++ b/coords/tilecoords.go @@ -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, diff --git a/initialrenderer/renderer.go b/initialrenderer/renderer.go index 345cad7..6592632 100644 --- a/initialrenderer/renderer.go +++ b/initialrenderer/renderer.go @@ -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) } }() diff --git a/mapblockrenderer/renderer_test.go b/mapblockrenderer/renderer_test.go index 2326fdb..13c8f72 100644 --- a/mapblockrenderer/renderer_test.go +++ b/mapblockrenderer/renderer_test.go @@ -76,6 +76,5 @@ func TestSimpleRender(t *testing.T) { } close(jobs) - defer close(results) } diff --git a/tiledb/accessor.go b/tiledb/accessor.go index 367a1e6..eecda5d 100644 --- a/tiledb/accessor.go +++ b/tiledb/accessor.go @@ -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 } diff --git a/tiledb/sqlite.go b/tiledb/sqlite.go index f5bbdd4..2440cbc 100644 --- a/tiledb/sqlite.go +++ b/tiledb/sqlite.go @@ -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 } diff --git a/tiledb/sqlite_test.go b/tiledb/sqlite_test.go index 3eaebc4..d4519f8 100644 --- a/tiledb/sqlite_test.go +++ b/tiledb/sqlite_test.go @@ -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) diff --git a/tilerenderer/renderer.go b/tilerenderer/renderer.go index d83f4ee..ba32d9d 100644 --- a/tilerenderer/renderer.go +++ b/tilerenderer/renderer.go @@ -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 }