diff --git a/coords/tileconvert.go b/coords/tileconvert.go new file mode 100644 index 0000000..6f9c03c --- /dev/null +++ b/coords/tileconvert.go @@ -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}; +} diff --git a/coords/tilecoords.go b/coords/tilecoords.go new file mode 100644 index 0000000..92e77d9 --- /dev/null +++ b/coords/tilecoords.go @@ -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, + } +} diff --git a/db/logger.go b/db/logger.go new file mode 100644 index 0000000..9bf66ce --- /dev/null +++ b/db/logger.go @@ -0,0 +1,10 @@ +package db + +import ( + "github.com/sirupsen/logrus" +) + +var log *logrus.Entry +func init(){ + log = logrus.WithFields(logrus.Fields{"prefix": "db"}) +} diff --git a/db/sqlite.go b/db/sqlite.go index 8474ba1..9f731b6 100644 --- a/db/sqlite.go +++ b/db/sqlite.go @@ -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); diff --git a/tiledb/accessor.go b/tiledb/accessor.go new file mode 100644 index 0000000..72dd08d --- /dev/null +++ b/tiledb/accessor.go @@ -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 +} diff --git a/tilerenderer/logger.go b/tilerenderer/logger.go new file mode 100644 index 0000000..3570e0a --- /dev/null +++ b/tilerenderer/logger.go @@ -0,0 +1,10 @@ +package tilerenderer + +import ( + "github.com/sirupsen/logrus" +) + +var log *logrus.Entry +func init(){ + log = logrus.WithFields(logrus.Fields{"prefix": "tilerenderer"}) +} diff --git a/tilerenderer/renderer.go b/tilerenderer/renderer.go new file mode 100644 index 0000000..a976649 --- /dev/null +++ b/tilerenderer/renderer.go @@ -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 +}