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);
67 function loadMore(e) {
71 var div = $(this).parents(".changeset_more");
74 div.find(".loader").show();
76 $.get($(this).attr("href"), function(data) {
77 div.replaceWith(data);
82 function updateMap() {
87 $("[data-changeset]").each(function () {
88 var changeset = $(this).data('changeset');
90 changeset.bounds = L.latLngBounds(
91 [changeset.bbox.minlat, changeset.bbox.minlon],
92 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
93 changesets.push(changeset);
97 changesets.sort(function (a, b) {
98 return b.bounds.getSize() - a.bounds.getSize();
101 for (var i = 0; i < changesets.length; ++i) {
102 var changeset = changesets[i],
103 rect = L.rectangle(changeset.bounds,
104 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
105 rect.id = changeset.id;
109 if (window.location.pathname !== '/history') {
110 var bounds = group.getBounds();
111 if (bounds.isValid()) map.fitBounds(bounds);
115 page.pushstate = page.popstate = function(path) {
116 $("#history_tab").addClass("current");
117 OSM.loadSidebarContent(path, page.load);
120 page.load = function() {
123 if (window.location.pathname === '/history') {
124 map.on("moveend", loadData)
130 page.unload = function() {
131 map.removeLayer(group);
133 if (window.location.pathname === '/history') {
134 map.off("moveend", loadData)
137 $("#history_tab").removeClass("current");