1 //= require jquery.simulate
3 OSM.History = function(map) {
7 .on("click", ".changeset_more a", loadMore)
8 .on("mouseover", "[data-changeset]", function () {
9 highlightChangeset($(this).data("changeset").id);
11 .on("mouseout", "[data-changeset]", function () {
12 unHighlightChangeset($(this).data("changeset").id);
14 .on("click", "[data-changeset]", function (e) {
15 if (!$(e.target).is('a')) {
16 clickChangeset($(this).data("changeset").id, e);
20 var group = L.featureGroup()
21 .on("mouseover", function (e) {
22 highlightChangeset(e.layer.id);
24 .on("mouseout", function (e) {
25 unHighlightChangeset(e.layer.id);
27 .on("click", function (e) {
28 clickChangeset(e.layer.id, e);
31 group.getLayerId = function(layer) {
35 function highlightChangeset(id) {
36 group.getLayer(id).setStyle({fillOpacity: 0.3});
37 $("#changeset_" + id).addClass("selected");
40 function unHighlightChangeset(id) {
41 group.getLayer(id).setStyle({fillOpacity: 0});
42 $("#changeset_" + id).removeClass("selected");
45 function clickChangeset(id, e) {
46 $("#changeset_" + id).find("a.changeset_id").simulate("click", e);
50 var data = {list: '1'};
52 if (window.location.pathname === '/history') {
53 data.bbox = map.getBounds().wrap().toBBoxString();
57 url: window.location.pathname,
60 success: function(html, status, xhr) {
61 $('#sidebar_content .changesets').html(html);
66 var feedLink = $('link[type="application/atom+xml"]'),
67 feedHref = feedLink.attr('href').split('?')[0];
69 feedLink.attr('href', feedHref + '?bbox=' + data.bbox);
72 function loadMore(e) {
76 var div = $(this).parents(".changeset_more");
79 div.find(".loader").show();
81 $.get($(this).attr("href"), function(data) {
82 div.replaceWith(data);
87 function updateMap() {
92 $("[data-changeset]").each(function () {
93 var changeset = $(this).data('changeset');
95 changeset.bounds = L.latLngBounds(
96 [changeset.bbox.minlat, changeset.bbox.minlon],
97 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
98 changesets.push(changeset);
102 changesets.sort(function (a, b) {
103 return b.bounds.getSize() - a.bounds.getSize();
106 for (var i = 0; i < changesets.length; ++i) {
107 var changeset = changesets[i],
108 rect = L.rectangle(changeset.bounds,
109 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
110 rect.id = changeset.id;
114 if (window.location.pathname !== '/history') {
115 var bounds = group.getBounds();
116 if (bounds.isValid()) map.fitBounds(bounds);
120 page.pushstate = page.popstate = function(path) {
121 $("#history_tab").addClass("current");
122 OSM.loadSidebarContent(path, page.load);
125 page.load = function() {
128 if (window.location.pathname === '/history') {
129 map.on("moveend", update);
135 page.unload = function() {
136 map.removeLayer(group);
137 map.off("moveend", update);
139 $("#history_tab").removeClass("current");