1
0
forked from MTSR/mapserver
mapserver/web/mapobjects.go

51 lines
987 B
Go
Raw Permalink Normal View History

2019-01-28 12:42:07 +03:00
package web
import (
2019-01-28 13:45:23 +03:00
"encoding/json"
2019-01-28 12:42:07 +03:00
"mapserver/mapobjectdb"
2023-12-29 18:00:11 +03:00
"mapserver/types"
2019-01-28 12:42:07 +03:00
"net/http"
2019-02-22 20:30:38 +03:00
"github.com/prometheus/client_golang/prometheus"
2019-01-28 12:42:07 +03:00
)
2021-04-12 14:55:00 +03:00
func (api *Api) QueryMapobjects(resp http.ResponseWriter, req *http.Request) {
2019-01-28 12:42:07 +03:00
2019-02-15 10:36:48 +03:00
timer := prometheus.NewTimer(mapobjectServeDuration)
defer timer.ObserveDuration()
2019-02-22 16:57:40 +03:00
decoder := json.NewDecoder(req.Body)
2019-02-22 20:30:38 +03:00
q := mapobjectdb.SearchQuery{}
2019-01-28 12:42:07 +03:00
2019-02-22 16:57:40 +03:00
err := decoder.Decode(&q)
2019-01-28 12:42:07 +03:00
if err != nil {
resp.WriteHeader(500)
resp.Write([]byte(err.Error()))
2019-02-22 16:57:40 +03:00
return
}
2019-01-28 12:42:07 +03:00
// apply defaults
limit := 1000
2022-01-17 11:45:32 +03:00
if q.Limit == nil {
q.Limit = &limit
}
if q.Pos1 == nil {
2023-12-29 18:00:11 +03:00
q.Pos1 = &types.MapBlockCoords{X: -2048, Y: -2048, Z: -2048}
}
if q.Pos2 == nil {
2023-12-29 18:00:11 +03:00
q.Pos2 = &types.MapBlockCoords{X: 2048, Y: 2048, Z: 2048}
}
2021-04-12 14:55:00 +03:00
objects, err := api.Context.Objectdb.GetMapData(&q)
2019-02-22 16:57:40 +03:00
if err != nil {
resp.WriteHeader(500)
resp.Write([]byte(err.Error()))
return
2019-01-28 12:42:07 +03:00
}
2019-02-22 16:57:40 +03:00
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode(objects)
2019-01-28 12:42:07 +03:00
}