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 {
|
} else {
|
||||||
data.items = places;
|
data.items = places;
|
||||||
if (options.query) {
|
if (options.query) {
|
||||||
// only case is key: 'id', value: ..., operator: '^$'
|
if (options.query.conditions[0].key == 'id') {
|
||||||
data.items = data.items.filter(function(place) {
|
data.items = data.items.filter(function(place) {
|
||||||
return place[options.query.key] == options.query.value;
|
return place.id == options.query.conditions[0].value;
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
if (options.area) {
|
Ox.print('query', options)
|
||||||
data.items = data.items.filter(function(place) {
|
data.items = data.items.filter(function(place) {
|
||||||
// fixme: fails if crosses dateline
|
var ret = true;
|
||||||
return place.lat > options.area.south
|
options.query.conditions.forEach(function(condition) {
|
||||||
&& place.lat < options.area.north
|
if (condition.operator == '-') {
|
||||||
&& place.lng > options.area.west
|
if (
|
||||||
&& place.lng < options.area.east;
|
place[condition.key] < condition.value[0]
|
||||||
}).sort(function(a, b) {
|
|| place[condition.key] > condition.value[1]
|
||||||
return b.area - a.area;
|
) {
|
||||||
}).filter(function(place, i) {
|
ret = false;
|
||||||
return i < 100;
|
}
|
||||||
});
|
} else { // '!-'
|
||||||
} else {
|
if (
|
||||||
data.items.sort(function(a, b) {
|
place[condition.key] > condition.value[0]
|
||||||
if (options.sort[0].key == 'geoname') {
|
&& place[condition.key] < condition.value[1]
|
||||||
aValue = a.geonameSort;
|
) {
|
||||||
bValue = b.geonameSort;
|
ret = false;
|
||||||
} else {
|
}
|
||||||
aValue = a[options.sort[0].key];
|
}
|
||||||
bValue = b[options.sort[0].key];
|
return ret;
|
||||||
}
|
});
|
||||||
var ret = 0;
|
return ret;
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
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) {
|
if (options.ids) {
|
||||||
data.positions = {};
|
data.positions = {};
|
||||||
data.items.forEach(function(place, i) {
|
data.items.forEach(function(place, i) {
|
||||||
|
|
|
@ -773,18 +773,12 @@ Ox.Map = function(options, self) {
|
||||||
], !crossesDateline ? [
|
], !crossesDateline ? [
|
||||||
{key: 'lng', value: [west, east], operator: '-'}
|
{key: 'lng', value: [west, east], operator: '-'}
|
||||||
] : [
|
] : [
|
||||||
{
|
{key: 'lng', value: [east, west], operator: '!-'}
|
||||||
conditions: [
|
|
||||||
{key: 'lng', value: west, operator: '<'},
|
|
||||||
{key: 'lng', value: east, operator: '>'}
|
|
||||||
],
|
|
||||||
operator: '|'
|
|
||||||
}
|
|
||||||
]),
|
]),
|
||||||
operator: '&'
|
operator: '&'
|
||||||
},
|
},
|
||||||
range: [0, self.options.maxMarkers],
|
range: [0, self.options.maxMarkers],
|
||||||
sort: [{key: 'area', operator: '+'}]
|
sort: [{key: 'area', operator: '-'}]
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
var ids = [];
|
var ids = [];
|
||||||
result.data.items.forEach(function(item, i) {
|
result.data.items.forEach(function(item, i) {
|
||||||
|
@ -958,7 +952,7 @@ Ox.Map = function(options, self) {
|
||||||
self.options.places({
|
self.options.places({
|
||||||
query: {
|
query: {
|
||||||
conditions: [
|
conditions: [
|
||||||
{key: 'id', value: id, operator: '^$'}
|
{key: 'id', value: id, operator: '='}
|
||||||
],
|
],
|
||||||
operator: ''
|
operator: ''
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue