1
0
forked from MTSR/mapserver

partial working search

This commit is contained in:
Thomas Rudin 2019-04-14 21:35:59 +02:00
parent 950bf53c88
commit dfcb4241f3
5 changed files with 74 additions and 9 deletions

View File

@ -26,6 +26,11 @@ LayerManager.prototype.setLayerId = function(layerId){
}); });
}; };
LayerManager.prototype.getLayerByY = function(y){
return this.layers.find(function(layer){
return (y >= (layer.from*16) && y <= (layer.to*16));
});
};
LayerManager.prototype.addListener = function(listener){ LayerManager.prototype.addListener = function(listener){
this.listeners.push(listener); this.listeners.push(listener);

View File

@ -18,7 +18,7 @@ api.getConfig().then(function(cfg){
var layers = {}; var layers = {};
var overlays = {}; var overlays = {};
var layerMgr = new LayerManager(cfg.layers, map); window.layerMgr = new LayerManager(cfg.layers, map);
layerMgr.setLayerId( Hashroute.getLayerId() ); layerMgr.setLayerId( Hashroute.getLayerId() );
//All layers //All layers

View File

@ -18,15 +18,26 @@ var ShopEmptyIcon = L.icon({
var ShopOverlay = AbstractIconOverlay.extend({ var ShopOverlay = AbstractIconOverlay.extend({
initialize: function(wsChannel, layerMgr) { initialize: function(wsChannel, layerMgr) {
AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "shop", ShopIcon); AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "shop");
}, },
getMaxDisplayedZoom: function(){ getMaxDisplayedZoom: function(){
return 5; return 5;
}, },
createPopup: function(poi){ getIcon: function(obj){
return "<h4>" + poi.attributes.type + "</h4><hr>" + if (obj.attributes.stock > 0)
"<b>Owner: </b> " + poi.attributes.owner + "<br>"; return ShopIcon;
else
return ShopEmptyIcon;
},
createPopup: function(obj){
console.log(obj)
return "<h4>" + obj.attributes.type + "</h4><hr>" +
"<b>Owner: </b> " + obj.attributes.owner + "<br>" +
"<b>Input: </b> " + obj.attributes.in_count + " x " + obj.attributes.in_item + "<br>" +
"<b>Output: </b> " + obj.attributes.out_count + " x " + obj.attributes.out_item + "<br>" +
"<b>Stock: </b> " + obj.attributes.stock + "<br>";
} }
}); });

View File

@ -1,4 +1,44 @@
var SearchResult = {
view: function(vnode){
function getLayer(obj){
var layer = layerMgr.getLayerByY(obj.y);
return layer ? layer.name : "<unknown>";
}
function getPos(obj){
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;
return m("a", { href: "#" + link }, text);
}
var rows = SearchStore.result.map(function(obj){
return m("tr", [
m("td", obj.type),
m("td", obj.attributes.owner),
m("td", getLayer(obj)),
m("td", getPos(obj)),
m("td", "stuff")
]);
});
return m("table", {class:"table"}, [
m("thead", [
m("tr", [
m("th", "Type"),
m("th", "Owner"),
m("th", "Layer"),
m("th", "Position"),
m("th", "Description")
])
]),
m("tbody", rows)
]);
}
}
var SearchMenu = { var SearchMenu = {
view: function(){ view: function(){
@ -18,7 +58,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" }) m("div", { class: "card-body", style: {overflow: "auto"} }, m(SearchResult))
]); ]);
} }
} }

View File

@ -1,6 +1,7 @@
var SearchStore = { var SearchStore = {
query: "", query: "",
result: [],
search: function(q){ search: function(q){
this.query = q; this.query = q;
@ -9,7 +10,9 @@ var SearchStore = {
}, },
fetchData: debounce(function(){ fetchData: debounce(function(){
console.log(this.query); var self = this;
this.result = [];
if (!this.query){ if (!this.query){
return; return;
} }
@ -17,15 +20,21 @@ var SearchStore = {
api.getMapObjects({ api.getMapObjects({
pos1: { x:-2048, y:-2048, z:-2048 }, pos1: { x:-2048, y:-2048, z:-2048 },
pos2: { x:2048, y:2048, z:2048 }, pos2: { x:2048, y:2048, z:2048 },
type: "shop" type: "shop",
attributelike: {
key: "out_item",
value: "%" + this.query + "%"
}
}) })
.then(function(result){ .then(function(result){
console.log(result); self.result = result;
console.log(result); //XXX
}); });
}, 400), }, 400),
clear: function(){ clear: function(){
this.query = ""; this.query = "";
this.result = [];
} }
}; };