1
0
forked from MTSR/mapserver
mapserver/server/static/js/search/SearchService.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-04-15 08:54:11 +03:00
/* exported SearchService */
/* globals SearchStore: true */
var SearchService = {
2019-04-21 22:51:43 +03:00
search: function(){
SearchStore.show = true;
2019-04-15 08:54:11 +03:00
this.fetchData();
},
2019-04-21 22:51:43 +03:00
fetchData: function(){
2019-04-15 08:54:11 +03:00
SearchStore.result = [];
if (!SearchStore.query){
return;
}
2019-04-21 22:51:43 +03:00
SearchStore.busy = true;
function searchFor(type, key, valuelike){
return api.getMapObjects({
pos1: { x:-2048, y:-2048, z:-2048 },
pos2: { x:2048, y:2048, z:2048 },
type: type,
attributelike: {
key: key,
value: "%" + valuelike +"%"
}
});
2019-04-20 18:59:22 +03:00
}
2019-05-14 09:31:35 +03:00
var prom_list = [
searchFor("shop", "out_item", SearchStore.query),
searchFor("poi", "name", SearchStore.query),
searchFor("train", "station", SearchStore.query),
searchFor("travelnet", "station_name", SearchStore.query),
2019-05-14 10:15:11 +03:00
searchFor("bones", "owner", SearchStore.query),
searchFor("locator", "name", SearchStore.query)
2019-05-14 09:31:35 +03:00
];
2019-04-20 18:59:22 +03:00
2019-04-21 22:51:43 +03:00
Promise.all(prom_list)
.then(function(results){
var arr = [];
results.forEach(function(r) {
arr = arr.concat(r);
});
SearchStore.result = arr;
SearchStore.busy = false;
2019-04-15 08:54:11 +03:00
});
2019-04-21 22:51:43 +03:00
},
2019-04-15 08:54:11 +03:00
clear: function(){
SearchStore.result = [];
2019-04-21 22:51:43 +03:00
SearchStore.show = false;
2019-04-15 08:54:11 +03:00
}
};