OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
- _changesets: [],
+ _changesets: new Map,
updateChangesets: function (map, changesets) {
- this._changesets = changesets;
+ this._changesets = new Map(changesets.map(changeset => [changeset.id, changeset]));
this.updateChangesetShapes(map);
},
updateChangesetShapes: function (map) {
this.clearLayers();
- for (const changeset of this._changesets) {
+ for (const changeset of this._changesets.values()) {
const bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
width = topRight.x - bottomLeft.x,
map.unproject(topRight));
}
- this._changesets.sort(function (a, b) {
+ const changesetEntries = [...this._changesets];
+ changesetEntries.sort(([, a], [, b]) => {
return b.bounds.getSize() - a.bounds.getSize();
});
+ this._changesets = new Map(changesetEntries);
this.updateChangesetLocations(map);
- for (const changeset of this._changesets) {
+ for (const changeset of this._changesets.values()) {
const rect = L.rectangle(changeset.bounds,
{ weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
rect.id = changeset.id;
updateChangesetLocations: function (map) {
const mapCenterLng = map.getCenter().lng;
- for (const changeset of this._changesets) {
+ for (const changeset of this._changesets.values()) {
const changesetSouthWest = changeset.bounds.getSouthWest();
const changesetNorthEast = changeset.bounds.getNorthEast();
const changesetCenterLng = (changesetSouthWest.lng + changesetNorthEast.lng) / 2;