]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/changeset.js
Implement closing sidebar
[rails.git] / app / assets / javascripts / index / changeset.js
1 OSM.ChangesetList = function(map) {
2   var page = {};
3
4   var group = L.featureGroup()
5     .on({
6       mouseover: function (e) {
7         highlightChangeset(e.layer.id);
8       },
9       mouseout: function (e) {
10         unHighlightChangeset(e.layer.id);
11       }
12     });
13
14   group.getLayerId = function(layer) {
15     return layer.id;
16   };
17
18   function highlightChangeset(id) {
19     group.getLayer(id).setStyle({fillOpacity: 0.5});
20     $("#changeset_" + id).addClass("selected");
21   }
22
23   function unHighlightChangeset(id) {
24     group.getLayer(id).setStyle({fillOpacity: 0});
25     $("#changeset_" + id).removeClass("selected");
26   }
27
28   page.pushstate = page.popstate = function(path) {
29     $("#history_tab").addClass("current");
30     $("#sidebar").removeClass("minimized");
31     map.invalidateSize();
32     $('#sidebar_content').load(path, page.load);
33   };
34
35   page.load = function() {
36     map.addLayer(group);
37
38     var changesets = [];
39     $("[data-changeset]").each(function () {
40       var changeset = $(this).data('changeset');
41       if (changeset.bbox) {
42         changeset.bounds = L.latLngBounds([changeset.bbox.minlat, changeset.bbox.minlon],
43           [changeset.bbox.maxlat, changeset.bbox.maxlon]);
44         changesets.push(changeset);
45       }
46     });
47
48     changesets.sort(function (a, b) {
49       return b.bounds.getSize() - a.bounds.getSize();
50     });
51
52     for (var i = 0; i < changesets.length; ++i) {
53       var changeset = changesets[i],
54         rect = L.rectangle(changeset.bounds,
55           {weight: 2, color: "#ee9900", fillColor: "#ffff55", fillOpacity: 0});
56       rect.id = changeset.id;
57       rect.addTo(group);
58     }
59
60     $("[data-changeset]").on({
61       mouseover: function () {
62         highlightChangeset($(this).data("changeset").id);
63       },
64       mouseout: function () {
65         unHighlightChangeset($(this).data("changeset").id);
66       }
67     });
68   };
69
70   page.unload = function() {
71     map.removeLayer(group);
72     group.clearLayers();
73     $("#history_tab").removeClass("current");
74   };
75
76   return page;
77 };