@abi-software/flatmap-viewer 2.2.11-devel.1 → 2.2.11-devel.2

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/src/layers.js CHANGED
@@ -20,9 +20,6 @@ limitations under the License.
20
20
 
21
21
  'use strict';
22
22
 
23
-
24
- // See https://stevage.github.io/map-gl-utils/ for layering ideas...
25
-
26
23
  //==============================================================================
27
24
 
28
25
  import {PATHWAYS_LAYER} from './pathways.js';
@@ -38,12 +35,13 @@ const RASTER_LAYERS_ID = 'background-image-layer';
38
35
 
39
36
  class MapStylingLayers
40
37
  {
41
- constructor(flatmap, layerId, options)
38
+ constructor(flatmap, layer, options)
42
39
  {
43
40
  this.__map = flatmap.map;
44
- this.__id = layerId;
45
- this.__layers = [];
41
+ this.__id = layer.id;
42
+ this.__description = layer.description;
46
43
  this.__active = true;
44
+ this.__layers = [];
47
45
  this.__layerOptions = options;
48
46
  this.__separateLayers = flatmap.options.separateLayers;
49
47
  }
@@ -54,6 +52,12 @@ class MapStylingLayers
54
52
  return this.__id;
55
53
  }
56
54
 
55
+ get description()
56
+ //===============
57
+ {
58
+ return this.__description;
59
+ }
60
+
57
61
  get active()
58
62
  //==========
59
63
  {
@@ -88,6 +92,16 @@ class MapStylingLayers
88
92
  return this.__separateLayers ? `${this.__id}_${sourceLayer}`
89
93
  : sourceLayer;
90
94
  }
95
+
96
+ setColour(options)
97
+ {
98
+
99
+ }
100
+
101
+ setFilter(options)
102
+ {
103
+
104
+ }
91
105
  }
92
106
 
93
107
  //==============================================================================
@@ -96,7 +110,7 @@ class MapFeatureLayers extends MapStylingLayers
96
110
  {
97
111
  constructor(flatmap, layer, options)
98
112
  {
99
- super(flatmap, layer.id, options);
113
+ super(flatmap, layer, options);
100
114
  const vectorTileSource = this.__map.getSource('vector-tiles');
101
115
  const haveVectorLayers = (typeof vectorTileSource !== 'undefined');
102
116
 
@@ -111,7 +125,7 @@ class MapFeatureLayers extends MapStylingLayers
111
125
  this.__addStyleLayer(style.FeatureLineLayer);
112
126
  this.__addStyleLayer(style.FeatureBorderLayer);
113
127
  }
114
- this.__addPathwayStyleLayers(this.__layerOptions);
128
+ this.__addPathwayStyleLayers();
115
129
  if (vectorFeatures) {
116
130
  this.__addStyleLayer(style.FeatureLargeSymbolLayer);
117
131
  if (!flatmap.options.tooltips) {
@@ -141,8 +155,12 @@ class MapFeatureLayers extends MapStylingLayers
141
155
  if (this.__map.getSource('vector-tiles')
142
156
  .vectorLayerIds
143
157
  .indexOf(pathwaysVectorSource) >= 0) {
158
+ this.__addStyleLayer(style.CentrelineEdgeLayer, PATHWAYS_LAYER);
159
+ this.__addStyleLayer(style.CentrelineTrackLayer, PATHWAYS_LAYER);
160
+
144
161
  this.__addStyleLayer(style.PathLineLayer, PATHWAYS_LAYER);
145
162
  this.__addStyleLayer(style.PathDashlineLayer, PATHWAYS_LAYER);
163
+
146
164
  this.__addStyleLayer(style.NervePolygonBorder, PATHWAYS_LAYER);
147
165
  this.__addStyleLayer(style.NervePolygonFill, PATHWAYS_LAYER);
148
166
  this.__addStyleLayer(style.FeatureNerveLayer, PATHWAYS_LAYER);
@@ -159,6 +177,17 @@ class MapFeatureLayers extends MapStylingLayers
159
177
  }
160
178
  }
161
179
  }
180
+
181
+ setFilter(options)
182
+ //================
183
+ {
184
+ for (const layer of this.__layers) {
185
+ const filter = layer.makeFilter(options);
186
+ if (filter !== null) {
187
+ this.__map.setFilter(layer.id, filter, {validate: true});
188
+ }
189
+ }
190
+ }
162
191
  }
163
192
 
164
193
  //==============================================================================
@@ -167,7 +196,11 @@ class MapRasterLayers extends MapStylingLayers
167
196
  {
168
197
  constructor(flatmap, options, bodyLayerId=null)
169
198
  {
170
- super(flatmap, RASTER_LAYERS_ID, options);
199
+ const rasterLayer = {
200
+ id: RASTER_LAYERS_ID,
201
+ description: RASTER_LAYERS_NAME
202
+ };
203
+ super(flatmap, rasterLayer, options);
171
204
  if (bodyLayerId !== null) {
172
205
  const layerId = `${bodyLayerId}_${FEATURES_LAYER}`;
173
206
  const source = flatmap.options.separateLayers ? layerId : FEATURES_LAYER;
@@ -212,11 +245,11 @@ export class LayerManager
212
245
  {
213
246
  this.__flatmap = flatmap;
214
247
  this.__map = flatmap.map;
215
- this.__layers = new Map;
216
248
  this.__mapLayers = new Map;
217
249
  this.__layerOptions = utils.setDefaults(flatmap.options.layerOptions, {
218
250
  colour: true,
219
- outline: true
251
+ outline: true,
252
+ sckan: 'valid'
220
253
  });;
221
254
  const backgroundLayer = new style.BackgroundLayer();
222
255
  if ('background' in flatmap.options) {
@@ -237,44 +270,29 @@ export class LayerManager
237
270
  for (const layer of flatmap.layers) {
238
271
  rasterLayers.addLayer(layer);
239
272
  }
240
- this.__layers.set(RASTER_LAYERS_ID, {
241
- id: RASTER_LAYERS_ID,
242
- description: RASTER_LAYERS_NAME
243
- });
244
273
  this.__mapLayers.set(RASTER_LAYERS_ID, rasterLayers);
245
274
  } else {
246
275
  this.__layerOptions.activeRasterLayer = false;
247
276
  }
248
277
  for (const layer of flatmap.layers) {
249
- this.__addFeatureLayer(layer);
250
- }
251
- }
252
-
253
- get activeLayerNames()
254
- //====================
255
- {
256
- const activeNames = [];
257
- for (const mapLayer of this.__mapLayers.values()) {
258
- if (mapLayer.active) {
259
- activeNames.push(mapLayer.id);
260
- }
278
+ this.__mapLayers.set(layer.id, new MapFeatureLayers(this.__flatmap,
279
+ layer,
280
+ this.__layerOptions));
261
281
  }
262
- return activeNames;
263
- }
264
-
265
- __addFeatureLayer(layer)
266
- //======================
267
- {
268
- this.__layers.set(layer.id, layer);
269
- this.__mapLayers.set(layer.id, new MapFeatureLayers(this.__flatmap,
270
- layer,
271
- this.__layerOptions));
272
282
  }
273
283
 
274
284
  get layers()
275
285
  //==========
276
286
  {
277
- return Array.from(this.__layers.values());
287
+ const layers = [];
288
+ for (const mapLayer of this.__mapLayers.values()) {
289
+ layers.push({
290
+ id: mapLayer.id,
291
+ description: mapLayer.description,
292
+ enabled: mapLayer.active
293
+ });
294
+ }
295
+ return layers;
278
296
  }
279
297
 
280
298
  activate(layerId, enable=true)
@@ -294,14 +312,23 @@ export class LayerManager
294
312
  }
295
313
  }
296
314
 
297
- setColour(options=null)
298
- //=====================
315
+ setColour(options={})
316
+ //===================
299
317
  {
300
318
  this.__layerOptions = utils.setDefaults(options, this.__layerOptions);
301
319
  for (const mapLayer of this.__mapLayers.values()) {
302
320
  mapLayer.setColour(this.__layerOptions);
303
321
  }
304
322
  }
323
+
324
+ setFilter(options={})
325
+ //===================
326
+ {
327
+ this.__layerOptions = utils.setDefaults(options, this.__layerOptions);
328
+ for (const mapLayer of this.__mapLayers.values()) {
329
+ mapLayer.setFilter(this.__layerOptions);
330
+ }
331
+ }
305
332
  }
306
333
 
307
334
  //==============================================================================
package/src/main.js CHANGED
@@ -57,14 +57,10 @@ export async function standaloneViewer(map_endpoint=null, options={})
57
57
  const mapOptions = Object.assign({
58
58
  tooltips: true,
59
59
  background: defaultBackground,
60
- backgroundControl: true,
61
60
  debug: false,
62
61
  minimap: false,
63
- searchable: true,
64
- featureInfo: true,
65
62
  showPosition: false,
66
- pathControls: true,
67
- layerControl: true
63
+ standalone: true
68
64
  }, options);
69
65
 
70
66
  function loadMap(id, taxon, sex)
@@ -92,8 +88,6 @@ export async function standaloneViewer(map_endpoint=null, options={})
92
88
  mapManager.loadMap(id, 'map-canvas', (eventType, ...args) => {
93
89
  if (args[0].type === 'control' && args[0].control === 'background') {
94
90
  mapOptions.background = args[0].value;
95
- } else if (eventType === 'click') {
96
- console.log(args);
97
91
  }
98
92
  }, mapOptions)
99
93
  .then(map => {
package/src/minimap.js CHANGED
@@ -300,7 +300,7 @@ export class MinimapControl
300
300
  const newBounds = this.moveTrackingRect_(offset);
301
301
 
302
302
  this._map.fitBounds(newBounds, {
303
- duration: 80, // Why these options??
303
+ duration: 80,
304
304
  noMoveStart: true
305
305
  });
306
306
  }
package/src/pathways.js CHANGED
@@ -29,7 +29,6 @@ export const PATHWAYS_LAYER = 'pathways';
29
29
  export const PATH_TYPES = [
30
30
  { type: "cns", label: "CNS", colour: "#9B1FC1"},
31
31
  { type: "intracardiac", label: "Local circuit neuron", colour: "#F19E38"},
32
- { type: "lcn", label: "Local circuit neuron", colour: "#F19E38"},
33
32
  { type: "para-pre", label: "Parasympathetic pre-ganglionic", colour: "#3F8F4A"},
34
33
  { type: "para-post", label: "Parasympathetic post-ganglionic", colour: "#3F8F4A"},
35
34
  { type: "sensory", label: "Sensory (afferent) neuron", colour: "#2A62F6"},
@@ -38,7 +37,8 @@ export const PATH_TYPES = [
38
37
  { type: "symp-post", label: "Sympathetic post-ganglionic", colour: "#EA3423"},
39
38
  { type: "other", label: "Other neuron type", colour: "#888"},
40
39
  { type: "arterial", label: "Arterial blood vessel", colour: "#F00"},
41
- { type: "venous", label: "Venous blood vessel", colour: "#2F6EBA"}
40
+ { type: "venous", label: "Venous blood vessel", colour: "#2F6EBA"},
41
+ { type: "centreline", label: "Nerve centrelines", colour: "#2F6EBA", enabled: false}
42
42
  ];
43
43
 
44
44
  export const PATH_STYLE_RULES =
package/src/search.js CHANGED
@@ -29,7 +29,6 @@ import MiniSearch from 'minisearch';
29
29
  // The properties of a feature we index and show
30
30
 
31
31
  export const indexedProperties = [
32
- 'id',
33
32
  'label',
34
33
  'models',
35
34
  'source'
package/src/styling.js CHANGED
@@ -44,6 +44,11 @@ class VectorStyleLayer
44
44
  return this.__id;
45
45
  }
46
46
 
47
+ makeFilter(options)
48
+ {
49
+ return null;
50
+ }
51
+
47
52
  paintStyle(options, changes=false)
48
53
  {
49
54
  return {};
@@ -184,7 +189,7 @@ export class FeatureBorderLayer extends VectorStyleLayer
184
189
  const activeRasterLayer = 'activeRasterLayer' in options && options.activeRasterLayer;
185
190
  const lineColour = [ 'case' ];
186
191
  lineColour.push(['boolean', ['feature-state', 'selected'], false]);
187
- lineColour.push('red');
192
+ lineColour.push('black');
188
193
  if (coloured && outlined) {
189
194
  lineColour.push(['boolean', ['feature-state', 'active'], false]);
190
195
  lineColour.push('blue');
@@ -193,7 +198,6 @@ export class FeatureBorderLayer extends VectorStyleLayer
193
198
  lineColour.push('#000');
194
199
  lineColour.push(['has', 'node']);
195
200
  lineColour.push('#AFA202');
196
- // this colour should be complement of background colour...
197
201
  lineColour.push('#444');
198
202
 
199
203
  const lineOpacity = [
@@ -251,25 +255,32 @@ export class FeatureBorderLayer extends VectorStyleLayer
251
255
 
252
256
  export class FeatureLineLayer extends VectorStyleLayer
253
257
  {
254
- constructor(id, sourceLayer, dashed=false)
258
+ constructor(id, sourceLayer, options={})
255
259
  {
260
+ const dashed = ('dashed' in options && options.dashed);
256
261
  const filterType = dashed ? 'line-dash' : 'line';
257
262
  super(id, `feature-${filterType}`, sourceLayer);
258
- this.__filter = dashed ?
259
- [
260
- 'any',
261
- ['==', 'type', `line-dash`]
262
- ]
263
- :
263
+ this.__dashed = dashed;
264
+ }
265
+
266
+ makeFilter(options={})
267
+ {
268
+ return this.__dashed ? [
269
+ 'all',
270
+ ['==', '$type', 'LineString'],
271
+ ['==', 'type', `line-dash`]
272
+ ] : [
273
+ 'all',
274
+ ['==', '$type', 'LineString'],
264
275
  [
265
276
  'any',
266
277
  ['==', 'type', 'bezier'],
267
278
  ['==', 'type', `line`]
268
- ];
269
- this.__dashed = dashed;
279
+ ]
280
+ ];
270
281
  }
271
282
 
272
- paintStyle(options)
283
+ paintStyle(options, changes=false)
273
284
  {
274
285
  const coloured = !('colour' in options) || options.colour;
275
286
  const paintStyle = {
@@ -311,7 +322,7 @@ export class FeatureLineLayer extends VectorStyleLayer
311
322
  if (this.__dashed) {
312
323
  paintStyle['line-dasharray'] = [3, 2];
313
324
  }
314
- return paintStyle;
325
+ return super.changedPaintStyle(paintStyle, changes);
315
326
  }
316
327
 
317
328
  style(options)
@@ -319,12 +330,7 @@ export class FeatureLineLayer extends VectorStyleLayer
319
330
  return {
320
331
  ...super.style(),
321
332
  'type': 'line',
322
- 'filter': [
323
- 'all',
324
- ['==', '$type', 'LineString'],
325
- this.__filter
326
- // not for paths...
327
- ],
333
+ 'filter': this.makeFilter(options),
328
334
  'paint': this.paintStyle(options)
329
335
  };
330
336
  }
@@ -336,7 +342,7 @@ export class FeatureDashLineLayer extends FeatureLineLayer
336
342
  {
337
343
  constructor(id, sourceLayer)
338
344
  {
339
- super(id, sourceLayer, true);
345
+ super(id, sourceLayer, {dashed: true});
340
346
  }
341
347
  }
342
348
 
@@ -344,26 +350,63 @@ export class FeatureDashLineLayer extends FeatureLineLayer
344
350
 
345
351
  export class PathLineLayer extends VectorStyleLayer
346
352
  {
347
- constructor(id, sourceLayer, dashed=false)
353
+ constructor(id, sourceLayer, options={})
348
354
  {
355
+ const dashed = ('dashed' in options && options.dashed);
349
356
  const filterType = dashed ? 'line-dash' : 'line';
350
357
  super(id, `path-${filterType}`, sourceLayer);
351
- this.__filter = dashed ?
352
- [
358
+ this.__dashed = dashed;
359
+ }
360
+
361
+ makeFilter(options={})
362
+ {
363
+ const sckanState = !'sckan' in options ? 'all'
364
+ : options.sckan.toLowerCase();
365
+ const sckan_filter =
366
+ sckanState == 'none' ? [
367
+ ['!has', 'sckan']
368
+ ] :
369
+ sckanState == 'valid' ? [[
353
370
  'any',
354
- ['==', 'type', `line-dash`]
355
- ]
356
- :
371
+ ['!has', 'sckan'],
372
+ [
373
+ 'all',
374
+ ['has', 'sckan'],
375
+ ['==', 'sckan', true]
376
+ ]
377
+ ]] :
378
+ sckanState == 'invalid' ? [[
379
+ 'any',
380
+ ['!has', 'sckan'],
381
+ [
382
+ 'all',
383
+ ['has', 'sckan'],
384
+ ['!=', 'sckan', true]
385
+ ]
386
+ ]] :
387
+ [ ];
388
+
389
+ return this.__dashed ? [
390
+ 'all',
391
+ ['==', '$type', 'LineString'],
392
+ ['==', 'type', `line-dash`],
393
+ ...sckan_filter
394
+ ] : [
395
+ 'all',
396
+ ['==', '$type', 'LineString'],
357
397
  [
358
398
  'any',
359
399
  ['==', 'type', 'bezier'],
360
- ['==', 'type', 'centreline'],
361
- ['==', 'type', `line`]
362
- ];
363
- this.__dashed = dashed;
400
+ [
401
+ 'all',
402
+ ['==', 'type', `line`],
403
+ ...sckan_filter
404
+ ]
405
+ ]
406
+ ];
364
407
  }
365
408
 
366
- paintStyle(options, changes=false)
409
+ paintStyle(options={}, changes=false)
367
410
  {
368
411
  const dimmed = 'dimmed' in options && options.dimmed;
369
412
  const paintStyle = {
@@ -372,7 +415,6 @@ export class PathLineLayer extends VectorStyleLayer
372
415
  ['boolean', ['feature-state', 'selected'], false], '#0F0',
373
416
  ['boolean', ['feature-state', 'hidden'], false], '#CCC',
374
417
  ['==', ['get', 'type'], 'bezier'], 'red',
375
- ['==', ['get', 'type'], 'centreline'], '#00F',
376
418
  ['has', 'error'], '#FFFE0E',
377
419
  ['==', ['get', 'kind'], 'unknown'], '#888',
378
420
  ...PATH_STYLE_RULES,
@@ -385,7 +427,6 @@ export class PathLineLayer extends VectorStyleLayer
385
427
  ['boolean', ['get', 'invisible'], false], 0.001,
386
428
  ['boolean', ['feature-state', 'selected'], false], 1.0,
387
429
  ['boolean', ['feature-state', 'active'], false], 1.0,
388
- // Only dim lines when other lines are selected, not if just features selected??
389
430
  dimmed ? 0.1 : 0.8
390
431
  ],
391
432
  'line-width': [
@@ -416,16 +457,12 @@ export class PathLineLayer extends VectorStyleLayer
416
457
  return super.changedPaintStyle(paintStyle, changes);
417
458
  }
418
459
 
419
- style(options)
460
+ style(options={})
420
461
  {
421
462
  return {
422
463
  ...super.style(),
423
464
  'type': 'line',
424
- 'filter': [
425
- 'all',
426
- ['==', '$type', 'LineString'],
427
- this.__filter
428
- ],
465
+ 'filter': this.makeFilter(options),
429
466
  'layout': {
430
467
  'line-cap': 'butt'
431
468
  },
@@ -440,12 +477,97 @@ export class PathDashlineLayer extends PathLineLayer
440
477
  {
441
478
  constructor(id, sourceLayer)
442
479
  {
443
- super(id, sourceLayer, true);
480
+ super(id, sourceLayer, {dashed: true});
444
481
  }
445
482
  }
446
483
 
447
484
  //==============================================================================
448
485
 
486
+ class CentrelineLayer extends VectorStyleLayer
487
+ {
488
+ constructor(id, type, sourceLayer)
489
+ {
490
+ super(id, `centreline-${type}`, sourceLayer);
491
+ this.__type = type;
492
+ }
493
+
494
+ paintStyle(options, changes=false)
495
+ {
496
+ const coloured = !('colour' in options) || options.colour;
497
+ const paintStyle = {
498
+ 'line-color': (this.__type == 'edge') ? '#000' : [
499
+ 'case',
500
+ ['boolean', ['feature-state', 'selected'], false], '#0F0',
501
+ ['boolean', ['feature-state', 'active'], false], '#444',
502
+ '#CCC'
503
+ ],
504
+ 'line-opacity': [
505
+ 'case',
506
+ ['boolean', ['feature-state', 'hidden'], false], 0.01,
507
+ ['boolean', ['feature-state', 'selected'], false], 1.0,
508
+ ['boolean', ['feature-state', 'active'], false], 1.0,
509
+ 0.8
510
+ ],
511
+ 'line-width': [
512
+ 'let',
513
+ 'width',
514
+ (this.__type == 'edge') ? 1.6 : 1.2,
515
+ [
516
+ 'interpolate',
517
+ ['exponential', 2],
518
+ ['zoom'],
519
+ 2, ["*", ['var', 'width'], ["^", 2, -0.5]],
520
+ 7, ["*", ['var', 'width'], ["^", 2, 2.5]],
521
+ 9, ["*", ['var', 'width'], ["^", 2, 4.0]]
522
+ ]
523
+ ]
524
+ // Need to vary width based on zoom??
525
+ // Or opacity??
526
+ };
527
+ return super.changedPaintStyle(paintStyle, changes);
528
+ }
529
+
530
+ style(options)
531
+ {
532
+ return {
533
+ ...super.style(),
534
+ 'type': 'line',
535
+ 'filter': [
536
+ 'all',
537
+ ['==', '$type', 'LineString'],
538
+ ['==', 'kind', 'centreline']
539
+ ],
540
+ 'paint': this.paintStyle(options),
541
+ 'layout': {
542
+ 'line-cap': 'square',
543
+ 'line-join': 'bevel'
544
+ }
545
+ };
546
+ }
547
+ }
548
+
549
+
550
+ export class CentrelineEdgeLayer extends CentrelineLayer
551
+ {
552
+ constructor(id, sourceLayer)
553
+ {
554
+ super(id, 'edge', sourceLayer);
555
+ }
556
+
557
+ }
558
+
559
+ export class CentrelineTrackLayer extends CentrelineLayer
560
+ {
561
+ constructor(id, sourceLayer)
562
+ {
563
+ super(id, 'track', sourceLayer);
564
+ }
565
+
566
+
567
+ }
568
+
569
+ //==============================================================================
570
+
449
571
  export class FeatureNerveLayer extends VectorStyleLayer
450
572
  {
451
573
  constructor(id, sourceLayer)
@@ -461,6 +583,7 @@ export class FeatureNerveLayer extends VectorStyleLayer
461
583
  'filter': [
462
584
  'all',
463
585
  ['==', '$type', 'LineString'],
586
+ ['!=', 'kind', 'centreline'],
464
587
  ['==', 'type', 'nerve']
465
588
  ],
466
589
  'paint': {
@@ -205,7 +205,7 @@ label[for=path-all-paths] {
205
205
  .nerve-cns {
206
206
  background: #9B1FC1;
207
207
  }
208
- .nerve-lcn {
208
+ .nerve-intracardiac {
209
209
  background: #F19E38;
210
210
  }
211
211
  .nerve-other {