shop/poi search

This commit is contained in:
Thomas Rudin 2019-04-20 17:59:22 +02:00
parent 36e3a53e6a
commit 4e95a9490e
6 changed files with 77 additions and 22 deletions

View File

@ -165,7 +165,7 @@ func ParseConfig(filename string) (*Config, error) {
Port: 8080, Port: 8080,
EnableRendering: true, EnableRendering: true,
EnablePrometheus: true, EnablePrometheus: true,
EnableSearch: false, EnableSearch: true,
EnableInitialRendering: true, EnableInitialRendering: true,
EnableTransparency: false, EnableTransparency: false,
Webdev: false, Webdev: false,

View File

@ -7,11 +7,14 @@ var SearchControl = L.Control.extend({
L.Control.prototype.initialize.call(this, opts); L.Control.prototype.initialize.call(this, opts);
}, },
onAdd: function() { onAdd: function(map) {
var div = L.DomUtil.create('div'); var div = L.DomUtil.create('div');
m.mount(div, SearchInput); m.mount(div, SearchInput);
m.mount(document.getElementById("search-content"), SearchMenu); m.mount(document.getElementById("search-content"), {
view: function () {
return m(SearchMenu, {map: map});
}
});
return div; return div;
} }

View File

@ -22,7 +22,7 @@ var ShopOverlay = AbstractIconOverlay.extend({
}, },
getMaxDisplayedZoom: function(){ getMaxDisplayedZoom: function(){
return 5; return 10;
}, },
getIcon: function(obj){ getIcon: function(obj){

View File

@ -4,7 +4,8 @@
/* globals SearchStore: true */ /* globals SearchStore: true */
var SearchMenu = { var SearchMenu = {
view: function(){ view: function(vnode){
var style = {}; var style = {};
if (!SearchStore.query) { if (!SearchStore.query) {
@ -21,7 +22,7 @@ var SearchMenu = {
"Search", "Search",
m("i", { class: "fa fa-times float-right", onclick: close }), m("i", { class: "fa fa-times float-right", onclick: close }),
]), ]),
m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult)) m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult, { map: vnode.attrs.map }))
]); ]);
} }
}; };

View File

@ -3,7 +3,8 @@
/* globals layerMgr: true */ /* globals layerMgr: true */
var SearchResult = { var SearchResult = {
view: function(){ view: function(vnode){
var map = vnode.attrs.map;
function getLayer(obj){ function getLayer(obj){
var layer = layerMgr.getLayerByY(obj.y); var layer = layerMgr.getLayerByY(obj.y);
@ -12,30 +13,68 @@ var SearchResult = {
function getPos(obj){ function getPos(obj){
var layer = layerMgr.getLayerByY(obj.y); var layer = layerMgr.getLayerByY(obj.y);
var link = (layer ? layer.id : "0") + "/" + obj.x + "/" + obj.z + "/" + 12;
var text = obj.x + "/" + obj.y + "/" + obj.z; var text = obj.x + "/" + obj.y + "/" + obj.z;
return m("a", { href: "#" + link }, text); return m("span", {class:"badge badge-success"}, text);
} }
var rows = SearchStore.result.map(function(obj){ var rows = SearchStore.result.map(function(obj){
return m("tr", [
m("td", obj.type), var row_classes = "";
var description = obj.type;
var type = obj.type;
if (obj.type == "poi"){
description = m("span", obj.attributes.name);
type = m("img", { src: "css/images/marker-icon.png" });
}
if (obj.type == "shop") {
if (obj.attributes.stock == 0){
row_classes += "table-warning";
type = m("img", { src: "pics/shop_empty.png" });
} else {
type = m("img", { src: "pics/shop.png" });
}
description = m("span", [
"Shop, trading ",
m("span", {class:"badge badge-primary"}, obj.attributes.out_count + "x"),
m("span", {class:"badge badge-info"}, obj.attributes.out_item),
" for ",
m("span", {class:"badge badge-primary"}, obj.attributes.in_count + "x"),
m("span", {class:"badge badge-info"}, obj.attributes.in_item),
" Stock: ",
m("span", {class:"badge badge-info"}, obj.attributes.stock)
]);
}
function onclick(){
map.setView([obj.z, obj.x], 12);
}
return m("tr", {"class": row_classes}, [
m("td", type),
m("td", obj.attributes.owner), m("td", obj.attributes.owner),
m("td", getLayer(obj)), m("td", getLayer(obj)),
m("td", getPos(obj)), m("td", getPos(obj)),
m("td", "stuff") m("td", description),
m("button[type=button]", {class: "btn btn-secondary", onclick: onclick }, [
"Goto ",
m("i", { class: "fas fa-play" })
])
]); ]);
}); });
return m("table", {class:"table"}, [ return m("table", {class:"table table-striped"}, [
m("thead", [ m("thead", [
m("tr", [ m("tr", [
m("th", "Type"), m("th", "Type"),
m("th", "Owner"), m("th", "Owner"),
m("th", "Layer"), m("th", "Layer"),
m("th", "Position"), m("th", "Position"),
m("th", "Description") m("th", "Description"),
m("th", "Action")
]) ])
]), ]),
m("tbody", rows) m("tbody", rows)

View File

@ -16,18 +16,30 @@ var SearchService = {
return; return;
} }
api.getMapObjects({ function searchFor(q){
pos1: { x:-2048, y:-2048, z:-2048 }, q.pos1 = { x:-2048, y:-2048, z:-2048 };
pos2: { x:2048, y:2048, z:2048 }, q.pos2 = { x:2048, y:2048, z:2048 };
return api.getMapObjects(q);
}
var shop_prom = searchFor({
type: "shop", type: "shop",
attributelike: { attributelike: {
key: "out_item", key: "out_item",
value: "%" + SearchStore.query + "%" value: "%" + SearchStore.query + "%"
} }
}) });
.then(function(result){
SearchStore.result = result; var poi_prom = searchFor({
//console.log(result); //XXX type: "poi",
attributelike: {
key: "name",
value: "%" + SearchStore.query + "%"
}
});
Promise.all([shop_prom, poi_prom]).then(function(results){
SearchStore.result = results[1].concat(results[0]);
}); });
}, 400), }, 400),