psql wip
This commit is contained in:
parent
a3bc7fd0eb
commit
017cf3abc8
@ -29,7 +29,7 @@ func GetTileCoordsFromMapBlock(mbc *MapBlockCoords, layers []*layer.Layer) *Tile
|
|||||||
return &tc
|
return &tc
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetMapBlockRangeFromTile(tc *TileCoords, y int) MapBlockRange {
|
func GetMapBlockRangeFromTile(tc *TileCoords, y int) *MapBlockRange {
|
||||||
scaleDiff := float64(MAX_ZOOM - tc.Zoom)
|
scaleDiff := float64(MAX_ZOOM - tc.Zoom)
|
||||||
scale := int(math.Pow(2, scaleDiff))
|
scale := int(math.Pow(2, scaleDiff))
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ func GetMapBlockRangeFromTile(tc *TileCoords, y int) MapBlockRange {
|
|||||||
mapBlockX2 := mapBlockX1 + scale - 1
|
mapBlockX2 := mapBlockX1 + scale - 1
|
||||||
mapBlockZ2 := (mapBlockZ1 + ((scale - 1) * -1))
|
mapBlockZ2 := (mapBlockZ1 + ((scale - 1) * -1))
|
||||||
|
|
||||||
return MapBlockRange{
|
return &MapBlockRange{
|
||||||
Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1),
|
Pos1: NewMapBlockCoords(mapBlockX1, y, mapBlockZ1),
|
||||||
Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2),
|
Pos2: NewMapBlockCoords(mapBlockX2, y, mapBlockZ2),
|
||||||
}
|
}
|
||||||
|
@ -3,23 +3,96 @@ package postgres
|
|||||||
import (
|
import (
|
||||||
"mapserver/db"
|
"mapserver/db"
|
||||||
"mapserver/layer"
|
"mapserver/layer"
|
||||||
|
"mapserver/coords"
|
||||||
"mapserver/settings"
|
"mapserver/settings"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SETTING_LAST_LAYER = "last_layer"
|
SETTING_LAST_LAYER = "last_layer"
|
||||||
|
SETTING_LAST_X_BLOCK = "last_x_block"
|
||||||
|
SETTING_LAST_Y_BLOCK = "last_y_block"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
// x -> 0 ... 256
|
||||||
|
|
||||||
|
//zoom/mapblock-width
|
||||||
|
//13 1
|
||||||
|
//12 2
|
||||||
|
//11 4
|
||||||
|
//10 8
|
||||||
|
//9 16
|
||||||
|
|
||||||
|
//Zoom 9:
|
||||||
|
//10 mapblocks height * 16 * 16 == 2560
|
||||||
|
|
||||||
|
|
||||||
func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
|
func (this *PostgresAccessor) FindNextInitialBlocks(s settings.Settings, layers []*layer.Layer, limit int) (*db.InitialBlocksResult, error) {
|
||||||
|
|
||||||
//zoom/mapblock-width
|
lastlayer := s.GetInt(SETTING_LAST_LAYER, 0)
|
||||||
//13 1
|
lastxblock := s.GetInt(SETTING_LAST_X_BLOCK, -128)
|
||||||
//12 2
|
lastyblock := s.GetInt(SETTING_LAST_Y_BLOCK, -128)
|
||||||
//11 4
|
|
||||||
//10 8
|
|
||||||
//9 16
|
|
||||||
|
|
||||||
//Zoom 9:
|
if lastxblock >= 128 {
|
||||||
//10 mapblocks height * 16 * 16 == 2560
|
lastxblock = -128
|
||||||
return nil, nil
|
lastyblock++
|
||||||
|
|
||||||
|
} else {
|
||||||
|
lastxblock++
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if lastyblock > 128 {
|
||||||
|
//done
|
||||||
|
//TODO: next layer
|
||||||
|
|
||||||
|
result := &db.InitialBlocksResult{}
|
||||||
|
result.HasMore = false
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
tc := coords.NewTileCoords(lastxblock, lastyblock, 9, lastlayer)
|
||||||
|
currentlayer := layer.FindLayerById(layers, lastlayer)
|
||||||
|
|
||||||
|
tcr := coords.GetMapBlockRangeFromTile(tc, currentlayer.From)
|
||||||
|
|
||||||
|
fields := logrus.Fields{
|
||||||
|
"layerId": lastlayer,
|
||||||
|
"pos1": tcr.Pos1,
|
||||||
|
"pos2": tcr.Pos2,
|
||||||
|
}
|
||||||
|
log.WithFields(fields).Info("Initial-Query")
|
||||||
|
|
||||||
|
rows, err := this.db.Query(getBlocksByInitialTileQuery,
|
||||||
|
tcr.Pos1.X, tcr.Pos1.X, tcr.Pos1.X,
|
||||||
|
tcr.Pos2.X, tcr.Pos2.X, tcr.Pos2.X,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer rows.Close()
|
||||||
|
blocks := make([]*db.Block, 0)
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var posx, posy, posz int
|
||||||
|
var data []byte
|
||||||
|
var mtime int64
|
||||||
|
|
||||||
|
err = rows.Scan(&posx, &posy, &posz, &data, &mtime)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
mb := convertRows(posx, posy, posz, data, mtime)
|
||||||
|
blocks = append(blocks, mb)
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &db.InitialBlocksResult{}
|
||||||
|
result.List = blocks
|
||||||
|
result.HasMore = true
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,17 @@
|
|||||||
package postgres
|
package postgres
|
||||||
|
|
||||||
|
const getBlocksByInitialTileQuery = `
|
||||||
|
select posx,posy,posz,data,mtime
|
||||||
|
from blocks b
|
||||||
|
where b.mtime = 0
|
||||||
|
and b.posx >= ?
|
||||||
|
and b.posy >= ?
|
||||||
|
and b.posz >= ?
|
||||||
|
and b.posx <= ?
|
||||||
|
and b.posy <= ?
|
||||||
|
and b.posz <= ?
|
||||||
|
`
|
||||||
|
|
||||||
const getBlocksByMtimeQuery = `
|
const getBlocksByMtimeQuery = `
|
||||||
select posx,posy,posz,data,mtime
|
select posx,posy,posz,data,mtime
|
||||||
from blocks b
|
from blocks b
|
||||||
|
Loading…
Reference in New Issue
Block a user