imerss-bioinfo 1.16.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "imerss-bioinfo",
3
3
  "description": "Working data of the IMERSS biodiversity informatics working group, together with algorithms",
4
- "version": "1.16.0",
4
+ "version": "1.18.0",
5
5
  "author": "Antranig Basman",
6
6
  "scripts": {
7
7
  "lint": "fluid-lint-all",
@@ -72,8 +72,19 @@ hortis.libreMap.polygonFilter.summarise = function (filterState) {
72
72
  return hortis.countSummary(filterState.length, ["polygon", "polygons"]);
73
73
  };
74
74
 
75
+ /**
76
+ * Filter observations to those lying within any of the polygons drawn. The polygons arrive as component material, read
77
+ * through a proxy which tracks each access - since every observation is tested against every vertex of the polygons,
78
+ * their bare values are read instead, which is many times faster.
79
+ * @param {Object[]} obsRows - The observations
80
+ * @param {Object[]} filterState - The polygons drawn, as GeoJSON features, possibly as a proxy
81
+ * @param {Map<Object, Object>} pointCache - Map of each observation to its point, possibly as a proxy
82
+ * @return {Object[]} The observations within any of the polygons
83
+ */
75
84
  hortis.libreMap.polygonFilter.doFilter = function (obsRows, filterState, pointCache) {
76
- return filterState.length === 0 ? obsRows : obsRows.filter(row => hortis.intersectsAnyFeature(filterState, pointCache.get(row)));
85
+ const features = fluid.unwrapProxy(filterState);
86
+ const points = fluid.unwrapProxy(pointCache);
87
+ return features.length === 0 ? obsRows : obsRows.filter(row => hortis.intersectsAnyFeature(features, points.get(row)));
77
88
  };
78
89
 
79
90
  hortis.libreMap.polygonFilter.reset = function (that) {
@@ -104,7 +115,18 @@ hortis.libreMap.polygonFilter.makeDraw = function (that, map, mapboxDrawOptions,
104
115
  const modeChange = e => that.drawMode = e.mode;
105
116
  const listeners = {"draw.create": updateArea, "draw.delete": updateArea, "draw.update": updateArea, "draw.modechange": modeChange};
106
117
  Object.entries(listeners).forEach(([event, listener]) => map.on(event, listener));
107
- togo = {map, draw, listeners};
118
+ // MapboxDraw's trash deletes only the polygons selected, and polygons restored from the URL are drawn unselected
119
+ // - so with none selected, the trash deletes them all. Heard before MapboxDraw's own handler, while the
120
+ // selection is still as the user left it
121
+ const trashButton = map.getContainer().querySelector(".mapbox-gl-draw_trash");
122
+ const trashAll = () => {
123
+ if (draw.getSelectedIds().length === 0 && draw.getAll().features.length > 0) {
124
+ draw.deleteAll();
125
+ updateArea();
126
+ }
127
+ };
128
+ trashButton?.addEventListener("click", trashAll, true);
129
+ togo = {map, draw, listeners, trashButton, trashAll};
108
130
  } else {
109
131
  togo = fluid.unavailable({message: "The MapboxDraw library is not loaded", variety: "config"});
110
132
  }
@@ -113,6 +135,7 @@ hortis.libreMap.polygonFilter.makeDraw = function (that, map, mapboxDrawOptions,
113
135
 
114
136
  hortis.libreMap.polygonFilter.removeDraw = function (record) {
115
137
  Object.entries(record.listeners).forEach(([event, listener]) => record.map.off(event, listener));
138
+ record.trashButton?.removeEventListener("click", record.trashAll, true);
116
139
  record.map.removeControl(record.draw);
117
140
  };
118
141