forked from MTSR/mapserver
partial working search
This commit is contained in:
parent
950bf53c88
commit
dfcb4241f3
@ -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){
|
||||
this.listeners.push(listener);
|
||||
|
@ -18,7 +18,7 @@ api.getConfig().then(function(cfg){
|
||||
var layers = {};
|
||||
var overlays = {};
|
||||
|
||||
var layerMgr = new LayerManager(cfg.layers, map);
|
||||
window.layerMgr = new LayerManager(cfg.layers, map);
|
||||
layerMgr.setLayerId( Hashroute.getLayerId() );
|
||||
|
||||
//All layers
|
||||
|
@ -18,15 +18,26 @@ var ShopEmptyIcon = L.icon({
|
||||
|
||||
var ShopOverlay = AbstractIconOverlay.extend({
|
||||
initialize: function(wsChannel, layerMgr) {
|
||||
AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "shop", ShopIcon);
|
||||
AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "shop");
|
||||
},
|
||||
|
||||
getMaxDisplayedZoom: function(){
|
||||
return 5;
|
||||
},
|
||||
|
||||
createPopup: function(poi){
|
||||
return "<h4>" + poi.attributes.type + "</h4><hr>" +
|
||||
"<b>Owner: </b> " + poi.attributes.owner + "<br>";
|
||||
getIcon: function(obj){
|
||||
if (obj.attributes.stock > 0)
|
||||
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>";
|
||||
}
|
||||
});
|
||||
|
@ -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 = {
|
||||
view: function(){
|
||||
@ -18,7 +58,7 @@ var SearchMenu = {
|
||||
"Search",
|
||||
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))
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
var SearchStore = {
|
||||
query: "",
|
||||
result: [],
|
||||
|
||||
search: function(q){
|
||||
this.query = q;
|
||||
@ -9,7 +10,9 @@ var SearchStore = {
|
||||
},
|
||||
|
||||
fetchData: debounce(function(){
|
||||
console.log(this.query);
|
||||
var self = this;
|
||||
this.result = [];
|
||||
|
||||
if (!this.query){
|
||||
return;
|
||||
}
|
||||
@ -17,15 +20,21 @@ var SearchStore = {
|
||||
api.getMapObjects({
|
||||
pos1: { 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){
|
||||
console.log(result);
|
||||
self.result = result;
|
||||
console.log(result); //XXX
|
||||
});
|
||||
|
||||
}, 400),
|
||||
|
||||
clear: function(){
|
||||
this.query = "";
|
||||
this.result = [];
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user