Skip to content
Snippets Groups Projects
Commit 8bc4620e authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[enh] Map WoT: get data using slice request (usefull if more than 1000 profiles)

[enh] Geo api: simplify code
parent 7f208c19
Branches
Tags
No related merge requests found
...@@ -18,8 +18,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser ...@@ -18,8 +18,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
that.raw = { that.raw = {
osm: { osm: {
searchByString: csHttp.get('nominatim.openstreetmap.org', 443, '/search.php?format=json&q=:query'), search: csHttp.get('nominatim.openstreetmap.org', 443, '/search.php?format=json')
searchByQuery: csHttp.get('nominatim.openstreetmap.org', 443, '/search.php?format=json')
}, },
google: { google: {
apiKey: undefined, apiKey: undefined,
...@@ -56,31 +55,16 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser ...@@ -56,31 +55,16 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
}); });
} }
function searchPositionByString(address) { function searchPositionByAddress(query) {
var now = new Date(); if (typeof query == 'string') {
console.debug('[ES] [geo] Searching position by string query [{0}]...'.format(address)); query = {q: query};
return that.raw.osm.searchByString({query: address})
.then(function(res) {
console.debug('[ES] [geo] Found {0} address position(s) in {0}ms'.format(res && res.length || 0, new Date().getTime() - now.getTime()));
return res;
})
// Fallback service
.catch(function(err) {
return _fallbackSearchPositionByString(err, address);
});
} }
function searchhPositionByQuery(query) {
if (typeof query == 'string') return searchPositionByString(query);
var now = new Date(); var now = new Date();
console.debug('[ES] [geo] Searching position by query...', query); //console.debug('[ES] [geo] Searching position...', query);
return that.raw.osm.searchByQuery(query) return that.raw.osm.search(query)
.then(function(res) { .then(function(res) {
console.debug('[ES] [geo] Found {0} address position(s) in {0}ms'.format(res && res.length || 0, new Date().getTime() - now.getTime()), res); console.debug('[ES] [geo] Found {0} address position(s) in {0}ms'.format(res && res.length || 0, new Date().getTime() - now.getTime()), res);
return res; return res;
...@@ -88,7 +72,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser ...@@ -88,7 +72,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
// Fallback service // Fallback service
.catch(function(err) { .catch(function(err) {
var address = (query.street ? query.street +', ' : '') + query.city + (query.country ? ', '+ query.country : ''); var address = query.q ? query.q : ((query.street ? query.street +', ' : '') + query.city + (query.country ? ', '+ query.country : ''));
return _fallbackSearchPositionByString(err, address); return _fallbackSearchPositionByString(err, address);
}); });
} }
...@@ -147,7 +131,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser ...@@ -147,7 +131,7 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
return { return {
point: { point: {
current: getCurrentPosition, current: getCurrentPosition,
searchByAddress: searchhPositionByQuery, searchByAddress: searchPositionByAddress,
searchByIP: searchPositionByIP searchByIP: searchPositionByIP
}, },
google: { google: {
......
...@@ -163,8 +163,14 @@ angular.module('cesium.map.wot.controllers', ['cesium.services', 'cesium.map.ser ...@@ -163,8 +163,14 @@ angular.module('cesium.map.wot.controllers', ['cesium.services', 'cesium.map.ser
// Show loading indicator // Show loading indicator
map.fire('dataloading'); map.fire('dataloading');
var options = {
fields: {
description: !UIUtils.screen.isSmall()
}
};
// Load wot data // Load wot data
return mapWot.load() return mapWot.load(options)
.then(function(res) { .then(function(res) {
var markers = {}; var markers = {};
......
...@@ -10,7 +10,7 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -10,7 +10,7 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
DEFAULT_LOAD_SIZE: 1000 DEFAULT_LOAD_SIZE: 1000
}, },
fields = { fields = {
profile: ["title", "geoPoint", "avatar._content_type", "address", "city", "description"] profile: ["title", "geoPoint", "avatar._content_type", "address", "city"]
}; };
that.raw = { that.raw = {
...@@ -64,11 +64,14 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -64,11 +64,14 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
options.size = options.size || constants.DEFAULT_LOAD_SIZE; options.size = options.size || constants.DEFAULT_LOAD_SIZE;
options.searchAddress = esGeo.google.isEnable() && (angular.isDefined(options.searchAddress) ? options.searchAddress : true); options.searchAddress = esGeo.google.isEnable() && (angular.isDefined(options.searchAddress) ? options.searchAddress : true);
options.fields = options.fields || {};
options.fields.description = angular.isDefined(options.fields.description) ? options.fields.description : true;
var request = { var request = {
query: createFilterQuery(options), query: createFilterQuery(options),
from: options.from, from: 0,
size: options.size, size: options.size,
_source: fields.profile _source: options.fields.description ? fields.profile.concat("description") : fields.profile
}; };
return $q.all([ return $q.all([
...@@ -104,6 +107,30 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -104,6 +107,30 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
return res; return res;
}, {}); }, {});
var jobs = [
processLoadHits(options, uids, memberships, res)
];
// Additional slice requests
request.from += request.size;
while (request.from < res.hits.total) {
jobs.push(that.raw.profile.postSearch(angular.copy(request))
.then(function(res) {
if (!res.hits || !res.hits.hits.length) return [];
return processLoadHits(options, uids, memberships, res);
}));
request.from += request.size;
}
return $q.all(jobs)
.then(function(res){
return res.reduce(function(res, items) {
return res.concat(items);
}, []);
});
});
}
function processLoadHits(options, uids, memberships, res) {
// Transform profile hits // Transform profile hits
var commaRegexp = new RegExp('[,]'); var commaRegexp = new RegExp('[,]');
...@@ -117,6 +144,7 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -117,6 +144,7 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
// City & address // City & address
item.city = hit._source.city; item.city = hit._source.city;
item.address = hit._source.address;
// Set geo point // Set geo point
item.geoPoint = hit._source.geoPoint; item.geoPoint = hit._source.geoPoint;
...@@ -146,7 +174,7 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -146,7 +174,7 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
} }
// Description // Description
item.description = esHttp.util.trustAsHtml(hit._source.description); item.description = hit._source.description && esHttp.util.trustAsHtml(hit._source.description);
return item.geoPoint ? res.concat(item) : res; return item.geoPoint ? res.concat(item) : res;
}, []); }, []);
...@@ -158,7 +186,7 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -158,7 +186,7 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
var counter = 0; var counter = 0;
return $q.all(searchAddressItems.reduce(function(res, item) { return $q.all(searchAddressItems.reduce(function(res, item) {
return !item.searchAddress ? res : res.concat(esGeo.google.searchByAddress(item.searchAddress) return !item.city ? res : res.concat(esGeo.google.searchByAddress(item.searchAddress)
.then(function(res) { .then(function(res) {
if (!res || !res.length) return; if (!res || !res.length) return;
item.geoPoint = res[0]; item.geoPoint = res[0];
...@@ -179,11 +207,9 @@ angular.module('cesium.map.wot.services', ['cesium.services']) ...@@ -179,11 +207,9 @@ angular.module('cesium.map.wot.services', ['cesium.services'])
}); });
} }
return items; return $q.when(items);
});
} }
return { return {
load: load load: load
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment