@abi-software/flatmap-viewer 2.2.1-beta.2 → 2.2.1-beta.5
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 +21 -33
- package/src/layers.js +42 -20
- package/src/styling.js +4 -4
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.5``
|
|
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
|
|
|
@@ -662,12 +634,21 @@ export class UserInteractions
|
|
|
662
634
|
tooltipHtml_(properties, forceLabel=false)
|
|
663
635
|
//========================================
|
|
664
636
|
{
|
|
665
|
-
if ('label' in properties
|
|
637
|
+
if (('label' in properties || 'hyperlink' in properties)
|
|
666
638
|
&& (forceLabel || !('tooltip' in properties) || properties.tooltip)
|
|
667
639
|
&& !('labelled' in properties)) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
640
|
+
let tooltip = '';
|
|
641
|
+
if ('label' in properties) {
|
|
642
|
+
const label = properties.label;
|
|
643
|
+
tooltip = (label.substr(0, 1).toUpperCase() + label.substr(1)).replaceAll("\n", "<br/>");
|
|
644
|
+
} else {
|
|
645
|
+
tooltip = properties.hyperlink
|
|
646
|
+
}
|
|
647
|
+
if ('hyperlink' in properties) {
|
|
648
|
+
return `<div class='flatmap-feature-label'><a href='{properties.hyperlink}'>${tooltip}</a></div>`;
|
|
649
|
+
} else {
|
|
650
|
+
return `<div class='flatmap-feature-label'>${tooltip}</div>`;
|
|
651
|
+
}
|
|
671
652
|
}
|
|
672
653
|
return '';
|
|
673
654
|
}
|
|
@@ -761,7 +742,8 @@ export class UserInteractions
|
|
|
761
742
|
}
|
|
762
743
|
}
|
|
763
744
|
} else {
|
|
764
|
-
let labelledFeatures = features.filter(feature => (('
|
|
745
|
+
let labelledFeatures = features.filter(feature => (('hyperlink' in feature.properties
|
|
746
|
+
|| 'label' in feature.properties
|
|
765
747
|
|| 'node' in feature.properties)
|
|
766
748
|
&& (!('tooltip' in feature.properties)
|
|
767
749
|
|| feature.properties.tooltip)))
|
|
@@ -809,6 +791,9 @@ export class UserInteractions
|
|
|
809
791
|
this.activateNerveFeatures_(feature.properties.nerveId);
|
|
810
792
|
}
|
|
811
793
|
}
|
|
794
|
+
if ('hyperlink' in feature.properties) {
|
|
795
|
+
this._map.getCanvas().style.cursor = 'pointer';
|
|
796
|
+
}
|
|
812
797
|
}
|
|
813
798
|
}
|
|
814
799
|
|
|
@@ -877,6 +862,9 @@ export class UserInteractions
|
|
|
877
862
|
if (feature !== undefined) {
|
|
878
863
|
this.__lastClickLngLat = event.lngLat;
|
|
879
864
|
this.__featureEvent('click', feature);
|
|
865
|
+
if ('hyperlink' in feature.properties) {
|
|
866
|
+
window.open(feature.properties.hyperlink, '_blank');
|
|
867
|
+
}
|
|
880
868
|
}
|
|
881
869
|
}
|
|
882
870
|
|
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,34 +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.FeatureDashLineLayer,
|
|
64
|
-
this.__addStyleLayer(style.FeatureLineLayer,
|
|
65
|
-
this.__addStyleLayer(style.FeatureBorderLayer,
|
|
65
|
+
this.__addStyleLayer(style.FeatureFillLayer, layerOptions);
|
|
66
|
+
this.__addStyleLayer(style.FeatureDashLineLayer, layerOptions);
|
|
67
|
+
this.__addStyleLayer(style.FeatureLineLayer, layerOptions);
|
|
68
|
+
this.__addStyleLayer(style.FeatureBorderLayer, layerOptions);
|
|
66
69
|
}
|
|
67
|
-
this.__addPathwayStyleLayers(
|
|
70
|
+
this.__addPathwayStyleLayers(layerOptions);
|
|
68
71
|
if (vectorFeatures) {
|
|
69
|
-
this.__addStyleLayer(style.FeatureLargeSymbolLayer,
|
|
72
|
+
this.__addStyleLayer(style.FeatureLargeSymbolLayer, layerOptions);
|
|
70
73
|
if (!flatmap.options.tooltips) {
|
|
71
|
-
this.__addStyleLayer(style.FeatureSmallSymbolLayer,
|
|
74
|
+
this.__addStyleLayer(style.FeatureSmallSymbolLayer, layerOptions);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
|
|
76
|
-
// Make sure our
|
|
79
|
+
// Make sure our colour options are set properly, in particular raster layer visibility
|
|
77
80
|
|
|
78
|
-
this.setColour(
|
|
81
|
+
this.setColour(layerOptions);
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
get id()
|
|
@@ -148,12 +151,31 @@ export class LayerManager
|
|
|
148
151
|
this.__mapLayers = new Map;
|
|
149
152
|
this.__activeLayers = [];
|
|
150
153
|
this.__activeLayerNames = [];
|
|
154
|
+
this.__rasterLayers = [];
|
|
155
|
+
const layerOptions = flatmap.options.layerOptions;
|
|
156
|
+
const fcDiagram = ('style' in layerOptions && layerOptions.style == 'fcdiagram');
|
|
151
157
|
const backgroundLayer = new style.BackgroundLayer();
|
|
152
|
-
if (
|
|
158
|
+
if (fcDiagram) {
|
|
159
|
+
this.__map.addLayer(backgroundLayer.style('black', 1));
|
|
160
|
+
}
|
|
161
|
+
else if ('background' in flatmap.options) {
|
|
153
162
|
this.__map.addLayer(backgroundLayer.style(flatmap.options.background));
|
|
154
163
|
} else {
|
|
155
164
|
this.__map.addLayer(backgroundLayer.style('white'));
|
|
156
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
|
+
}
|
|
157
179
|
}
|
|
158
180
|
|
|
159
181
|
get activeLayerNames()
|
|
@@ -162,12 +184,12 @@ export class LayerManager
|
|
|
162
184
|
return this.__activeLayerNames;
|
|
163
185
|
}
|
|
164
186
|
|
|
165
|
-
addLayer(layer,
|
|
166
|
-
|
|
187
|
+
addLayer(layer, background_layers=true)
|
|
188
|
+
//=====================================
|
|
167
189
|
{
|
|
168
190
|
this.__mapLayers.set(layer.id, layer);
|
|
169
191
|
|
|
170
|
-
const layers = new MapFeatureLayer(this.__flatmap, layer,
|
|
192
|
+
const layers = new MapFeatureLayer(this.__flatmap, layer, background_layers);
|
|
171
193
|
const layerId = this.__flatmap.mapLayerId(layer.id);
|
|
172
194
|
this.__layers.set(layerId, layers);
|
|
173
195
|
}
|
package/src/styling.js
CHANGED
|
@@ -265,7 +265,7 @@ export class FeatureLineLayer extends VectorStyleLayer
|
|
|
265
265
|
['boolean', ['feature-state', 'selected'], false], '#0F0',
|
|
266
266
|
['==', ['get', 'type'], 'network'], '#AFA202',
|
|
267
267
|
['has', 'centreline'], '#888',
|
|
268
|
-
('
|
|
268
|
+
('style' in options && options.style === 'authoring') ? '#C44' : '#444'
|
|
269
269
|
],
|
|
270
270
|
'line-opacity': [
|
|
271
271
|
'case',
|
|
@@ -279,7 +279,7 @@ export class FeatureLineLayer extends VectorStyleLayer
|
|
|
279
279
|
['has', 'centreline'], 1.2,
|
|
280
280
|
['==', ['get', 'type'], 'network'], 1.2,
|
|
281
281
|
['boolean', ['feature-state', 'active'], false], 1.2,
|
|
282
|
-
('
|
|
282
|
+
('style' in options && options.style === 'authoring') ? 0.7 : 0.5
|
|
283
283
|
], [
|
|
284
284
|
'interpolate',
|
|
285
285
|
['exponential', 2],
|
|
@@ -674,14 +674,14 @@ export class BackgroundLayer
|
|
|
674
674
|
return this.__id;
|
|
675
675
|
}
|
|
676
676
|
|
|
677
|
-
style(backgroundColour)
|
|
677
|
+
style(backgroundColour, opacity=0.1)
|
|
678
678
|
{
|
|
679
679
|
return {
|
|
680
680
|
'id': this.__id,
|
|
681
681
|
'type': 'background',
|
|
682
682
|
'paint': {
|
|
683
683
|
'background-color': backgroundColour,
|
|
684
|
-
'background-opacity':
|
|
684
|
+
'background-opacity': opacity
|
|
685
685
|
}
|
|
686
686
|
};
|
|
687
687
|
}
|