1
0
forked from MTSR/mapserver
mapserver/server/mapobjectdb/sqlite/tiles.go

54 lines
954 B
Go
Raw Normal View History

2019-02-05 15:25:01 +03:00
package sqlite
2019-01-14 14:38:26 +03:00
import (
2019-01-16 18:36:28 +03:00
"mapserver/coords"
2019-02-05 15:25:01 +03:00
"mapserver/mapobjectdb"
2019-01-14 14:38:26 +03:00
)
2019-01-14 14:48:46 +03:00
2019-02-05 15:25:01 +03:00
func (db *Sqlite3Accessor) GetTile(pos *coords.TileCoords) (*mapobjectdb.Tile, error) {
2019-01-17 10:53:07 +03:00
rows, err := db.db.Query(getTileQuery, pos.LayerId, pos.X, pos.Y, pos.Zoom)
2019-01-16 18:36:28 +03:00
if err != nil {
return nil, err
}
2019-01-17 10:01:48 +03:00
defer rows.Close()
2019-01-16 18:36:28 +03:00
if rows.Next() {
var data []byte
var mtime int64
err = rows.Scan(&data, &mtime)
if err != nil {
return nil, err
}
if data == nil {
return nil, nil
}
2019-02-05 15:25:01 +03:00
mb := mapobjectdb.Tile{
2019-01-18 11:13:37 +03:00
Pos: pos,
Data: data,
Mtime: mtime,
2019-01-16 18:36:28 +03:00
}
return &mb, nil
}
return nil, nil
2019-01-14 14:38:26 +03:00
}
2019-01-16 18:36:28 +03:00
2019-02-05 15:25:01 +03:00
func (db *Sqlite3Accessor) SetTile(tile *mapobjectdb.Tile) error {
2019-01-17 18:32:36 +03:00
_, err := db.db.Exec(setTileQuery, tile.Pos.X, tile.Pos.Y, tile.Pos.Zoom, tile.Pos.LayerId, tile.Data, tile.Mtime)
return err
2019-01-14 14:38:26 +03:00
}
2019-02-05 15:25:01 +03:00
2019-01-17 13:20:03 +03:00
2019-01-21 15:27:36 +03:00
func (db *Sqlite3Accessor) RemoveTile(pos *coords.TileCoords) error {
2019-01-17 13:20:03 +03:00
_, err := db.db.Exec(removeTileQuery, pos.X, pos.Y, pos.Zoom, pos.LayerId)
return err
}