tile db / accessor
This commit is contained in:
parent
9aa5e5e27c
commit
deff39ea93
10
coords/tileconvert.go
Normal file
10
coords/tileconvert.go
Normal file
@ -0,0 +1,10 @@
|
||||
package coords
|
||||
|
||||
const (
|
||||
MAX_ZOOM = 13
|
||||
)
|
||||
|
||||
|
||||
func GetTileCoordsFromMapBlock(mbc MapBlockCoords) TileCoords {
|
||||
return TileCoords{X:mbc.X, Y:(mbc.Z + 1) * -1, Zoom:MAX_ZOOM};
|
||||
}
|
44
coords/tilecoords.go
Normal file
44
coords/tilecoords.go
Normal file
@ -0,0 +1,44 @@
|
||||
package coords
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
type TileCoords struct {
|
||||
X,Y int
|
||||
Zoom 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 (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}
|
||||
}
|
||||
|
||||
func (tc TileCoords) GetZoomedQuadrantsFromTile() TileQuadrants {
|
||||
nextZoom := tc.Zoom + 1
|
||||
|
||||
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}
|
||||
|
||||
return TileQuadrants{
|
||||
UpperLeft: upperLeft,
|
||||
UpperRight: upperRight,
|
||||
LowerLeft: lowerLeft,
|
||||
LowerRight: lowerRight,
|
||||
}
|
||||
}
|
10
db/logger.go
Normal file
10
db/logger.go
Normal file
@ -0,0 +1,10 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log *logrus.Entry
|
||||
func init(){
|
||||
log = logrus.WithFields(logrus.Fields{"prefix": "db"})
|
||||
}
|
@ -8,11 +8,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var log *logrus.Entry
|
||||
func init(){
|
||||
log = logrus.WithFields(logrus.Fields{"prefix": "db/sqlite"})
|
||||
}
|
||||
|
||||
const migrateScript = `
|
||||
alter table blocks add mtime integer default 0;
|
||||
create index blocks_mtime on blocks(mtime);
|
||||
|
18
tiledb/accessor.go
Normal file
18
tiledb/accessor.go
Normal file
@ -0,0 +1,18 @@
|
||||
package tiledb
|
||||
|
||||
import (
|
||||
"mapserver/coords"
|
||||
)
|
||||
|
||||
type Tile struct {
|
||||
Pos coords.TileCoords
|
||||
LayerId int
|
||||
Data []byte
|
||||
Mtime int64
|
||||
}
|
||||
|
||||
type DBAccessor interface {
|
||||
Migrate() error
|
||||
GetTile(pos coords.TileCoords) (*Tile, error)
|
||||
SetTile(pos coords.TileCoords, tile *Tile) error
|
||||
}
|
10
tilerenderer/logger.go
Normal file
10
tilerenderer/logger.go
Normal file
@ -0,0 +1,10 @@
|
||||
package tilerenderer
|
||||
|
||||
import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var log *logrus.Entry
|
||||
func init(){
|
||||
log = logrus.WithFields(logrus.Fields{"prefix": "tilerenderer"})
|
||||
}
|
25
tilerenderer/renderer.go
Normal file
25
tilerenderer/renderer.go
Normal file
@ -0,0 +1,25 @@
|
||||
package tilerenderer
|
||||
|
||||
import (
|
||||
"mapserver/coords"
|
||||
"mapserver/mapblockrenderer"
|
||||
"mapserver/tiledb"
|
||||
"image"
|
||||
)
|
||||
|
||||
type TileRenderer struct {
|
||||
mapblockrenderer *mapblockrenderer.MapBlockRenderer
|
||||
tiledb *tiledb.DBAccessor
|
||||
}
|
||||
|
||||
func NewTileRenderer(mapblockrenderer *mapblockrenderer.MapBlockRenderer, tiledb *tiledb.DBAccessor) *TileRenderer {
|
||||
return &TileRenderer{
|
||||
mapblockrenderer: mapblockrenderer,
|
||||
tiledb: tiledb,
|
||||
}
|
||||
}
|
||||
|
||||
//TODO layerConfig
|
||||
func (tr *TileRenderer) Render(tc coords.TileCoords, layerId int) (*image.NRGBA, error) {
|
||||
return nil, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user