add/remove place markers dynamically, based on viewport and size

This commit is contained in:
rlx 2011-03-05 12:35:14 +00:00
parent dc86a5c53e
commit 311521c911

View file

@ -9332,6 +9332,7 @@ requires
editable: false, editable: false,
height: 256, height: 256,
labels: false, labels: false,
markers: 100,
places: [], places: [],
selected: null, selected: null,
statusbar: false, statusbar: false,
@ -9828,7 +9829,7 @@ requires
self.options.places.forEach(function(place, i) { self.options.places.forEach(function(place, i) {
self.places[i] = new Ox.MapPlace(Ox.extend({ self.places[i] = new Ox.MapPlace(Ox.extend({
map: that map: that
}, place)).add(); }, place))/*.add()*/;
}); });
google.maps.event.trigger(self.map, 'resize'); google.maps.event.trigger(self.map, 'resize');
that.gainFocus(); that.gainFocus();
@ -9838,27 +9839,24 @@ requires
function mapChanged() { function mapChanged() {
// gets called after panning or zooming // gets called after panning or zooming
Ox.print('mapChanged'); Ox.print('mapChanged');
var bounds, places var bounds;
if (self.boundsChanged) { if (self.boundsChanged) {
/*
bounds = self.map.getBounds(); bounds = self.map.getBounds();
places = Ox.clone(self.places).filter(function(place) { self.places.sort(function(a, b) {
return bounds.contains(place.center); var sort = {
}); a: a.selected ? Infinity :
if (places.length > 100) { (bounds.contains(a.center) ? a.size : -Infinity),
places.sort(function(a, b) { b: b.selected ? Infinity :
return a.size < b.size ? 1 : (a.size > b.size ? -1 : 0); (bounds.contains(b.center) ? b.size : -Infinity),
}); };
} return sort.b - sort.a;
self.places.forEach(function(place) { }).forEach(function(place, i) {
place.remove(); if (i < self.options.markers && !place.visible) {
});
places.forEach(function(place, i) {
if (i < 100) {
place.add(); place.add();
} else if (i >= self.options.markers && place.visible) {
place.remove();
} }
}); });
*/
self.boundsChanged = false; self.boundsChanged = false;
} }
if (self.centerChanged) { if (self.centerChanged) {
@ -10216,6 +10214,7 @@ requires
selected: false, selected: false,
south: 0, south: 0,
type: [], type: [],
visible: false,
west: 0 west: 0
}, options), }, options),
that = this; that = this;
@ -10272,6 +10271,7 @@ requires
that.add = function() { that.add = function() {
Ox.print('MapPlace add', that) Ox.print('MapPlace add', that)
that.visible = true;
that.marker.add(); that.marker.add();
return that; return that;
}; };
@ -10317,6 +10317,7 @@ requires
Ox.print('MapPlace remove', that) Ox.print('MapPlace remove', that)
that.editing && that.submit(); that.editing && that.submit();
that.selected && that.deselect(); that.selected && that.deselect();
that.visible = false;
that.marker.remove(); that.marker.remove();
return that; return that;
}; };