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

52 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-04-15 08:54:11 +03:00
/* exported SearchService */
/* globals SearchStore: true */
var SearchService = {
search: function(q){
SearchStore.query = q;
this.fetchData();
},
fetchData: debounce(function(){
SearchStore.result = [];
if (!SearchStore.query){
return;
}
2019-04-20 18:59:22 +03:00
function searchFor(q){
q.pos1 = { x:-2048, y:-2048, z:-2048 };
q.pos2 = { x:2048, y:2048, z:2048 };
return api.getMapObjects(q);
}
var shop_prom = searchFor({
2019-04-15 08:54:11 +03:00
type: "shop",
attributelike: {
key: "out_item",
value: "%" + SearchStore.query + "%"
}
2019-04-20 18:59:22 +03:00
});
var poi_prom = searchFor({
type: "poi",
attributelike: {
key: "name",
value: "%" + SearchStore.query + "%"
}
});
Promise.all([shop_prom, poi_prom]).then(function(results){
SearchStore.result = results[1].concat(results[0]);
2019-04-15 08:54:11 +03:00
});
}, 400),
clear: function(){
SearchStore.query = "";
SearchStore.result = [];
}
};