@abi-software/flatmap-viewer 2.4.2-b.3 → 2.4.2-b.5

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/README.rst CHANGED
@@ -38,7 +38,7 @@ The map server endpoint is specified as ``MAP_ENDPOINT`` in ``src/main.js``. It
38
38
  Package Installation
39
39
  ====================
40
40
 
41
- * ``npm install @abi-software/flatmap-viewer@2.4.2-b.3``
41
+ * ``npm install @abi-software/flatmap-viewer@2.4.2-b.5``
42
42
 
43
43
  Documentation
44
44
  -------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/flatmap-viewer",
3
- "version": "2.4.2-b.3",
3
+ "version": "2.4.2-b.5",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
5
  "repository": "https://github.com/AnatomicMaps/flatmap-viewer.git",
6
6
  "main": "src/main.js",
@@ -29,7 +29,8 @@ export const displayedProperties = [
29
29
  'fc-class',
30
30
  'fc-kind',
31
31
  'name',
32
- ...indexedProperties
32
+ ...indexedProperties,
33
+ 'featureId'
33
34
  ];
34
35
 
35
36
  //==============================================================================
@@ -247,18 +248,25 @@ export class InfoControl
247
248
  }
248
249
  }
249
250
  });
250
- displayValues.set(feature.id, values);
251
+ if (Object.keys(values).length > 0) {
252
+ displayValues.set(feature.id, values);
253
+ }
251
254
  }
252
255
  }
253
256
 
254
257
  const htmlList = [];
255
- for (const values of displayValues.values()) {
258
+ let lastId = null;
259
+ for (const [id, values] of displayValues.entries()) {
260
+ if (lastId !== null && lastId !== id) {
261
+ htmlList.push(`<span><hr/></span><span></span>`);
262
+ }
256
263
  for (const prop of displayedProperties) {
257
264
  if (prop in values) {
258
265
  htmlList.push(`<span class="info-name">${prop}:</span>`);
259
266
  htmlList.push(`<span class="info-value">${values[prop]}</span>`);
260
267
  }
261
268
  }
269
+ lastId = id;
262
270
  }
263
271
  if (htmlList.length > 0) {
264
272
  html = `<div id="info-control-info">${htmlList.join('\n')}</div>`;
@@ -622,6 +622,12 @@ class FlatMap
622
622
  return (ann && 'models' in ann) ? utils.normaliseId(ann.models) : null;
623
623
  }
624
624
 
625
+ /**
626
+ * Get model terms of all paths connected to a node.
627
+ *
628
+ * @param {number} pathId The local (GeoJSON) identifier of a node
629
+ * @return {set<string>} Model terms of all paths connected to the node
630
+ */
625
631
  nodePathModels(nodeId)
626
632
  //====================
627
633
  {
@@ -630,6 +636,20 @@ class FlatMap
630
636
  }
631
637
  }
632
638
 
639
+ /**
640
+ * Get feature ids of all nodes of a path model.
641
+ *
642
+ * @param {string} pathId The path model identifier
643
+ * @return {set<number>} Local (GeoJSON) identifiers of features on the path
644
+ */
645
+ pathModelNodes(modelId)
646
+ //=====================
647
+ {
648
+ if (this._userInteractions !== null) {
649
+ return this._userInteractions.pathModelNodes(modelId);
650
+ }
651
+ }
652
+
633
653
  get layers()
634
654
  //==========
635
655
  {
@@ -936,6 +956,7 @@ class FlatMap
936
956
  * @param {string} anatomicalId The anatomical identifier of the feature on which
937
957
  * to place the marker.
938
958
  * @arg {Object} options Configurable options for the marker.
959
+ * @arg {string} options.className Space-separated CSS class names to add to marker element.
939
960
  * @arg {string} options.colour Colour of the default marker. Defaults to ``'#005974'``
940
961
  * (dark blue).
941
962
  * @arg {string} options.element The DOM element to use as a marker. The default is
@@ -1012,23 +1033,18 @@ class FlatMap
1012
1033
  return false;
1013
1034
  }
1014
1035
 
1015
- /**
1016
- * Generate a callback as a result of some event with a flatmap feature.
1017
- *
1018
- * @param {string} eventType The event type
1019
- * @param {Object} properties Properties associated with the feature
1020
- */
1021
- featureEvent(eventType, properties)
1022
- //=================================
1036
+ __exportedProperties(properties)
1037
+ //==============================
1023
1038
  {
1024
1039
  const data = {};
1025
1040
  const exportedProperties = [
1041
+ 'id',
1042
+ 'featureId',
1026
1043
  'connectivity',
1027
1044
  'dataset',
1028
1045
  'kind',
1029
1046
  'label',
1030
1047
  'models',
1031
- 'nodeId',
1032
1048
  'source',
1033
1049
  'taxons',
1034
1050
  'hyperlinks'
@@ -1042,6 +1058,8 @@ class FlatMap
1042
1058
  if (value !== undefined) {
1043
1059
  if (jsonProperties.includes(property)) {
1044
1060
  data[property] = JSON.parse(properties[property])
1061
+ } else if (property === 'featureId') {
1062
+ data[property] = +properties[property]; // Ensure numeric
1045
1063
  } else {
1046
1064
  data[property] = properties[property];
1047
1065
  }
@@ -1050,12 +1068,41 @@ class FlatMap
1050
1068
  }
1051
1069
  if (Object.keys(data).length > 0) {
1052
1070
  data['type'] = 'feature';
1071
+ }
1072
+ return data;
1073
+ }
1074
+
1075
+ /**
1076
+ * Generate a callback as a result of some event with a flatmap feature.
1077
+ *
1078
+ * @param {string} eventType The event type
1079
+ * @param {Object} properties Properties associated with the feature
1080
+ */
1081
+ featureEvent(eventType, properties)
1082
+ //=================================
1083
+ {
1084
+ const data = this.__exportedProperties(properties);
1085
+
1086
+ if (Object.keys(data).length > 0) {
1053
1087
  this.callback(eventType, data);
1054
1088
  return true;
1055
1089
  }
1056
1090
  return false;
1057
1091
  }
1058
1092
 
1093
+ /**
1094
+ * Return properties associated with a feature.
1095
+ *
1096
+ * @param {number} featureId The feature's internal (GeoJSON) id
1097
+ * @returns {Object} Properties associated with the feature
1098
+ */
1099
+ featureProperties(featureId)
1100
+ //==========================
1101
+ {
1102
+ const properties = this.annotation(featureId);
1103
+ return properties ? this.__exportedProperties(properties) : {};
1104
+ }
1105
+
1059
1106
  /**
1060
1107
  * Generate a callback as a result of some event with a marker.
1061
1108
  *
@@ -1089,7 +1089,7 @@ export class UserInteractions
1089
1089
  }
1090
1090
  }
1091
1091
  if ('nodeId' in feature.properties) {
1092
- for (const featureId of this.__pathManager.nodeFeatureIds(feature.properties.nodeId)) {
1092
+ for (const featureId of this.__pathManager.pathFeatureIds(feature.properties.nodeId)) {
1093
1093
  this.__activateFeature(this.mapFeature(featureId));
1094
1094
  }
1095
1095
  }
@@ -1122,6 +1122,12 @@ export class UserInteractions
1122
1122
  return featureIds;
1123
1123
  }
1124
1124
 
1125
+ pathModelNodes(modelId)
1126
+ //=====================
1127
+ {
1128
+ return this.__pathManager.pathModelNodes(modelId);
1129
+ }
1130
+
1125
1131
  nodePathModels(nodeId)
1126
1132
  //====================
1127
1133
  {
@@ -1227,9 +1233,12 @@ export class UserInteractions
1227
1233
  markerIcon.innerHTML = markerHTML.getElement().innerHTML;
1228
1234
  markerElement.id = `marker-${markerId}`;
1229
1235
  markerElement.appendChild(markerIcon);
1230
-
1236
+ const markerOptions = {element: markerElement};
1237
+ if ('className' in options) {
1238
+ markerOptions.className = options.className;
1239
+ }
1231
1240
  const markerPosition = this.__markerPosition(featureId, annotation);
1232
- const marker = new maplibregl.Marker({element: markerElement})
1241
+ const marker = new maplibregl.Marker(markerOptions)
1233
1242
  .setLngLat(markerPosition)
1234
1243
  .addTo(this._map);
1235
1244
  markerElement.addEventListener('mouseenter',
package/src/main.js CHANGED
@@ -93,7 +93,7 @@ export async function standaloneViewer(map_endpoint=null, options={})
93
93
  }
94
94
  }, mapOptions)
95
95
  .then(map => {
96
- map.addMarker('UBERON:0000948'); // Heart
96
+ map.addMarker('UBERON:0000948', {className: 'heart-marker'}); // Heart
97
97
  map.addMarker('UBERON:0002048'); // Lung
98
98
  map.addMarker('UBERON:0000945'); // Stomach
99
99
  map.addMarker('UBERON:0001155'); // Colon
package/src/pathways.js CHANGED
@@ -214,16 +214,6 @@ export class PathManager
214
214
  return featureIds;
215
215
  }
216
216
 
217
- nodeFeatureIds(nodeId)
218
- //===================
219
- {
220
- const featureIds = new Set();
221
- if (nodeId in this._nodePaths) {
222
- this.addPathsToFeatureSet_(this._nodePaths[nodeId], featureIds);
223
- }
224
- return featureIds;
225
- }
226
-
227
217
  pathProperties(feature)
228
218
  //=====================
229
219
  {
@@ -348,6 +338,20 @@ export class PathManager
348
338
  }
349
339
  return modelIds;
350
340
  }
341
+
342
+ pathModelNodes(modelId)
343
+ //=====================
344
+ {
345
+ const nodeIds = new Set();
346
+ if (modelId in this.__pathModelPaths) {
347
+ for (const pathId of this.__pathModelPaths[modelId]) {
348
+ for (const nodeId of this.__paths[pathId].nodes) {
349
+ nodeIds.add(nodeId);
350
+ }
351
+ }
352
+ }
353
+ return nodeIds;
354
+ }
351
355
  }
352
356
 
353
357
  //==============================================================================