@abi-software/flatmap-viewer 2.5.6 → 2.5.8

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.6``
41
+ * ``npm install @abi-software/flatmap-viewer@2.5.8``
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.6",
3
+ "version": "2.5.8",
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",
@@ -21,6 +24,7 @@
21
24
  "@deck.gl/core": "^8.9.33",
22
25
  "@deck.gl/layers": "^8.9.33",
23
26
  "@deck.gl/mapbox": "^8.9.33",
27
+ "@mapbox/mapbox-gl-draw": "^1.4.3",
24
28
  "@turf/area": "^6.5.0",
25
29
  "@turf/bbox": "^6.5.0",
26
30
  "@turf/helpers": "^6.5.0",
@@ -38,7 +42,7 @@
38
42
  "@babel/plugin-transform-runtime": "^7.5.5",
39
43
  "@babel/preset-env": "^7.10.4",
40
44
  "babel-loader": "^8.1.0",
41
- "browser-sync": "^3.0.2",
45
+ "browser-sync": "^2.26.7",
42
46
  "bs-fullscreen-message": "^1.1.0",
43
47
  "clean-webpack-plugin": "^3.0.0",
44
48
  "css-loader": "^6.7.3",
@@ -96,6 +96,7 @@ export class AnnotationDrawControl
96
96
  e.preventDefault();
97
97
  }
98
98
  }, false)
99
+ map.on('draw.modechange', this.featureModeChanged.bind(this))
99
100
  map.on('draw.create', this.createdFeature.bind(this))
100
101
  map.on('draw.delete', this.deletedFeature.bind(this))
101
102
  map.on('draw.update', this.updatedFeature.bind(this))
@@ -146,7 +147,10 @@ export class AnnotationDrawControl
146
147
  #sendEvent(type, feature)
147
148
  //=======================
148
149
  {
149
- this.__uncommittedFeatureIds.add(feature.id)
150
+ if (feature.id) {
151
+ // Add when the event is 'created', 'updated' or 'deleted'
152
+ this.__uncommittedFeatureIds.add(feature.id)
153
+ }
150
154
  this.__flatmap.annotationEvent(type, feature)
151
155
  }
152
156
 
@@ -193,6 +197,13 @@ export class AnnotationDrawControl
193
197
  }
194
198
  }
195
199
 
200
+ featureModeChanged(event)
201
+ //=======================
202
+ {
203
+ // Used as a flag to indicate the feature mode
204
+ this.#sendEvent('modeChanged', event)
205
+ }
206
+
196
207
  commitEvent(event)
197
208
  //================
198
209
  {
@@ -205,6 +216,14 @@ export class AnnotationDrawControl
205
216
  this.__uncommittedFeatureIds.delete(feature.id)
206
217
  }
207
218
 
219
+ abortEvent(event)
220
+ //===============
221
+ {
222
+ // Used as a flag to indicate the popup is closed
223
+ // Rollback should be performed when triggered 'aborted' event
224
+ this.#sendEvent('aborted', event)
225
+ }
226
+
208
227
  rollbackEvent(event)
209
228
  //==================
210
229
  {
@@ -226,6 +245,12 @@ export class AnnotationDrawControl
226
245
  }
227
246
  }
228
247
  }
248
+
249
+ clearFeature()
250
+ //============
251
+ {
252
+ this.__draw.deleteAll()
253
+ }
229
254
 
230
255
  addFeature(feature)
231
256
  //=================
@@ -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;
@@ -340,14 +341,30 @@ export class UserInteractions
340
341
  }
341
342
  }
342
343
 
344
+ abortAnnotationEvent(event)
345
+ //=========================
346
+ {
347
+ if (this.#annotationDrawControl) {
348
+ this.#annotationDrawControl.abortEvent(event)
349
+ }
350
+ }
351
+
343
352
  rollbackAnnotationEvent(event)
344
- //==========================
353
+ //============================
345
354
  {
346
355
  if (this.#annotationDrawControl) {
347
356
  this.#annotationDrawControl.rollbackEvent(event)
348
357
  }
349
358
  }
350
359
 
360
+ clearAnnotationFeature()
361
+ //======================
362
+ {
363
+ if (this.#annotationDrawControl) {
364
+ this.#annotationDrawControl.clearFeature()
365
+ }
366
+ }
367
+
351
368
  addAnnotationFeature(feature)
352
369
  //===========================
353
370
  {
@@ -788,7 +805,8 @@ export class UserInteractions
788
805
  //=======================================
789
806
  {
790
807
  const ann = this._flatmap.annotation(featureId);
791
- if (ann) { // The feature exists
808
+ const drawn = options && options.annotationFeatureGeometry;
809
+ if (ann || drawn) { // The feature exists or it is a drawn annotation
792
810
 
793
811
  // Remove any existing popup
794
812
 
@@ -818,6 +836,10 @@ export class UserInteractions
818
836
  && options.positionAtLastClick
819
837
  && this.__lastClickLngLat !== null) {
820
838
  location = this.__lastClickLngLat;
839
+ } else if (drawn) {
840
+ // Popup at the centroid of the feature
841
+ // Calculated with the feature geometry coordinates
842
+ location = options.annotationFeatureGeometry;
821
843
  } else {
822
844
  // Position popup at the feature's 'centre'
823
845
  location = this.__markerPosition(featureId, ann);
@@ -831,6 +853,9 @@ export class UserInteractions
831
853
  this.setModal_();
832
854
  this._currentPopup = new maplibregl.Popup(options).addTo(this._map);
833
855
  this._currentPopup.on('close', this.__onCloseCurrentPopup.bind(this));
856
+ if (drawn) {
857
+ this._currentPopup.on('close', this.abortAnnotationEvent.bind(this));
858
+ }
834
859
  this._currentPopup.setLngLat(location);
835
860
  if (typeof content === 'object') {
836
861
  this._currentPopup.setDOMContent(content);
@@ -1160,7 +1185,8 @@ export class UserInteractions
1160
1185
  this.unselectFeatures();
1161
1186
  return;
1162
1187
  }
1163
- const clickedFeature = clickedFeatures[0];
1188
+ const clickedFeature = clickedFeatures.filter((f)=>f.id)[0];
1189
+ const clickedDrawnFeature = clickedFeatures.filter((f)=>!f.id)[0];
1164
1190
  this.selectionEvent_(event.originalEvent, clickedFeature);
1165
1191
  if (this._modal) {
1166
1192
  // Remove tooltip, reset active features, etc
@@ -1173,6 +1199,8 @@ export class UserInteractions
1173
1199
  if ('properties' in clickedFeature && 'hyperlink' in clickedFeature.properties) {
1174
1200
  window.open(clickedFeature.properties.hyperlink, '_blank');
1175
1201
  }
1202
+ } else if (clickedDrawnFeature !== undefined) {
1203
+ this.__featureEvent('click', clickedDrawnFeature);
1176
1204
  }
1177
1205
  }
1178
1206
 
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
  })