1 //= require jquery-simulate/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("mousedown", "[data-changeset]", function () {
 
  17         .one("click", function (e) {
 
  18           if (!moved && !$(e.target).is("a")) {
 
  19             clickChangeset($(this).data("changeset").id, e);
 
  22         .one("mousemove", function () {
 
  27   var group = L.featureGroup()
 
  28     .on("mouseover", function (e) {
 
  29       highlightChangeset(e.layer.id);
 
  31     .on("mouseout", function (e) {
 
  32       unHighlightChangeset(e.layer.id);
 
  34     .on("click", function (e) {
 
  35       clickChangeset(e.layer.id, e);
 
  38   group.getLayerId = function (layer) {
 
  42   function highlightChangeset(id) {
 
  43     var layer = group.getLayer(id);
 
  44     if (layer) layer.setStyle({ fillOpacity: 0.3, color: "#FF6600", weight: 3 });
 
  45     $("#changeset_" + id).addClass("selected");
 
  48   function unHighlightChangeset(id) {
 
  49     var layer = group.getLayer(id);
 
  50     if (layer) layer.setStyle({ fillOpacity: 0, color: "#FF9500", weight: 2 });
 
  51     $("#changeset_" + id).removeClass("selected");
 
  54   function clickChangeset(id, e) {
 
  55     $("#changeset_" + id).find("a.changeset_id").simulate("click", e);
 
  59     var data = { list: "1" };
 
  61     if (window.location.pathname === "/history") {
 
  62       data.bbox = map.getBounds().wrap().toBBoxString();
 
  66       url: window.location.pathname,
 
  69       success: function (html) {
 
  70         $("#sidebar_content .changesets").html(html);
 
  75     var feedLink = $("link[type=\"application/atom+xml\"]"),
 
  76         feedHref = feedLink.attr("href").split("?")[0];
 
  78     feedLink.attr("href", feedHref + "?bbox=" + data.bbox);
 
  81   function loadMore(e) {
 
  85     var div = $(this).parents(".changeset_more");
 
  88     div.find(".loader").show();
 
  90     $.get($(this).attr("href"), function (data) {
 
  91       div.replaceWith(data);
 
  98   function updateBounds() {
 
 101     changesets.forEach(function (changeset) {
 
 102       var bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
 
 103           topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
 
 104           width = topRight.x - bottomLeft.x,
 
 105           height = bottomLeft.y - topRight.y,
 
 106           minSize = 20; // Min width/height of changeset in pixels
 
 108       if (width < minSize) {
 
 109         bottomLeft.x -= ((minSize - width) / 2);
 
 110         topRight.x += ((minSize - width) / 2);
 
 113       if (height < minSize) {
 
 114         bottomLeft.y += ((minSize - height) / 2);
 
 115         topRight.y -= ((minSize - height) / 2);
 
 118       changeset.bounds = L.latLngBounds(map.unproject(bottomLeft),
 
 119                                         map.unproject(topRight));
 
 122     changesets.sort(function (a, b) {
 
 123       return b.bounds.getSize() - a.bounds.getSize();
 
 126     for (var i = 0; i < changesets.length; ++i) {
 
 127       var changeset = changesets[i],
 
 128           rect = L.rectangle(changeset.bounds,
 
 129                              { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
 
 130       rect.id = changeset.id;
 
 135   function updateMap() {
 
 136     changesets = $("[data-changeset]").map(function (index, element) {
 
 137       return $(element).data("changeset");
 
 138     }).get().filter(function (changeset) {
 
 139       return changeset.bbox;
 
 144     if (window.location.pathname !== "/history") {
 
 145       var bounds = group.getBounds();
 
 146       if (bounds.isValid()) map.fitBounds(bounds);
 
 150   page.pushstate = page.popstate = function (path) {
 
 151     $("#history_tab").addClass("current");
 
 152     OSM.loadSidebarContent(path, page.load);
 
 155   page.load = function () {
 
 158     if (window.location.pathname === "/history") {
 
 159       map.on("moveend", update);
 
 162     map.on("zoomend", updateBounds);
 
 167   page.unload = function () {
 
 168     map.removeLayer(group);
 
 169     map.off("moveend", update);
 
 171     $("#history_tab").removeClass("current");