simplify area query, fix async listmap demo
This commit is contained in:
parent
b9ab4a0adf
commit
bd592e0056
2 changed files with 54 additions and 49 deletions
|
@ -96,47 +96,58 @@ Ox.load('Geo', function() {
|
|||
} else {
|
||||
data.items = places;
|
||||
if (options.query) {
|
||||
// only case is key: 'id', value: ..., operator: '^$'
|
||||
data.items = data.items.filter(function(place) {
|
||||
return place[options.query.key] == options.query.value;
|
||||
});
|
||||
}
|
||||
if (options.area) {
|
||||
data.items = data.items.filter(function(place) {
|
||||
// fixme: fails if crosses dateline
|
||||
return place.lat > options.area.south
|
||||
&& place.lat < options.area.north
|
||||
&& place.lng > options.area.west
|
||||
&& place.lng < options.area.east;
|
||||
}).sort(function(a, b) {
|
||||
return b.area - a.area;
|
||||
}).filter(function(place, i) {
|
||||
return i < 100;
|
||||
});
|
||||
} else {
|
||||
data.items.sort(function(a, b) {
|
||||
if (options.sort[0].key == 'geoname') {
|
||||
aValue = a.geonameSort;
|
||||
bValue = b.geonameSort;
|
||||
} else {
|
||||
aValue = a[options.sort[0].key];
|
||||
bValue = b[options.sort[0].key];
|
||||
}
|
||||
var ret = 0;
|
||||
if (
|
||||
(options.sort[0].operator == '+' && aValue < bValue)
|
||||
|| (options.sort[0].operator == '-' && aValue > bValue)
|
||||
) {
|
||||
ret = -1;
|
||||
} else if (
|
||||
(options.sort[0].operator == '+' && aValue > bValue)
|
||||
|| (options.sort[0].operator == '-' && aValue < bValue)
|
||||
) {
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
if (options.query.conditions[0].key == 'id') {
|
||||
data.items = data.items.filter(function(place) {
|
||||
return place.id == options.query.conditions[0].value;
|
||||
});
|
||||
} else {
|
||||
Ox.print('query', options)
|
||||
data.items = data.items.filter(function(place) {
|
||||
var ret = true;
|
||||
options.query.conditions.forEach(function(condition) {
|
||||
if (condition.operator == '-') {
|
||||
if (
|
||||
place[condition.key] < condition.value[0]
|
||||
|| place[condition.key] > condition.value[1]
|
||||
) {
|
||||
ret = false;
|
||||
}
|
||||
} else { // '!-'
|
||||
if (
|
||||
place[condition.key] > condition.value[0]
|
||||
&& place[condition.key] < condition.value[1]
|
||||
) {
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
return ret;
|
||||
});
|
||||
}
|
||||
}
|
||||
data.items.sort(function(a, b) {
|
||||
if (options.sort[0].key == 'geoname') {
|
||||
aValue = a.geonameSort;
|
||||
bValue = b.geonameSort;
|
||||
} else {
|
||||
aValue = a[options.sort[0].key];
|
||||
bValue = b[options.sort[0].key];
|
||||
}
|
||||
var ret = 0;
|
||||
if (
|
||||
(options.sort[0].operator == '+' && aValue < bValue)
|
||||
|| (options.sort[0].operator == '-' && aValue > bValue)
|
||||
) {
|
||||
ret = -1;
|
||||
} else if (
|
||||
(options.sort[0].operator == '+' && aValue > bValue)
|
||||
|| (options.sort[0].operator == '-' && aValue < bValue)
|
||||
) {
|
||||
ret = 1;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
if (options.ids) {
|
||||
data.positions = {};
|
||||
data.items.forEach(function(place, i) {
|
||||
|
|
|
@ -773,18 +773,12 @@ Ox.Map = function(options, self) {
|
|||
], !crossesDateline ? [
|
||||
{key: 'lng', value: [west, east], operator: '-'}
|
||||
] : [
|
||||
{
|
||||
conditions: [
|
||||
{key: 'lng', value: west, operator: '<'},
|
||||
{key: 'lng', value: east, operator: '>'}
|
||||
],
|
||||
operator: '|'
|
||||
}
|
||||
{key: 'lng', value: [east, west], operator: '!-'}
|
||||
]),
|
||||
operator: '&'
|
||||
},
|
||||
range: [0, self.options.maxMarkers],
|
||||
sort: [{key: 'area', operator: '+'}]
|
||||
sort: [{key: 'area', operator: '-'}]
|
||||
}, function(result) {
|
||||
var ids = [];
|
||||
result.data.items.forEach(function(item, i) {
|
||||
|
@ -958,7 +952,7 @@ Ox.Map = function(options, self) {
|
|||
self.options.places({
|
||||
query: {
|
||||
conditions: [
|
||||
{key: 'id', value: id, operator: '^$'}
|
||||
{key: 'id', value: id, operator: '='}
|
||||
],
|
||||
operator: ''
|
||||
|
||||
|
|
Loading…
Reference in a new issue