1 OSM.History = function(map) {
5 .on("click", ".changeset_more a", loadMore)
6 .on("mouseover", "[data-changeset]", function () {
7 highlightChangeset($(this).data("changeset").id);
9 .on("mouseout", "[data-changeset]", function () {
10 unHighlightChangeset($(this).data("changeset").id);
12 .on("click", "[data-changeset]", function (e) {
14 clickChangeset($(this).data("changeset").id);
17 var group = L.featureGroup()
18 .on("mouseover", function (e) {
19 highlightChangeset(e.layer.id);
21 .on("mouseout", function (e) {
22 unHighlightChangeset(e.layer.id);
24 .on("click", function (e) {
25 clickChangeset(e.layer.id);
28 group.getLayerId = function(layer) {
32 function highlightChangeset(id) {
33 group.getLayer(id).setStyle({fillOpacity: 0.3});
34 $("#changeset_" + id).addClass("selected");
37 function unHighlightChangeset(id) {
38 group.getLayer(id).setStyle({fillOpacity: 0});
39 $("#changeset_" + id).removeClass("selected");
42 function clickChangeset(id) {
43 OSM.router.route($("#changeset_" + id).find(".changeset_id").attr("href"));
47 var data = {list: '1'};
49 if (window.location.pathname === '/history') {
50 data.bbox = map.getBounds().wrap().toBBoxString();
54 url: window.location.pathname,
57 success: function(html, status, xhr) {
58 $('#sidebar_content .changesets').html(html);
64 function loadMore(e) {
68 var div = $(this).parents(".changeset_more");
71 div.find(".loader").show();
73 $.get($(this).attr("href"), function(data) {
74 div.replaceWith(data);
79 function updateMap() {
84 $("[data-changeset]").each(function () {
85 var changeset = $(this).data('changeset');
87 changeset.bounds = L.latLngBounds(
88 [changeset.bbox.minlat, changeset.bbox.minlon],
89 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
90 changesets.push(changeset);
94 changesets.sort(function (a, b) {
95 return b.bounds.getSize() - a.bounds.getSize();
98 for (var i = 0; i < changesets.length; ++i) {
99 var changeset = changesets[i],
100 rect = L.rectangle(changeset.bounds,
101 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
102 rect.id = changeset.id;
106 if (window.location.pathname !== '/history') {
107 var bounds = group.getBounds();
108 if (bounds.isValid()) map.fitBounds(bounds);
112 page.pushstate = page.popstate = function(path) {
113 $("#history_tab").addClass("current");
114 OSM.loadSidebarContent(path, page.load);
117 page.load = function() {
120 if (window.location.pathname === '/history') {
121 map.on("moveend", loadData)
127 page.unload = function() {
128 map.removeLayer(group);
130 if (window.location.pathname === '/history') {
131 map.off("moveend", loadData)
134 $("#history_tab").removeClass("current");