@abi-software/flatmap-viewer 2.5.7 → 2.5.9

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.5.7``
41
+ * ``npm install @abi-software/flatmap-viewer@2.5.9``
42
42
 
43
43
  Documentation
44
44
  -------------
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@abi-software/flatmap-viewer",
3
- "version": "2.5.7",
3
+ "version": "2.5.9",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
- "repository": "https://github.com/AnatomicMaps/flatmap-viewer.git",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/AnatomicMaps/flatmap-viewer.git"
8
+ },
6
9
  "main": "src/main.js",
7
10
  "files": [
8
11
  "src",
@@ -78,6 +78,7 @@ export class AnnotationDrawControl
78
78
  keybindings: true
79
79
  })
80
80
  this.__map = null
81
+ this.__inDrawing = false
81
82
  }
82
83
 
83
84
  onAdd(map)
@@ -96,6 +97,7 @@ export class AnnotationDrawControl
96
97
  e.preventDefault();
97
98
  }
98
99
  }, false)
100
+ map.on('draw.modechange', this.modeChangedEvent.bind(this))
99
101
  map.on('draw.create', this.createdFeature.bind(this))
100
102
  map.on('draw.delete', this.deletedFeature.bind(this))
101
103
  map.on('draw.update', this.updatedFeature.bind(this))
@@ -146,7 +148,10 @@ export class AnnotationDrawControl
146
148
  #sendEvent(type, feature)
147
149
  //=======================
148
150
  {
149
- this.__uncommittedFeatureIds.add(feature.id)
151
+ if (feature.id) {
152
+ // Add when the event is 'created', 'updated' or 'deleted'
153
+ this.__uncommittedFeatureIds.add(feature.id)
154
+ }
150
155
  this.__flatmap.annotationEvent(type, feature)
151
156
  }
152
157
 
@@ -193,6 +198,20 @@ export class AnnotationDrawControl
193
198
  }
194
199
  }
195
200
 
201
+ modeChangedEvent(event)
202
+ //=====================
203
+ {
204
+ // Used as a flag to indicate the feature mode
205
+ this.__inDrawing = (event.mode.startsWith('draw'))
206
+ this.#sendEvent('modeChanged', event)
207
+ }
208
+
209
+ inDrawingMode()
210
+ //=============
211
+ {
212
+ return this.__inDrawing
213
+ }
214
+
196
215
  commitEvent(event)
197
216
  //================
198
217
  {
@@ -205,6 +224,14 @@ export class AnnotationDrawControl
205
224
  this.__uncommittedFeatureIds.delete(feature.id)
206
225
  }
207
226
 
227
+ abortEvent(event)
228
+ //===============
229
+ {
230
+ // Used as a flag to indicate the popup is closed
231
+ // Rollback should be performed when triggered 'aborted' event
232
+ this.#sendEvent('aborted', event)
233
+ }
234
+
208
235
  rollbackEvent(event)
209
236
  //==================
210
237
  {
@@ -226,6 +253,12 @@ export class AnnotationDrawControl
226
253
  }
227
254
  }
228
255
  }
256
+
257
+ clearFeature()
258
+ //============
259
+ {
260
+ this.__draw.deleteAll()
261
+ }
229
262
 
230
263
  addFeature(feature)
231
264
  //=================
@@ -484,7 +484,7 @@ class FlatMap
484
484
  /**
485
485
  * Flag the feature as having external annotation.
486
486
  *
487
- * @param {string} featureId The feature's identifier
487
+ * @param {string} featureId The feature's external identifier
488
488
  */
489
489
  setFeatureAnnotated(featureId)
490
490
  //============================
@@ -1110,6 +1110,17 @@ class FlatMap
1110
1110
  this._userInteractions.rollbackAnnotationEvent(event)
1111
1111
  }
1112
1112
  }
1113
+
1114
+ /**
1115
+ * Clear all drawn annotations from current annotation layer.
1116
+ */
1117
+ clearAnnotationFeature()
1118
+ //======================
1119
+ {
1120
+ if (this._userInteractions) {
1121
+ this._userInteractions.clearAnnotationFeature()
1122
+ }
1123
+ }
1113
1124
 
1114
1125
  /**
1115
1126
  * Add a drawn feature to the annotation drawing tool.
@@ -268,6 +268,7 @@ export class UserInteractions
268
268
  // Handle mouse events
269
269
 
270
270
  this._map.on('click', this.clickEvent_.bind(this));
271
+ this._map.on('touchend', this.clickEvent_.bind(this));
271
272
  this._map.on('mousemove', this.mouseMoveEvent_.bind(this));
272
273
  this._lastFeatureMouseEntered = null;
273
274
  this._lastFeatureModelsMouse = null;
@@ -332,6 +333,14 @@ export class UserInteractions
332
333
  }
333
334
  }
334
335
 
336
+ inDrawingAnnotationMode()
337
+ //=======================
338
+ {
339
+ if (this.#annotationDrawControl) {
340
+ return this.#annotationDrawControl.inDrawingMode()
341
+ }
342
+ }
343
+
335
344
  commitAnnotationEvent(event)
336
345
  //==========================
337
346
  {
@@ -340,14 +349,30 @@ export class UserInteractions
340
349
  }
341
350
  }
342
351
 
352
+ abortAnnotationEvent(event)
353
+ //=========================
354
+ {
355
+ if (this.#annotationDrawControl) {
356
+ this.#annotationDrawControl.abortEvent(event)
357
+ }
358
+ }
359
+
343
360
  rollbackAnnotationEvent(event)
344
- //==========================
361
+ //============================
345
362
  {
346
363
  if (this.#annotationDrawControl) {
347
364
  this.#annotationDrawControl.rollbackEvent(event)
348
365
  }
349
366
  }
350
367
 
368
+ clearAnnotationFeature()
369
+ //======================
370
+ {
371
+ if (this.#annotationDrawControl) {
372
+ this.#annotationDrawControl.clearFeature()
373
+ }
374
+ }
375
+
351
376
  addAnnotationFeature(feature)
352
377
  //===========================
353
378
  {
@@ -788,7 +813,8 @@ export class UserInteractions
788
813
  //=======================================
789
814
  {
790
815
  const ann = this._flatmap.annotation(featureId);
791
- if (ann) { // The feature exists
816
+ const drawn = options && options.annotationFeatureGeometry;
817
+ if (ann || drawn) { // The feature exists or it is a drawn annotation
792
818
 
793
819
  // Remove any existing popup
794
820
 
@@ -818,6 +844,10 @@ export class UserInteractions
818
844
  && options.positionAtLastClick
819
845
  && this.__lastClickLngLat !== null) {
820
846
  location = this.__lastClickLngLat;
847
+ } else if (drawn) {
848
+ // Popup at the centroid of the feature
849
+ // Calculated with the feature geometry coordinates
850
+ location = options.annotationFeatureGeometry;
821
851
  } else {
822
852
  // Position popup at the feature's 'centre'
823
853
  location = this.__markerPosition(featureId, ann);
@@ -831,6 +861,9 @@ export class UserInteractions
831
861
  this.setModal_();
832
862
  this._currentPopup = new maplibregl.Popup(options).addTo(this._map);
833
863
  this._currentPopup.on('close', this.__onCloseCurrentPopup.bind(this));
864
+ if (drawn) {
865
+ this._currentPopup.on('close', this.abortAnnotationEvent.bind(this));
866
+ }
834
867
  this._currentPopup.setLngLat(location);
835
868
  if (typeof content === 'object') {
836
869
  this._currentPopup.setDOMContent(content);
@@ -1160,14 +1193,20 @@ export class UserInteractions
1160
1193
  this.unselectFeatures();
1161
1194
  return;
1162
1195
  }
1163
- const clickedFeature = clickedFeatures[0];
1196
+ const inDrawing = this.inDrawingAnnotationMode()
1197
+ const clickedDrawnFeature = clickedFeatures.filter((f) => !f.id)[0];
1198
+ const clickedFeature = clickedFeatures.filter((f) => f.id)[0];
1164
1199
  this.selectionEvent_(event.originalEvent, clickedFeature);
1165
1200
  if (this._modal) {
1166
1201
  // Remove tooltip, reset active features, etc
1167
1202
  this.__resetFeatureDisplay();
1168
1203
  this.unselectFeatures();
1169
1204
  this.__clearModal();
1170
- } else if (clickedFeature !== undefined) {
1205
+ } else if (clickedDrawnFeature && !inDrawing) {
1206
+ // When feature and drawn feature are coinciding, click on annotation layer by default
1207
+ // While in drawing, DISABLE 'click' event on annotation layer
1208
+ this.__featureEvent('click', clickedDrawnFeature);
1209
+ } else if (clickedFeature) {
1171
1210
  this.__lastClickLngLat = event.lngLat;
1172
1211
  this.__featureEvent('click', clickedFeature);
1173
1212
  if ('properties' in clickedFeature && 'hyperlink' in clickedFeature.properties) {
package/src/main.js CHANGED
@@ -147,6 +147,7 @@ export async function standaloneViewer(map_endpoint=null, options={})
147
147
  map.addMarker('UBERON:0000945'); // Stomach
148
148
  map.addMarker('UBERON:0001155'); // Colon
149
149
  map.addMarker('UBERON:0001255'); // Bladder
150
+ map.addMarker('UBERON:0001759'); // Vagus
150
151
  currentMap = map;
151
152
  drawControl = new DrawControl(map)
152
153
  })