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);
13 var group = L.featureGroup()
14 .on("mouseover", function (e) {
15 highlightChangeset(e.layer.id);
17 .on("mouseout", function (e) {
18 unHighlightChangeset(e.layer.id);
20 .on("click", function (e) {
21 clickChangeset(e.layer.id);
24 group.getLayerId = function(layer) {
28 function highlightChangeset(id) {
29 group.getLayer(id).setStyle({fillOpacity: 0.3});
30 $("#changeset_" + id).addClass("selected");
33 function unHighlightChangeset(id) {
34 group.getLayer(id).setStyle({fillOpacity: 0});
35 $("#changeset_" + id).removeClass("selected");
38 function clickChangeset(id) {
39 OSM.router.route($("#changeset_" + id).find(".changeset_id").attr("href"));
45 if (window.location.pathname === '/history') {
46 data = {bbox: map.getBounds().wrap().toBBoxString()};
50 url: window.location.pathname,
53 success: function(html, status, xhr) {
54 $('#sidebar_content .changesets').html(html);
60 function loadMore(e) {
64 var div = $(this).parents(".changeset_more");
67 div.find(".loader").show();
69 $.get($(this).attr("href"), function(data) {
70 div.replaceWith(data);
75 function updateMap() {
80 $("[data-changeset]").each(function () {
81 var changeset = $(this).data('changeset');
83 changeset.bounds = L.latLngBounds(
84 [changeset.bbox.minlat, changeset.bbox.minlon],
85 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
86 changesets.push(changeset);
90 changesets.sort(function (a, b) {
91 return b.bounds.getSize() - a.bounds.getSize();
94 for (var i = 0; i < changesets.length; ++i) {
95 var changeset = changesets[i],
96 rect = L.rectangle(changeset.bounds,
97 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
98 rect.id = changeset.id;
102 if (window.location.pathname !== '/history') {
103 var bounds = group.getBounds();
104 if (bounds.isValid()) map.fitBounds(bounds);
108 page.pushstate = page.popstate = function(path) {
109 $("#history_tab").addClass("current");
110 OSM.loadSidebarContent(path, page.load);
113 page.load = function() {
116 if (window.location.pathname === '/history') {
117 map.on("moveend", loadData)
123 page.unload = function() {
124 map.removeLayer(group);
126 if (window.location.pathname === '/history') {
127 map.off("moveend", loadData)
130 $("#history_tab").removeClass("current");