POST mapobject query

This commit is contained in:
NatureFreshMilk 2019-02-22 14:57:40 +01:00
parent 3b42ab9e16
commit cd54371361
4 changed files with 30 additions and 44 deletions

View File

@ -1,11 +1,11 @@
var api = {
getMapObjects: function(x1,y1,z1,x2,y2,z2,type){
return m.request("/api/mapobjects/" +
x1 + "/" + y1 + "/" + z1 + "/" +
x2 + "/" + y2 + "/" + z2 + "/" +
type
);
getMapObjects: function(query){
return m.request({
method: "POST",
url: "api/mapobjects",
data: query
});
},
getConfig: function(){

View File

@ -57,10 +57,11 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
var z1 = parseInt(min.lat);
var z2 = parseInt(max.lat);
api.getMapObjects(
x1, y1, z1,
x2, y2, z2,
this.type)
api.getMapObjects({
pos1: { x:x1, y:y1, z:z1 },
pos2: { x:x2, y:y2, z:z2 },
type: this.type
})
.then(function(objects){
self.clearLayers();

View File

@ -72,10 +72,11 @@ var AbstractIconOverlay = L.LayerGroup.extend({
var z1 = parseInt(min.lat);
var z2 = parseInt(max.lat);
api.getMapObjects(
x1, y1, z1,
x2, y2, z2,
this.type)
api.getMapObjects({
pos1: { x:x1, y:y1, z:z1 },
pos2: { x:x2, y:y2, z:z2 },
type: this.type
})
.then(function(objects){
//TODO: remove non-existing markers

View File

@ -4,11 +4,8 @@ import (
"encoding/json"
"github.com/prometheus/client_golang/prometheus"
"mapserver/app"
"mapserver/coords"
"mapserver/mapobjectdb"
"net/http"
"strconv"
"strings"
)
type MapObjects struct {
@ -16,40 +13,27 @@ type MapObjects struct {
}
func (t *MapObjects) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
str := strings.TrimPrefix(req.URL.Path, "/api/mapobjects/")
// x1/y1/z1/x2/y2/z2/type
parts := strings.Split(str, "/")
if len(parts) != 7 {
resp.WriteHeader(500)
resp.Write([]byte("wrong number of arguments"))
return
}
timer := prometheus.NewTimer(mapobjectServeDuration)
defer timer.ObserveDuration()
x1, _ := strconv.Atoi(parts[0])
y1, _ := strconv.Atoi(parts[1])
z1, _ := strconv.Atoi(parts[2])
x2, _ := strconv.Atoi(parts[3])
y2, _ := strconv.Atoi(parts[4])
z2, _ := strconv.Atoi(parts[5])
typeStr := parts[6]
q := mapobjectdb.SearchQuery{
Pos1: coords.NewMapBlockCoords(x1, y1, z1),
Pos2: coords.NewMapBlockCoords(x2, y2, z2),
Type: typeStr,
}
objects, err := t.ctx.Objectdb.GetMapData(q)
decoder := json.NewDecoder(req.Body)
var q mapobjectdb.SearchQuery
err := decoder.Decode(&q)
if err != nil {
resp.WriteHeader(500)
resp.Write([]byte(err.Error()))
} else {
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode(objects)
return
}
objects, err := t.ctx.Objectdb.GetMapData(q)
if err != nil {
resp.WriteHeader(500)
resp.Write([]byte(err.Error()))
return
}
resp.Header().Add("content-type", "application/json")
json.NewEncoder(resp).Encode(objects)
}