make map in async listmap async

This commit is contained in:
rolux 2011-05-29 14:22:54 +02:00
parent 14174136d8
commit 93408b0b4d
4 changed files with 167 additions and 135 deletions

View file

@ -23,7 +23,7 @@ Ox.load('Geo', function() {
lngSize = area * Ox.getDegreesPerMeter(city.latitude); lngSize = area * Ox.getDegreesPerMeter(city.latitude);
return { return {
alternativeNames: [], alternativeNames: [],
area: city.population * 100, area: area,
countryCode: countryCode, countryCode: countryCode,
editable: true, editable: true,
flag: countryCode, flag: countryCode,
@ -71,7 +71,10 @@ 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: '='
data.items = data.items.filter(function(place) {
return place[options.query.key] == options.query.value;
});
} }
if (options.area) { if (options.area) {
data.items = data.items.filter(function(place) { data.items = data.items.filter(function(place) {
@ -80,8 +83,12 @@ Ox.load('Geo', function() {
&& place.lat < options.area.north && place.lat < options.area.north
&& place.lng > options.area.west && place.lng > options.area.west
&& place.lng < options.area.east; && 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) { data.items.sort(function(a, b) {
if (options.sort[0].key == 'geoname') { if (options.sort[0].key == 'geoname') {
aValue = a.geonameSort; aValue = a.geonameSort;
@ -104,6 +111,7 @@ Ox.load('Geo', function() {
} }
return ret; return ret;
}); });
}
if (options.ids) { if (options.ids) {
data.positions = {}; data.positions = {};
data.items.forEach(function(place, i) { data.items.forEach(function(place, i) {

View file

@ -281,7 +281,36 @@ Ox.ListMap = function(options, self) {
self.$status = Ox.Element() self.$status = Ox.Element()
.css({paddingTop: '2px', margin: 'auto', fontSize: '9px', textAlign: 'center'}) .css({paddingTop: '2px', margin: 'auto', fontSize: '9px', textAlign: 'center'})
.appendTo(self.$listStatusbar); .appendTo(self.$listStatusbar);
setStatus();
self.$map = Ox.Map({
clickable: true,
editable: true,
findPlaceholder: 'Find on Map',
height: self.options.height,
places: self.options.places,
//statusbar: true,
toolbar: true,
width: self.options.width - 514,//self.mapResize[1],
zoombar: true
})
.bindEvent({
addplace: function(event, data) {
that.triggerEvent('addplace', data);
},
changeplace: function(event, data) {
self.$placeForm.values(Ox.map(data, function(val, key) {
// fixme: no size key anymore
return key == 'size' ? Ox.formatArea(val) : val;
})).show();
},
geocode: function(event, data) {
that.triggerEvent('geocode', data);
},
resize: function() {
self.$map.resizeMap(); // fixme: don't need event
},
selectplace: selectPlace
});
self.$placeTitlebar = Ox.Bar({ self.$placeTitlebar = Ox.Bar({
size: 24 size: 24
@ -458,54 +487,15 @@ Ox.ListMap = function(options, self) {
*/ */
if (!self.isAsync) { if (!self.isAsync) {
init(self.options.places) self.placesLength = self.options.places.length;
setStatus();
} else { } else {
self.options.places({}, function(result) { self.options.places({}, function(result) {
Ox.print('$$$$', result.data.items) self.placesLength = result.data.items;
self.options.places({ setStatus();
keys: self.columns.map(function(column) {
return column.id
}),
range: [0, result.data.items],
sort: self.options.sort,
}, function(result) {
Ox.print('DATA', result)
init(result.data.items);
});
}); });
} }
function init(places) {
//Ox.print('PLACES', places)
self.$map = Ox.Map({
clickable: true,
editable: true,
findPlaceholder: 'Find on Map',
height: self.options.height,
places: places,
//statusbar: true,
toolbar: true,
width: self.options.width - 514,//self.mapResize[1],
zoombar: true
})
.bindEvent({
addplace: function(event, data) {
that.triggerEvent('addplace', data);
},
changeplace: function(event, data) {
self.$placeForm.values(Ox.map(data, function(val, key) {
// fixme: no size key anymore
return key == 'size' ? Ox.formatArea(val) : val;
})).show();
},
geocode: function(event, data) {
that.triggerEvent('geocode', data);
},
resize: function() {
self.$map.resizeMap(); // fixme: don't need event
},
selectplace: selectPlace
});
that.$element.replaceWith( that.$element.replaceWith(
that.$element = Ox.SplitPanel({ that.$element = Ox.SplitPanel({
elements: [ elements: [
@ -568,7 +558,6 @@ Ox.ListMap = function(options, self) {
orientation: 'horizontal' orientation: 'horizontal'
}).$element }).$element
); );
}
function initList(event, data) { function initList(event, data) {
self.$status.html(data.items + ' place' + (data.items == 1 ? '' : 's')) self.$status.html(data.items + ' place' + (data.items == 1 ? '' : 's'))
@ -621,8 +610,8 @@ Ox.ListMap = function(options, self) {
function setStatus() { function setStatus() {
self.$status.html( self.$status.html(
self.options.places.length + ' Place' + ( self.options.placesLength + ' Place' + (
self.options.places.length == 1 ? '' : 's' self.options.placesLength == 1 ? '' : 's'
) )
); );
} }

View file

@ -922,14 +922,37 @@ Ox.Map = function(options, self) {
} }
function selectPlace(id) { function selectPlace(id) {
// id can be null (deselect)
var place, var place,
selected = getSelectedMarker(); selected = getSelectedMarker();
//Ox.print('Ox.Map selectPlace()', id, selected); Ox.print('Ox.Map selectPlace()', id, selected);
if (id != selected) { if (id != selected) {
place = getPlaceById(selected); place = getPlaceById(selected);
place && place.deselect(); place && place.deselect();
if (id !== null) {
place = getPlaceById(id); place = getPlaceById(id);
place && place.select(); if (place) {
select();
} else {
// async && place doesn't exist yet
self.options.places({
query: {
key: 'id',
value: id,
operator: '='
}
}, function(results) {
place = new Ox.MapPlace(Ox.extend({
map: that
}, results.data.items[0])).add();
self.places.push(place);
select();
});
}
}
}
function select() {
place.select();
self.options.selected = id; self.options.selected = id;
setStatus(); setStatus();
that.triggerEvent('selectplace', place); that.triggerEvent('selectplace', place);

View file

@ -1127,6 +1127,18 @@ import wikipedia
if __name__ == '__main__': if __name__ == '__main__':
file = '../txt/geonames.org/cities1000.txt'
geo['keys'] = read_json('../json/oxjs.org/geonames.keys.json')
keys = geo['keys']['place']['geonames.org']
drop = ['alternatenames']
# filter = lambda x: x['feature_code'] != 'PPLX' and x['population'] >= 100000
filter = lambda x: x['feature_code'] == 'PPLC' or x['population'] >= 10000
sort = lambda x: -x['population']
data = read_table(file, keys, drop=drop, filter=filter, sort=sort)
write_json('../json/geonames.org/cities10000.json', data, False)
print len(data)
sys.exit()
write_json('../json/geo.json', geo) write_json('../json/geo.json', geo)
countries = get_countries() countries = get_countries()