Refine changeset browse behavior

The general history view shows changesets in the current view
and updates when you move the map. The view for an individual
user, nearby users, or friends zooms the map to the extent of
the results, and doesn't change when you move the map.
This commit is contained in:
John Firebaugh 2013-11-19 12:10:00 -08:00
parent a5e8b4cb88
commit d0de36b607
5 changed files with 41 additions and 28 deletions

View file

@ -242,19 +242,18 @@ $(document).ready(function () {
return page;
};
var history = OSM.History(map),
note = OSM.Note(map);
var history = OSM.History(map);
OSM.route = OSM.Router(map, {
"/": OSM.Index(map),
"/search": OSM.Search(map),
"/export": OSM.Export(map),
"/history": history,
"/new_note": OSM.NewNote(map),
"/history": history,
"/user/:display_name/edits": history,
"/browse/friends": history,
"/browse/nearby": history,
"/browse/note/:id": note,
"/browse/note/:id": OSM.Note(map),
"/browse/:type/:id(/history)": OSM.Browse(map)
});

View file

@ -43,10 +43,16 @@ OSM.History = function(map) {
}
function loadData() {
var data = {};
if (window.location.pathname === '/history') {
data = {bbox: map.getBounds().wrap().toBBoxString()};
}
$.ajax({
url: window.location.pathname,
method: "GET",
data: {bbox: map.getBounds().wrap().toBBoxString()},
data: data,
success: function(html, status, xhr) {
$('#sidebar_content .changesets').html(html);
updateMap();
@ -95,6 +101,11 @@ OSM.History = function(map) {
rect.id = changeset.id;
rect.addTo(group);
}
if (window.location.pathname !== '/history') {
var bounds = group.getBounds();
if (bounds.isValid()) map.fitBounds(bounds);
}
}
page.pushstate = page.popstate = function(path) {
@ -103,19 +114,22 @@ OSM.History = function(map) {
};
page.load = function() {
map
.on("moveend", loadData)
.addLayer(group);
map.addLayer(group);
if (window.location.pathname === '/history') {
map.on("moveend", loadData)
}
loadData();
};
page.unload = function() {
map
.off("moveend", loadData)
.removeLayer(group);
map.removeLayer(group);
if (window.location.pathname === '/history') {
map.off("moveend", loadData)
}
group.clearLayers();
$("#history_tab").removeClass("current");
};