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 () {
13 clickChangeset($(this).data("changeset").id);
16 var group = L.featureGroup()
17 .on("mouseover", function (e) {
18 highlightChangeset(e.layer.id);
20 .on("mouseout", function (e) {
21 unHighlightChangeset(e.layer.id);
23 .on("click", function (e) {
24 clickChangeset(e.layer.id);
27 group.getLayerId = function(layer) {
31 function highlightChangeset(id) {
32 group.getLayer(id).setStyle({fillOpacity: 0.3});
33 $("#changeset_" + id).addClass("selected");
36 function unHighlightChangeset(id) {
37 group.getLayer(id).setStyle({fillOpacity: 0});
38 $("#changeset_" + id).removeClass("selected");
41 function clickChangeset(id) {
42 OSM.route($("#changeset_" + id).find(".changeset_id").attr("href"));
48 if (window.location.pathname === '/history') {
49 data = {bbox: map.getBounds().wrap().toBBoxString()};
53 url: window.location.pathname,
56 success: function(html, status, xhr) {
57 $('#sidebar_content .changesets').html(html);
63 function loadMore(e) {
67 var div = $(this).parents(".changeset_more");
70 div.find(".loader").show();
72 $.get($(this).attr("href"), function(data) {
73 div.replaceWith(data);
78 function updateMap() {
83 $("[data-changeset]").each(function () {
84 var changeset = $(this).data('changeset');
86 changeset.bounds = L.latLngBounds(
87 [changeset.bbox.minlat, changeset.bbox.minlon],
88 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
89 changesets.push(changeset);
93 changesets.sort(function (a, b) {
94 return b.bounds.getSize() - a.bounds.getSize();
97 for (var i = 0; i < changesets.length; ++i) {
98 var changeset = changesets[i],
99 rect = L.rectangle(changeset.bounds,
100 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
101 rect.id = changeset.id;
105 if (window.location.pathname !== '/history') {
106 var bounds = group.getBounds();
107 if (bounds.isValid()) map.fitBounds(bounds);
111 page.pushstate = page.popstate = function(path) {
112 $("#history_tab").addClass("current");
113 OSM.loadSidebarContent(path, page.load);
116 page.load = function() {
119 if (window.location.pathname === '/history') {
120 map.on("moveend", loadData)
126 page.unload = function() {
127 map.removeLayer(group);
129 if (window.location.pathname === '/history') {
130 map.off("moveend", loadData)
133 $("#history_tab").removeClass("current");