@abi-software/flatmap-viewer 2.7.0-a.2 → 2.7.1-a.1

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/flatmap-viewer",
3
- "version": "2.7.0-a.2",
3
+ "version": "2.7.1-a.1",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
5
  "repository": {
6
6
  "type": "git",
@@ -955,8 +955,10 @@ export class FlatMap
955
955
  * to place the marker.
956
956
  * @arg {Object} options Configurable options for the marker.
957
957
  * @arg {string} options.className Space-separated CSS class names to add to marker element.
958
- * @arg {string} options.colour Colour of the default marker. Defaults to ``'#005974'``
959
- * (dark blue).
958
+ * @arg {string} options.cluster The marker will be clustered together with other geographically
959
+ * close markers. Defaults to ``true``.
960
+ * @arg {string} options.colour Colour of the marker. Defaults to ``'#005974'``
961
+ * (dark cyan).
960
962
  * @arg {string} options.element The DOM element to use as a marker. The default is
961
963
  * a dark blue droplet-shaped SVG marker.
962
964
  * @return {integer} The identifier for the resulting marker. -1 is returned if the
@@ -965,15 +967,33 @@ export class FlatMap
965
967
  addMarker(anatomicalId, options={})
966
968
  //==================================
967
969
  {
970
+ options = Object.assign({cluster: true}, options)
968
971
  if (this._userInteractions !== null) {
969
972
  return this._userInteractions.addMarker(anatomicalId, options);
970
973
  }
971
974
  return -1;
972
975
  }
973
976
 
977
+ /**
978
+ * Add a list of markers to the map.
979
+ *
980
+ * @param {Array.<string>} anatomicalId Anatomical identifiers of features on which
981
+ * to place markers.
982
+ * @arg {Object} options Configurable options for the markers.
983
+ * @arg {string} options.className Space-separated CSS class names to add to marker elemens.
984
+ * @arg {string} options.cluster The markers will be clustered together with other geographically
985
+ * close markers. Defaults to ``true``.
986
+ * @arg {string} options.colour Colour of the markers. Defaults to ``'#005974'``
987
+ * (dark cyan).
988
+ * @arg {string} options.element The DOM element to use as a marker. The default is
989
+ * a dark blue droplet-shaped SVG marker.
990
+ * @return {array.<integer>} The identifiers of the resulting markers. -1 is returned if the
991
+ * map doesn't contain a feature with the given anatomical identifier
992
+ */
974
993
  addMarkers(anatomicalIds, options={})
975
994
  //====================================
976
995
  {
996
+ options = Object.assign({cluster: true}, options)
977
997
  const markerIds = []
978
998
  for (const anatomicalId of anatomicalIds) {
979
999
  if (this._userInteractions !== null) {
@@ -985,7 +1005,6 @@ export class FlatMap
985
1005
  return markerIds
986
1006
  }
987
1007
 
988
-
989
1008
  /**
990
1009
  * Remove a marker from the map.
991
1010
  *
@@ -1028,7 +1047,7 @@ export class FlatMap
1028
1047
  * Shows a popup at a marker.
1029
1048
  *
1030
1049
  * This method should only be called in response to a ``mouseenter`` event
1031
- * passed to the map's ``callback`` function as a popup won't be shown.
1050
+ * passed to the map's ``callback`` function otherwise a popup won't be shown.
1032
1051
  *
1033
1052
  * @param {integer} markerId The identifier of the marker
1034
1053
  * @param {string | DOMElement} content The popup's content
@@ -1020,6 +1020,10 @@ export class UserInteractions
1020
1020
  // Simulate `mouseenter` events on features
1021
1021
 
1022
1022
  const feature = features[0];
1023
+
1024
+ //is feature a marker??
1025
+ console.log('mm', event.type, feature)
1026
+
1023
1027
  const featureModels = ('properties' in feature && 'models' in feature.properties)
1024
1028
  ? feature.properties.models
1025
1029
  : null;
@@ -1378,8 +1382,6 @@ export class UserInteractions
1378
1382
  const marker = new maplibregl.Marker(markerOptions)
1379
1383
  .setLngLat(markerPosition)
1380
1384
  .addTo(this._map);
1381
-
1382
-
1383
1385
  markerElement.addEventListener('mouseenter',
1384
1386
  this.markerMouseEvent_.bind(this, marker, anatomicalId));
1385
1387
  markerElement.addEventListener('mousemove',
@@ -1443,20 +1445,17 @@ export class UserInteractions
1443
1445
  return anatomicalIds;
1444
1446
  }
1445
1447
 
1446
- // Separate out MapLibre specific code and result of mouse event (tooltip,
1447
- // client message, etc) so clustering code can also use this to process
1448
- // events.
1449
-
1450
1448
  markerMouseEvent_(marker, anatomicalId, event)
1451
1449
  //============================================
1452
1450
  {
1451
+ console.log('mk', event.type)
1453
1452
  // No tooltip when context menu is open
1454
1453
  if (this._modal
1455
1454
  || (this.__activeMarker !== null && event.type === 'mouseleave')) {
1456
1455
  return
1457
1456
  }
1458
1457
 
1459
- if (['mouseenter', 'mouseleave', 'click'].includes(event.type)) {
1458
+ if (['mouseenter', 'mousemove', 'click'].includes(event.type)) {
1460
1459
  this.__activeMarker = marker
1461
1460
 
1462
1461
  // Remove any tooltip
@@ -1465,24 +1464,25 @@ export class UserInteractions
1465
1464
  // Reset cursor
1466
1465
  marker.getElement().style.cursor = 'default';
1467
1466
 
1468
-
1469
1467
  const markerId = this.__markerIdByMarker.get(marker)
1470
1468
  const annotation = this.__annotationByMarkerId.get(markerId)
1471
1469
 
1472
1470
  this.markerEvent_(event, markerId, marker.getLngLat(),
1473
- anatomicalId, annotation)
1471
+ anatomicalId, annotation)
1472
+ console.log('mk handled...')
1473
+ event.stopPropagation()
1474
1474
  }
1475
1475
  }
1476
1476
 
1477
1477
  markerEvent_(event, markerId, markerPosition, anatomicalId, annotation)
1478
1478
  //=====================================================================
1479
1479
  {
1480
- if (['mouseenter', 'mouseleave', 'click'].includes(event.type)) {
1480
+ if (['mousemove', 'click'].includes(event.type)) {
1481
1481
 
1482
- // Remove any existing tooltips
1482
+ // Remove any tooltips
1483
1483
  this.removeTooltip_();
1484
1484
 
1485
- if (['mouseenter', 'click'].includes(event.type)) {
1485
+ if (['mouseenter', 'mousemove', 'click'].includes(event.type)) {
1486
1486
  // The marker's feature
1487
1487
  const feature = this.mapFeature(annotation.featureId);
1488
1488
  if (feature !== undefined) {
@@ -1499,7 +1499,7 @@ export class UserInteractions
1499
1499
  this.__showToolTip(html, markerPosition);
1500
1500
 
1501
1501
  // Send marker event message
1502
- this._flatmap.markerEvent(event.type, markerId, anatomicalId);
1502
+ this._flatmap.markerEvent(event.type, markerId, anatomicalId)
1503
1503
  }
1504
1504
  }
1505
1505
  }
@@ -63,8 +63,6 @@ export class ClusteredMarkerLayer
63
63
  }
64
64
  #ui
65
65
 
66
- seenmove = false
67
-
68
66
  constructor(flatmap, ui)
69
67
  {
70
68
  this.#flatmap = flatmap
@@ -136,29 +134,21 @@ export class ClusteredMarkerLayer
136
134
  this.#map.on('mouseleave', 'clustered-markers', () => {
137
135
  this.#map.getCanvas().style.cursor = ''
138
136
  })
139
-
140
- // Also 'mousemove'...
141
137
  }
142
138
 
143
139
  singleMarkerEvent(event)
144
140
  //======================
145
141
  {
142
+ console.log('cl', event.type)
146
143
  const features = this.#map.queryRenderedFeatures(event.point, {
147
144
  layers: ['single-points']
148
145
  })
149
146
  for (const feature of features) {
150
- if (event.type === 'mousemove' && !this.seenMove) {
151
- console.log('Single marker', event.type, feature)
152
- this.seenMove = true
153
- } else if (event.type !== 'mousemove') {
154
- console.log('Single marker', event.type, feature)
155
- this.seenMove = false
156
- }
157
-
158
147
  const properties = feature.properties
159
148
  const position = properties.markerPosition.slice(1, -1).split(',').map(p => +p)
160
149
  this.#ui.markerEvent_(event, feature.id, position, properties.models, properties)
161
150
  }
151
+ console.log('cl handled...')
162
152
  event.originalEvent.stopPropagation()
163
153
  }
164
154
 
package/src/main.js CHANGED
@@ -49,7 +49,7 @@ const ALL_MARKERS = [
49
49
  'UBERON:0037094',
50
50
  'ILX:0738305',
51
51
 
52
- 'UBERON:0000948', // {className: 'heart-marker'}); // Heart
52
+ // 'UBERON:0000948', // {className: 'heart-marker'}); // Heart
53
53
  'UBERON:0002048', // Lung
54
54
  'UBERON:0000945', // Stomach
55
55
  'UBERON:0001155', // Colon
@@ -175,8 +175,8 @@ export async function standaloneViewer(map_endpoint=null, options={})
175
175
  mapOptions.background = args[0].value;
176
176
  } else if (eventType === 'annotation') {
177
177
  drawControl.handleEvent(...args)
178
- } else {
179
- //console.log(eventType, ...args)
178
+ } else if (args[0].type === 'marker') {
179
+ console.log(eventType, ...args)
180
180
  }
181
181
  }, mapOptions)
182
182
  .then(map => {
@@ -188,7 +188,11 @@ export async function standaloneViewer(map_endpoint=null, options={})
188
188
  map.addMarker('UBERON:0001255'); // Bladder
189
189
  map.addMarker('UBERON:0001759'); // Vagus
190
190
  */
191
- map.addMarkers(ALL_MARKERS, {cluster: true})
191
+ map.addMarker('UBERON:0000945', {cluster: true}); // Stomach
192
+ // map.addMarker('UBERON:0016508', {cluster: false}); // Pelvic ganglion
193
+ map.addMarker('UBERON:0016508', {cluster: true}); // Pelvic ganglion
194
+ map.addMarker('UBERON:0000948', {cluster: true, className: 'heart-marker'}); // Heart
195
+ // map.addMarkers(ALL_MARKERS)
192
196
  currentMap = map;
193
197
  drawControl = new DrawControl(map)
194
198
  })