@abi-software/flatmap-viewer 2.2.1-beta.1 → 2.2.1-beta.4
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 +2 -2
- package/package.json +1 -1
- package/src/flatmap-viewer.js +7 -1
- package/src/interactions.js +0 -28
- package/src/layers.js +42 -19
- package/src/styling.js +77 -43
package/README.rst
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Flatmap Viewer
|
|
3
3
|
==============
|
|
4
4
|
|
|
5
|
-
A viewer for anatomical flatmaps generated by `flatmap-maker <https://github.com/
|
|
5
|
+
A viewer for anatomical flatmaps generated by `flatmap-maker <https://github.com/AnatomicMaps/flatmap-maker>`_. The viewer is intended to be a component of a larger Javascript web application, although may be used standalone for local flatmap development and testing. Flatmap content is obtained from a `flatmap-server <https://github.com/AnatomicMaps/flatmap-server>`_.
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Standalone Use
|
|
@@ -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.2.1-beta.
|
|
41
|
+
* ``npm install @abi-software/flatmap-viewer@2.2.1-beta.4``
|
|
42
42
|
|
|
43
43
|
Documentation
|
|
44
44
|
-------------
|
package/package.json
CHANGED
package/src/flatmap-viewer.js
CHANGED
|
@@ -1259,7 +1259,13 @@ export class MapManager
|
|
|
1259
1259
|
outline: true
|
|
1260
1260
|
};
|
|
1261
1261
|
}
|
|
1262
|
-
|
|
1262
|
+
if ('authoring' in mapIndex) {
|
|
1263
|
+
mapOptions.layerOptions.style == 'authoring'
|
|
1264
|
+
} else if ('style' in mapIndex) {
|
|
1265
|
+
mapOptions.layerOptions.style = mapIndex.style;
|
|
1266
|
+
} else {
|
|
1267
|
+
mapOptions.layerOptions.style = 'flatmap';
|
|
1268
|
+
}
|
|
1263
1269
|
|
|
1264
1270
|
// Are features in separate vector tile source layers?
|
|
1265
1271
|
|
package/src/interactions.js
CHANGED
|
@@ -162,34 +162,6 @@ export class UserInteractions
|
|
|
162
162
|
|
|
163
163
|
this._layerManager = new LayerManager(flatmap);
|
|
164
164
|
|
|
165
|
-
// Add the map's layers
|
|
166
|
-
|
|
167
|
-
// Layers have an id, either layer-N or an assigned name
|
|
168
|
-
// Some layers might have a description. These are the selectable layers,
|
|
169
|
-
// unless they are flagged as `no-select`
|
|
170
|
-
// Selectable layers have opacity 0 unless active, in which case they have opacity 1.
|
|
171
|
-
// `no-select` layers have opacity 0.5
|
|
172
|
-
// Background layer has opacity 0.2
|
|
173
|
-
|
|
174
|
-
const layersById = new Map();
|
|
175
|
-
const layerBackgroundIds = [];
|
|
176
|
-
for (const layer of flatmap.layers) {
|
|
177
|
-
layer.backgroundLayers = [];
|
|
178
|
-
layersById.set(layer.id, layer);
|
|
179
|
-
}
|
|
180
|
-
for (const layer of flatmap.layers) {
|
|
181
|
-
if (layer.background_for) {
|
|
182
|
-
const l = layersById.get(layer.background_for);
|
|
183
|
-
l.backgroundLayers.push(layer);
|
|
184
|
-
layerBackgroundIds.push(layer.id);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
for (const layer of flatmap.layers) {
|
|
188
|
-
if (layerBackgroundIds.indexOf(layer.id) < 0) {
|
|
189
|
-
this._layerManager.addLayer(layer, flatmap.options.layerOptions);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
165
|
// Flag features that have annotations
|
|
194
166
|
// Also flag those features that are models of something
|
|
195
167
|
|
package/src/layers.js
CHANGED
|
@@ -33,7 +33,7 @@ const FEATURES_LAYER = 'features'
|
|
|
33
33
|
|
|
34
34
|
class MapFeatureLayer
|
|
35
35
|
{
|
|
36
|
-
constructor(flatmap, layer,
|
|
36
|
+
constructor(flatmap, layer, background_layers=true)
|
|
37
37
|
{
|
|
38
38
|
this.__map = flatmap.map;
|
|
39
39
|
this.__separateLayers = flatmap.options.separateLayers;
|
|
@@ -41,6 +41,7 @@ class MapFeatureLayer
|
|
|
41
41
|
this.__rasterLayers = [];
|
|
42
42
|
this.__styleLayers = [];
|
|
43
43
|
|
|
44
|
+
const layerOptions = flatmap.options.layerOptions;
|
|
44
45
|
const vectorTileSource = this.__map.getSource('vector-tiles');
|
|
45
46
|
const haveVectorLayers = (typeof vectorTileSource !== 'undefined');
|
|
46
47
|
const featuresVectorLayerId = this.__separateLayers
|
|
@@ -48,33 +49,36 @@ class MapFeatureLayer
|
|
|
48
49
|
: FEATURES_LAYER;
|
|
49
50
|
const vectorFeatures = haveVectorLayers
|
|
50
51
|
&& vectorTileSource.vectorLayerIds.indexOf(featuresVectorLayerId) >= 0;
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
52
|
+
if (background_layers) {
|
|
53
|
+
if (vectorFeatures) {
|
|
54
|
+
this.__addStyleLayer(style.BodyLayer, layerOptions);
|
|
55
|
+
}
|
|
56
|
+
if (flatmap.details['image_layer']) {
|
|
57
|
+
for (const raster_layer_id of layer['image-layers']) {
|
|
58
|
+
this.__addRasterLayer(raster_layer_id, layerOptions);
|
|
59
|
+
}
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
// if no image layers then make feature borders (and lines?) more visible...??
|
|
60
63
|
if (haveVectorLayers) {
|
|
61
64
|
if (vectorFeatures) {
|
|
62
|
-
this.__addStyleLayer(style.FeatureFillLayer,
|
|
63
|
-
this.__addStyleLayer(style.
|
|
64
|
-
this.__addStyleLayer(style.
|
|
65
|
+
this.__addStyleLayer(style.FeatureFillLayer, layerOptions);
|
|
66
|
+
this.__addStyleLayer(style.FeatureDashLineLayer, layerOptions);
|
|
67
|
+
this.__addStyleLayer(style.FeatureLineLayer, layerOptions);
|
|
68
|
+
this.__addStyleLayer(style.FeatureBorderLayer, layerOptions);
|
|
65
69
|
}
|
|
66
|
-
this.__addPathwayStyleLayers(
|
|
70
|
+
this.__addPathwayStyleLayers(layerOptions);
|
|
67
71
|
if (vectorFeatures) {
|
|
68
|
-
this.__addStyleLayer(style.FeatureLargeSymbolLayer,
|
|
72
|
+
this.__addStyleLayer(style.FeatureLargeSymbolLayer, layerOptions);
|
|
69
73
|
if (!flatmap.options.tooltips) {
|
|
70
|
-
this.__addStyleLayer(style.FeatureSmallSymbolLayer,
|
|
74
|
+
this.__addStyleLayer(style.FeatureSmallSymbolLayer, layerOptions);
|
|
71
75
|
}
|
|
72
76
|
}
|
|
73
77
|
}
|
|
74
78
|
|
|
75
|
-
// Make sure our
|
|
79
|
+
// Make sure our colour options are set properly, in particular raster layer visibility
|
|
76
80
|
|
|
77
|
-
this.setColour(
|
|
81
|
+
this.setColour(layerOptions);
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
get id()
|
|
@@ -147,12 +151,31 @@ export class LayerManager
|
|
|
147
151
|
this.__mapLayers = new Map;
|
|
148
152
|
this.__activeLayers = [];
|
|
149
153
|
this.__activeLayerNames = [];
|
|
154
|
+
this.__rasterLayers = [];
|
|
155
|
+
const layerOptions = flatmap.options.layerOptions;
|
|
156
|
+
const fcDiagram = ('style' in layerOptions && layerOptions.style == 'fcdiagram');
|
|
150
157
|
const backgroundLayer = new style.BackgroundLayer();
|
|
151
|
-
if (
|
|
158
|
+
if (fcDiagram) {
|
|
159
|
+
this.__map.addLayer(backgroundLayer.style('black', 1));
|
|
160
|
+
}
|
|
161
|
+
else if ('background' in flatmap.options) {
|
|
152
162
|
this.__map.addLayer(backgroundLayer.style(flatmap.options.background));
|
|
153
163
|
} else {
|
|
154
164
|
this.__map.addLayer(backgroundLayer.style('white'));
|
|
155
165
|
}
|
|
166
|
+
// Add the map's layers
|
|
167
|
+
if (fcDiagram && flatmap.details['image_layer']) {
|
|
168
|
+
for (const layer of flatmap.layers) {
|
|
169
|
+
for (const raster_layer_id of layer['image-layers']) {
|
|
170
|
+
const rasterLayer = new style.RasterLayer(raster_layer_id);
|
|
171
|
+
this.__map.addLayer(rasterLayer.style(layerOptions));
|
|
172
|
+
this.__rasterLayers.push(rasterLayer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
for (const layer of flatmap.layers) {
|
|
177
|
+
this.addLayer(layer, !fcDiagram);
|
|
178
|
+
}
|
|
156
179
|
}
|
|
157
180
|
|
|
158
181
|
get activeLayerNames()
|
|
@@ -161,12 +184,12 @@ export class LayerManager
|
|
|
161
184
|
return this.__activeLayerNames;
|
|
162
185
|
}
|
|
163
186
|
|
|
164
|
-
addLayer(layer,
|
|
165
|
-
|
|
187
|
+
addLayer(layer, background_layers=true)
|
|
188
|
+
//=====================================
|
|
166
189
|
{
|
|
167
190
|
this.__mapLayers.set(layer.id, layer);
|
|
168
191
|
|
|
169
|
-
const layers = new MapFeatureLayer(this.__flatmap, layer,
|
|
192
|
+
const layers = new MapFeatureLayer(this.__flatmap, layer, background_layers);
|
|
170
193
|
const layerId = this.__flatmap.mapLayerId(layer.id);
|
|
171
194
|
this.__layers.set(layerId, layers);
|
|
172
195
|
}
|
package/src/styling.js
CHANGED
|
@@ -117,12 +117,12 @@ export class FeatureFillLayer extends VectorStyleLayer
|
|
|
117
117
|
const paintStyle = {
|
|
118
118
|
'fill-color': [
|
|
119
119
|
'case',
|
|
120
|
+
['has', 'colour'], ['get', 'colour'],
|
|
120
121
|
['boolean', ['feature-state', 'active'], false], coloured ? '#D88' : '#CCC',
|
|
121
122
|
['boolean', ['feature-state', 'selected'], false], '#0F0',
|
|
122
123
|
['any',
|
|
123
124
|
['==', ['get', 'kind'], 'scaffold']
|
|
124
125
|
], 'white',
|
|
125
|
-
['has', 'colour'], ['get', 'colour'],
|
|
126
126
|
['has', 'node'], '#AFA202',
|
|
127
127
|
'white' // background colour? body colour ??
|
|
128
128
|
],
|
|
@@ -133,10 +133,10 @@ export class FeatureFillLayer extends VectorStyleLayer
|
|
|
133
133
|
['==', ['get', 'kind'], 'tissue'],
|
|
134
134
|
['==', ['get', 'kind'], 'cell-type'],
|
|
135
135
|
], 0.1,
|
|
136
|
-
['has', 'colour'], 0.008,
|
|
137
136
|
['has', 'node'], 0.3,
|
|
138
137
|
['boolean', ['feature-state', 'selected'], false], 1.0,
|
|
139
138
|
['boolean', ['feature-state', 'active'], false], 0.8,
|
|
139
|
+
['has', 'colour'], 0.008,
|
|
140
140
|
(coloured && !dimmed) ? 0.01 : 0.5
|
|
141
141
|
]
|
|
142
142
|
};
|
|
@@ -236,62 +236,96 @@ export class FeatureBorderLayer extends VectorStyleLayer
|
|
|
236
236
|
|
|
237
237
|
export class FeatureLineLayer extends VectorStyleLayer
|
|
238
238
|
{
|
|
239
|
-
constructor(id, sourceLayer)
|
|
239
|
+
constructor(id, sourceLayer, dashed=false)
|
|
240
240
|
{
|
|
241
|
-
|
|
241
|
+
const filterType = dashed ? 'line-dash' : 'line';
|
|
242
|
+
super(id, `divider-${filterType}`, sourceLayer);
|
|
243
|
+
this.__filter = dashed ?
|
|
244
|
+
[
|
|
245
|
+
'any',
|
|
246
|
+
['==', 'type', `line-dash`]
|
|
247
|
+
]
|
|
248
|
+
:
|
|
249
|
+
[
|
|
250
|
+
'any',
|
|
251
|
+
['==', 'type', 'bezier'],
|
|
252
|
+
['==', 'type', `line`]
|
|
253
|
+
];
|
|
254
|
+
this.__dashed = dashed;
|
|
242
255
|
}
|
|
243
256
|
|
|
244
|
-
|
|
257
|
+
paintStyle(options)
|
|
245
258
|
{
|
|
246
259
|
const coloured = !('colour' in options) || options.colour;
|
|
260
|
+
const paintStyle = {
|
|
261
|
+
'line-color': [
|
|
262
|
+
'case',
|
|
263
|
+
['has', 'colour'], ['get', 'colour'],
|
|
264
|
+
['boolean', ['feature-state', 'active'], false], coloured ? '#D88' : '#CCC',
|
|
265
|
+
['boolean', ['feature-state', 'selected'], false], '#0F0',
|
|
266
|
+
['==', ['get', 'type'], 'network'], '#AFA202',
|
|
267
|
+
['has', 'centreline'], '#888',
|
|
268
|
+
('style' in options && options.style === 'authoring') ? '#C44' : '#444'
|
|
269
|
+
],
|
|
270
|
+
'line-opacity': [
|
|
271
|
+
'case',
|
|
272
|
+
['boolean', ['feature-state', 'active'], false], 1.0,
|
|
273
|
+
0.3
|
|
274
|
+
],
|
|
275
|
+
'line-width': [
|
|
276
|
+
'let',
|
|
277
|
+
'width', [
|
|
278
|
+
'case',
|
|
279
|
+
['has', 'centreline'], 1.2,
|
|
280
|
+
['==', ['get', 'type'], 'network'], 1.2,
|
|
281
|
+
['boolean', ['feature-state', 'active'], false], 1.2,
|
|
282
|
+
('style' in options && options.style === 'authoring') ? 0.7 : 0.5
|
|
283
|
+
], [
|
|
284
|
+
'interpolate',
|
|
285
|
+
['exponential', 2],
|
|
286
|
+
['zoom'],
|
|
287
|
+
2, ["*", ['var', 'width'], ["^", 2, -0.5]],
|
|
288
|
+
7, ["*", ['var', 'width'], ["^", 2, 2.5]],
|
|
289
|
+
9, ["*", ['var', 'width'], ["^", 2, 4.0]]
|
|
290
|
+
]
|
|
291
|
+
]
|
|
292
|
+
// Need to vary width based on zoom??
|
|
293
|
+
// Or opacity??
|
|
294
|
+
};
|
|
295
|
+
if (this.__dashed) {
|
|
296
|
+
paintStyle['line-dasharray'] = [3, 2];
|
|
297
|
+
}
|
|
298
|
+
return paintStyle;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
style(options)
|
|
302
|
+
{
|
|
247
303
|
return {
|
|
248
304
|
...super.style(),
|
|
249
305
|
'type': 'line',
|
|
250
306
|
'filter': [
|
|
251
|
-
|
|
252
|
-
|
|
307
|
+
'all',
|
|
308
|
+
['==', '$type', 'LineString'],
|
|
309
|
+
this.__filter
|
|
253
310
|
// not for paths...
|
|
254
311
|
],
|
|
255
|
-
'paint':
|
|
256
|
-
'line-color': [
|
|
257
|
-
'case',
|
|
258
|
-
['boolean', ['feature-state', 'active'], false], coloured ? '#D88' : '#CCC',
|
|
259
|
-
['boolean', ['feature-state', 'selected'], false], '#0F0',
|
|
260
|
-
['==', ['get', 'type'], 'network'], '#AFA202',
|
|
261
|
-
['has', 'centreline'], '#888',
|
|
262
|
-
('authoring' in options && options.authoring) ? '#C44' : '#444'
|
|
263
|
-
],
|
|
264
|
-
'line-opacity': [
|
|
265
|
-
'case',
|
|
266
|
-
['boolean', ['feature-state', 'active'], false], 1.0,
|
|
267
|
-
0.3
|
|
268
|
-
],
|
|
269
|
-
'line-width': [
|
|
270
|
-
'let',
|
|
271
|
-
'width', [
|
|
272
|
-
'case',
|
|
273
|
-
['has', 'centreline'], 1.2,
|
|
274
|
-
['==', ['get', 'type'], 'network'], 1.2,
|
|
275
|
-
['boolean', ['feature-state', 'active'], false], 1.2,
|
|
276
|
-
('authoring' in options && options.authoring) ? 0.7 : 0.1
|
|
277
|
-
], [
|
|
278
|
-
'interpolate',
|
|
279
|
-
['exponential', 2],
|
|
280
|
-
['zoom'],
|
|
281
|
-
2, ["*", ['var', 'width'], ["^", 2, -0.5]],
|
|
282
|
-
7, ["*", ['var', 'width'], ["^", 2, 2.5]],
|
|
283
|
-
9, ["*", ['var', 'width'], ["^", 2, 4.0]]
|
|
284
|
-
]
|
|
285
|
-
]
|
|
286
|
-
// Need to vary width based on zoom??
|
|
287
|
-
// Or opacity??
|
|
288
|
-
}
|
|
312
|
+
'paint': this.paintStyle(options)
|
|
289
313
|
};
|
|
290
314
|
}
|
|
291
315
|
}
|
|
292
316
|
|
|
293
317
|
//==============================================================================
|
|
294
318
|
|
|
319
|
+
export class FeatureDashLineLayer extends FeatureLineLayer
|
|
320
|
+
{
|
|
321
|
+
constructor(id, sourceLayer)
|
|
322
|
+
{
|
|
323
|
+
super(id, sourceLayer, true);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
//==============================================================================
|
|
328
|
+
|
|
295
329
|
export class PathLineLayer extends VectorStyleLayer
|
|
296
330
|
{
|
|
297
331
|
constructor(id, sourceLayer, dashed=false)
|
|
@@ -640,14 +674,14 @@ export class BackgroundLayer
|
|
|
640
674
|
return this.__id;
|
|
641
675
|
}
|
|
642
676
|
|
|
643
|
-
style(backgroundColour)
|
|
677
|
+
style(backgroundColour, opacity=0.1)
|
|
644
678
|
{
|
|
645
679
|
return {
|
|
646
680
|
'id': this.__id,
|
|
647
681
|
'type': 'background',
|
|
648
682
|
'paint': {
|
|
649
683
|
'background-color': backgroundColour,
|
|
650
|
-
'background-opacity':
|
|
684
|
+
'background-opacity': opacity
|
|
651
685
|
}
|
|
652
686
|
};
|
|
653
687
|
}
|