From bd592e005600fa8b321cce3cd317baf0f6e3ce88 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 30 May 2011 08:13:28 +0200 Subject: [PATCH] simplify area query, fix async listmap demo --- demos/listmap2/js/listmap.js | 91 ++++++++++++++++++++--------------- source/Ox.UI/js/Map/Ox.Map.js | 12 ++--- 2 files changed, 54 insertions(+), 49 deletions(-) diff --git a/demos/listmap2/js/listmap.js b/demos/listmap2/js/listmap.js index bc493ff1..a3238170 100644 --- a/demos/listmap2/js/listmap.js +++ b/demos/listmap2/js/listmap.js @@ -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) { diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js index ffa9c966..754ad3ed 100644 --- a/source/Ox.UI/js/Map/Ox.Map.js +++ b/source/Ox.UI/js/Map/Ox.Map.js @@ -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: ''