@abi-software/flatmap-viewer 2.4.4 → 2.5.0-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/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.4``
41
+ * ``npm install @abi-software/flatmap-viewer@2.5.0-a.1``
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.4",
3
+ "version": "2.5.0-a.1",
4
4
  "description": "Flatmap viewer using Maplibre GL",
5
5
  "repository": "https://github.com/AnatomicMaps/flatmap-viewer.git",
6
6
  "main": "src/main.js",
@@ -18,12 +18,16 @@
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.10.4",
21
+ "@deck.gl/core": "^8.9.33",
22
+ "@deck.gl/layers": "^8.9.33",
23
+ "@deck.gl/mapbox": "^8.9.33",
21
24
  "@fortawesome/fontawesome-free": "^6.4.0",
22
25
  "@turf/area": "^6.5.0",
23
26
  "@turf/bbox": "^6.5.0",
24
27
  "@turf/helpers": "^6.5.0",
25
28
  "@turf/projection": "^6.5.0",
26
29
  "bezier-js": "^6.1.0",
30
+ "colord": "^2.9.3",
27
31
  "html-es6cape": "^2.0.2",
28
32
  "maplibre-gl": ">=3.6.0",
29
33
  "mathjax-full": "^3.2.2",
@@ -170,8 +170,8 @@ class FlatMap
170
170
 
171
171
  // Disable map rotation
172
172
 
173
- this._map.dragRotate.disable();
174
- this._map.touchZoomRotate.disableRotation();
173
+ //this._map.dragRotate.disable();
174
+ //this._map.touchZoomRotate.disableRotation();
175
175
 
176
176
  // Add navigation controls if option set
177
177
 
@@ -22,6 +22,10 @@ limitations under the License.
22
22
 
23
23
  //==============================================================================
24
24
 
25
+ import {colord} from "colord";
26
+
27
+ import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox';
28
+ import {ArcLayer} from '@deck.gl/layers';
25
29
  import maplibregl from 'maplibre-gl';
26
30
 
27
31
  import {default as turfArea} from '@turf/area';
@@ -34,7 +38,7 @@ import polylabel from 'polylabel';
34
38
  //==============================================================================
35
39
 
36
40
  import {LayerManager} from './layers';
37
- import {PATHWAYS_LAYER, PathManager} from './pathways';
41
+ import {pathColour, PATHWAYS_LAYER, PathManager} from './pathways';
38
42
  import {VECTOR_TILES_SOURCE} from './styling';
39
43
  import {SystemsManager} from './systems';
40
44
 
@@ -116,6 +120,13 @@ function getRenderedLabel(properties)
116
120
  return properties.renderedLabel;
117
121
  }
118
122
 
123
+ // Should this be in `pathways.js` ??
124
+ function pathColourRGB(pathType, alpha=255)
125
+ {
126
+ const rgb = colord(pathColour(pathType)).toRgb();
127
+ return [rgb.r, rgb.g, rgb.b, alpha];
128
+ }
129
+
119
130
  //==============================================================================
120
131
 
121
132
  export class UserInteractions
@@ -216,6 +227,72 @@ export class UserInteractions
216
227
  }
217
228
  }
218
229
 
230
+ const pathData = [...flatmap.annotations.values()]
231
+ .filter(ann => ann['tile-layer'] === 'pathways'
232
+ && ann['geometry'] === 'LineString'
233
+ && 'type' in ann && ann['type'].startsWith('line')
234
+ && 'kind' in ann && !ann['kind'].includes('arterial') && !ann['kind'].includes('venous')
235
+ && 'pathStartPosition' in ann
236
+ && 'pathEndPosition' in ann)
237
+
238
+ /*
239
+ {
240
+ "featureId": 37,
241
+ "id": "ilxtr_neuron-type-keast-10",
242
+ "kind": "sensory",
243
+ "label": "L6-S1 sensory neuron innervating bladder",
244
+ "models": "ilxtr:neuron-type-keast-10",
245
+ "sckan": true,
246
+ "source": "https://apinatomy.org/uris/models/keast-bladder",
247
+ "taxons": ["NCBITaxon:10116"],
248
+ "tile-layer": "pathways",
249
+ "type": "line",
250
+ "bounds": [1.5454426659162825, -1.6254174813389017, 1.7478459571498208, -1.3632864333949712],
251
+ "markerPosition": [1.6466443115330516, -1.4943519573669364],
252
+ "geometry": "LineString",
253
+ "layer": "neural-routes",
254
+ "pathStartPosition": [1.7478459571498208, -1.3632864333949712],
255
+ "pathEndPosition": [1.5454426659162825, -1.6254174813389017]
256
+ }
257
+ */
258
+
259
+ const deckOverlay = new DeckOverlay({
260
+ layers: [
261
+ new ArcLayer({
262
+ id: 'arcs',
263
+ data: pathData,
264
+ pickable: true,
265
+ autoHighlight: true,
266
+ numSegments: 100,
267
+ onHover: (i, e) => {
268
+ //console.log('hover', i, e)
269
+ if (i.object) {
270
+ const lineFeatureId = +i.object.featureId;
271
+ this.__activateFeature(this.mapFeature(lineFeatureId));
272
+ for (const featureId of this.__pathManager.lineFeatureIds([lineFeatureId])) {
273
+ if (+featureId !== lineFeatureId) {
274
+ this.__activateFeature(this.mapFeature(featureId));
275
+ }
276
+ }
277
+ }
278
+ },
279
+ onClick: (i, e) => {
280
+ console.log('click', i, e)
281
+ },
282
+ // Styles
283
+ getSourcePosition: f => f.pathStartPosition,
284
+ getTargetPosition: f => f.pathEndPosition,
285
+ getSourceColor: f => pathColourRGB(f.kind, 160),
286
+ getTargetColor: f => pathColourRGB(f.kind, 160),
287
+ highlightColor: o => pathColourRGB(o.object.kind),
288
+ getWidth: 3
289
+ })
290
+ ],
291
+ getTooltip: ({object}) => object && object.label
292
+ });
293
+
294
+ this._map.addControl(deckOverlay);
295
+
219
296
  // Handle mouse events
220
297
 
221
298
  this._map.on('click', this.clickEvent_.bind(this));
@@ -515,7 +592,6 @@ export class UserInteractions
515
592
  this.__clearModal();
516
593
  this.__clearActiveMarker();
517
594
  this.unselectFeatures();
518
- this.__enablePathFeatures(this.__pathManager.allFeatureIds(), true);
519
595
  }
520
596
 
521
597
  clearSearchResults(reset=true)
package/src/pathways.js CHANGED
@@ -52,6 +52,14 @@ const PATH_TYPES = [
52
52
  export const PATH_STYLE_RULES =
53
53
  PATH_TYPES.flatMap(pathType => [['==', ['get', 'kind'], pathType.type], pathType.colour]);
54
54
 
55
+ export const PATH_COLOURS =
56
+ Object.fromEntries(PATH_TYPES.flatMap(pathType => [[pathType.type, pathType.colour]]));
57
+
58
+ export function pathColour(pathType)
59
+ {
60
+ return PATH_COLOURS[pathType] || '#FF0';
61
+ }
62
+
55
63
  //==============================================================================
56
64
 
57
65
  export class PathManager