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) {
13 if (!$(e.target).is('a')) {
14 clickChangeset($(this).data("changeset").id, e);
18 var group = L.featureGroup()
19 .on("mouseover", function (e) {
20 highlightChangeset(e.layer.id);
22 .on("mouseout", function (e) {
23 unHighlightChangeset(e.layer.id);
25 .on("click", function (e) {
26 clickChangeset(e.layer.id, e);
29 group.getLayerId = function(layer) {
33 function highlightChangeset(id) {
34 group.getLayer(id).setStyle({fillOpacity: 0.3});
35 $("#changeset_" + id).addClass("selected");
38 function unHighlightChangeset(id) {
39 group.getLayer(id).setStyle({fillOpacity: 0});
40 $("#changeset_" + id).removeClass("selected");
43 function clickChangeset(id, e) {
44 var evt, el = $("#changeset_" + id).find("a.changeset_id")[0];
45 if ('createEvent' in document) {
46 evt = document.createEvent('MouseEvents');
47 evt.initMouseEvent('click',
50 window, // 'AbstractView'
51 e.clicks, // click count
60 e.button, // mouse button
61 e.relatedTarget // relatedTarget
63 el.dispatchEvent(evt);
65 evt = document.createEventObject();
66 el.fireEvent('onclick', evt);
71 var data = {list: '1'};
73 if (window.location.pathname === '/history') {
74 data.bbox = map.getBounds().wrap().toBBoxString();
78 url: window.location.pathname,
81 success: function(html, status, xhr) {
82 $('#sidebar_content .changesets').html(html);
88 function loadMore(e) {
92 var div = $(this).parents(".changeset_more");
95 div.find(".loader").show();
97 $.get($(this).attr("href"), function(data) {
98 div.replaceWith(data);
103 function updateMap() {
108 $("[data-changeset]").each(function () {
109 var changeset = $(this).data('changeset');
110 if (changeset.bbox) {
111 changeset.bounds = L.latLngBounds(
112 [changeset.bbox.minlat, changeset.bbox.minlon],
113 [changeset.bbox.maxlat, changeset.bbox.maxlon]);
114 changesets.push(changeset);
118 changesets.sort(function (a, b) {
119 return b.bounds.getSize() - a.bounds.getSize();
122 for (var i = 0; i < changesets.length; ++i) {
123 var changeset = changesets[i],
124 rect = L.rectangle(changeset.bounds,
125 {weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFBF", fillOpacity: 0});
126 rect.id = changeset.id;
130 if (window.location.pathname !== '/history') {
131 var bounds = group.getBounds();
132 if (bounds.isValid()) map.fitBounds(bounds);
136 page.pushstate = page.popstate = function(path) {
137 $("#history_tab").addClass("current");
138 OSM.loadSidebarContent(path, page.load);
141 page.load = function() {
144 if (window.location.pathname === '/history') {
145 map.on("moveend", loadData)
151 page.unload = function() {
152 map.removeLayer(group);
154 if (window.location.pathname === '/history') {
155 map.off("moveend", loadData)
158 $("#history_tab").removeClass("current");