]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/history-changesets-layer.js
Add history changesets layer module
[rails.git] / app / assets / javascripts / index / history-changesets-layer.js
1 OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
2   _changesets: [],
3
4   updateChangesets: function (map, changesets) {
5     this._changesets = changesets;
6     this.updateChangesetShapes(map);
7   },
8
9   updateChangesetShapes: function (map) {
10     this.clearLayers();
11
12     for (const changeset of this._changesets) {
13       const bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
14             topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
15             width = topRight.x - bottomLeft.x,
16             height = bottomLeft.y - topRight.y,
17             minSize = 20; // Min width/height of changeset in pixels
18
19       if (width < minSize) {
20         bottomLeft.x -= ((minSize - width) / 2);
21         topRight.x += ((minSize - width) / 2);
22       }
23
24       if (height < minSize) {
25         bottomLeft.y += ((minSize - height) / 2);
26         topRight.y -= ((minSize - height) / 2);
27       }
28
29       changeset.bounds = L.latLngBounds(map.unproject(bottomLeft),
30                                         map.unproject(topRight));
31     }
32
33     this._changesets.sort(function (a, b) {
34       return b.bounds.getSize() - a.bounds.getSize();
35     });
36
37     for (const changeset of this._changesets) {
38       const rect = L.rectangle(changeset.bounds,
39                                { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
40       rect.id = changeset.id;
41       rect.addTo(this);
42     }
43   },
44
45   highlightChangeset: function (id) {
46     this.getLayer(id)?.setStyle({ fillOpacity: 0.3, color: "#FF6600", weight: 3 });
47   },
48
49   unHighlightChangeset: function (id) {
50     this.getLayer(id)?.setStyle({ fillOpacity: 0, color: "#FF9500", weight: 2 });
51   },
52
53   getLayerId: function (layer) {
54     return layer.id;
55   }
56 });