Skip to content

Commit 9159b11

Browse files
MV88offtherailz
authored andcommitted
Fix #608 Toc tooltips options saved in map configuration (#3663)
1 parent 4594ab4 commit 9159b11

7 files changed

Lines changed: 213 additions & 25 deletions

File tree

web/client/components/TOC/fragments/GroupTitle.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const PropTypes = require('prop-types');
1111
const StatusIcon = require('./StatusIcon');
1212
const {Tooltip} = require('react-bootstrap');
1313
const OverlayTrigger = require('../../misc/OverlayTrigger');
14-
const {getTitleAndtooltip} = require('../../../utils/TOCUtils');
14+
const {getTitleAndTooltip} = require('../../../utils/TOCUtils');
1515

1616
class GroupTitle extends React.Component {
1717
static propTypes = {
@@ -40,7 +40,7 @@ class GroupTitle extends React.Component {
4040

4141
render() {
4242
let expanded = this.props.node.expanded !== undefined ? this.props.node.expanded : true;
43-
const {title: groupTitle, tooltipText} = getTitleAndtooltip(this.props);
43+
const {title: groupTitle, tooltipText} = getTitleAndTooltip(this.props);
4444

4545
return this.props.tooltip && tooltipText ? (
4646
<OverlayTrigger placement={this.props.node.tooltipPlacement || "top"} overlay={(<Tooltip id={"tooltip-layer-group"}>{tooltipText}</Tooltip>)}>

web/client/components/TOC/fragments/Title.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const PropTypes = require('prop-types');
1010
const React = require('react');
1111
const {Tooltip} = require('react-bootstrap');
1212
const OverlayTrigger = require('../../misc/OverlayTrigger');
13-
const {getTitleAndtooltip} = require('../../../utils/TOCUtils');
13+
const {getTitleAndTooltip} = require('../../../utils/TOCUtils');
14+
1415
require("./css/toctitle.css");
1516

1617
class Title extends React.Component {
@@ -48,7 +49,7 @@ class Title extends React.Component {
4849
}
4950

5051
render() {
51-
const {title, tooltipText} = getTitleAndtooltip(this.props);
52+
const {title, tooltipText} = getTitleAndTooltip(this.props);
5253
return this.props.tooltip && tooltipText ? (
5354
<OverlayTrigger placement={this.props.node.tooltipPlacement || "top"} overlay={(<Tooltip id={"tooltip-layer-title"}>{tooltipText}</Tooltip>)}>
5455
<div className="toc-title" onClick={this.props.onClick ? (e) => this.props.onClick(this.props.node.id, 'layer', e.ctrlKey) : () => {}} onContextMenu={(e) => {e.preventDefault(); this.props.onContextMenu(this.props.node); }}>

web/client/utils/LayersUtils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ const LayersUtils = {
464464
useForElevation: layer.useForElevation || false,
465465
hidden: layer.hidden || false,
466466
origin: layer.origin,
467-
thematic: layer.thematic
467+
thematic: layer.thematic,
468+
tooltipOptions: layer.tooltipOptions,
469+
tooltipPlacement: layer.tooltipPlacement
468470
},
469471
layer.params ? { params: layer.params } : {},
470472
layer.credits ? { credits: layer.credits } : {});

web/client/utils/TOCUtils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ const TOCUtils = {
6969
* @return {string} separator
7070
* @return {number} maxLength
7171
*/
72-
getTitleAndtooltip: ({node, currentLocale, tooltipOptions = {separator: " - ", maxLength: 807}}) => {
73-
let tooltipText = TOCUtils.getTooltip(node, currentLocale, tooltipOptions.separator).substring(0, tooltipOptions.maxLength);
72+
getTitleAndTooltip: ({node, currentLocale, tooltipOptions = {separator: " - ", maxLength: 807}}) => {
73+
let tooltipText = TOCUtils.getTooltip(node, currentLocale, tooltipOptions.separator) || "";
74+
tooltipText = tooltipText && tooltipText.substring(0, tooltipOptions.maxLength);
7475
if (tooltipText.length === tooltipOptions.maxLength) {
7576
tooltipText += "...";
7677
}

web/client/utils/__tests__/LayersUtils-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,17 @@ describe('LayersUtils', () => {
844844
l => {
845845
expect(l.credits).toExist();
846846
}
847+
],
848+
// save tooltipOptions and tooltipPlacement if present
849+
[
850+
{
851+
tooltipOptions: "both",
852+
tooltipPlacement: "right"
853+
},
854+
l => {
855+
expect(l.tooltipOptions).toExist();
856+
expect(l.tooltipPlacement).toExist();
857+
}
847858
]
848859
];
849860
layers.map(([layer, test]) => test(LayersUtils.saveLayer(layer)) );

web/client/utils/__tests__/MapUtils-test.js

Lines changed: 172 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ describe('Test the MapUtils', () => {
284284
hidden: false,
285285
useForElevation: false,
286286
origin: undefined,
287-
thematic: undefined
287+
thematic: undefined,
288+
tooltipOptions: undefined,
289+
tooltipPlacement: undefined
288290
},
289291
{
290292
allowedSRS: {},
@@ -328,7 +330,9 @@ describe('Test the MapUtils', () => {
328330
hidden: false,
329331
useForElevation: false,
330332
origin: undefined,
331-
thematic: undefined
333+
thematic: undefined,
334+
tooltipOptions: undefined,
335+
tooltipPlacement: undefined
332336
},
333337
{
334338
allowedSRS: {},
@@ -372,7 +376,9 @@ describe('Test the MapUtils', () => {
372376
hidden: false,
373377
useForElevation: false,
374378
origin: undefined,
375-
thematic: undefined
379+
thematic: undefined,
380+
tooltipOptions: undefined,
381+
tooltipPlacement: undefined
376382
},
377383
{
378384
allowedSRS: {},
@@ -416,7 +422,9 @@ describe('Test the MapUtils', () => {
416422
hidden: false,
417423
useForElevation: false,
418424
origin: [100000, 100000],
419-
thematic: undefined
425+
thematic: undefined,
426+
tooltipOptions: undefined,
427+
tooltipPlacement: undefined
420428
}],
421429
mapOptions: {},
422430
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
@@ -478,7 +486,9 @@ describe('Test the MapUtils', () => {
478486
type: "wms",
479487
url: "",
480488
visibility: true,
481-
catalogURL: "url"
489+
catalogURL: "url",
490+
tooltipOptions: "both",
491+
tooltipPlacement: "right"
482492
}
483493
];
484494

@@ -582,7 +592,9 @@ describe('Test the MapUtils', () => {
582592
hidden: false,
583593
useForElevation: false,
584594
origin: undefined,
585-
thematic: undefined
595+
thematic: undefined,
596+
tooltipOptions: undefined,
597+
tooltipPlacement: undefined
586598
},
587599
{
588600
allowedSRS: {},
@@ -626,7 +638,9 @@ describe('Test the MapUtils', () => {
626638
hidden: false,
627639
useForElevation: false,
628640
origin: undefined,
629-
thematic: undefined
641+
thematic: undefined,
642+
tooltipOptions: undefined,
643+
tooltipPlacement: undefined
630644
},
631645
{
632646
allowedSRS: {},
@@ -670,7 +684,9 @@ describe('Test the MapUtils', () => {
670684
hidden: false,
671685
useForElevation: false,
672686
origin: undefined,
673-
thematic: undefined
687+
thematic: undefined,
688+
tooltipOptions: "both",
689+
tooltipPlacement: "right"
674690
}],
675691
mapOptions: {
676692
view: {
@@ -854,7 +870,9 @@ describe('Test the MapUtils', () => {
854870
hidden: false,
855871
useForElevation: false,
856872
origin: undefined,
857-
thematic: undefined
873+
thematic: undefined,
874+
tooltipOptions: undefined,
875+
tooltipPlacement: undefined
858876
},
859877
{
860878
allowedSRS: {},
@@ -898,7 +916,9 @@ describe('Test the MapUtils', () => {
898916
hidden: false,
899917
useForElevation: false,
900918
origin: undefined,
901-
thematic: undefined
919+
thematic: undefined,
920+
tooltipOptions: undefined,
921+
tooltipPlacement: undefined
902922
},
903923
{
904924
allowedSRS: {},
@@ -942,7 +962,9 @@ describe('Test the MapUtils', () => {
942962
hidden: false,
943963
useForElevation: false,
944964
origin: undefined,
945-
thematic: undefined
965+
thematic: undefined,
966+
tooltipOptions: undefined,
967+
tooltipPlacement: undefined
946968
}],
947969
mapOptions: {},
948970
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
@@ -969,6 +991,145 @@ describe('Test the MapUtils', () => {
969991
});
970992

971993

994+
it('save map configuration with tile matrix and map info configuration', () => {
995+
const flat = [
996+
{
997+
allowedSRS: {},
998+
bbox: {},
999+
description: undefined,
1000+
dimensions: [],
1001+
id: "layer001",
1002+
loading: true,
1003+
name: "layer001",
1004+
params: {},
1005+
search: {},
1006+
singleTile: false,
1007+
title: "layer001",
1008+
type: "wms",
1009+
url: "http:url001",
1010+
visibility: true,
1011+
catalogURL: "url",
1012+
matrixIds: {
1013+
'EPSG:4326': [{
1014+
identifier: 'EPSG:4326:0'
1015+
}]
1016+
},
1017+
tileMatrixSet: [{
1018+
TileMatrix: [{
1019+
'ows:Identifier': 'EPSG:4326:0'
1020+
}],
1021+
'ows:Identifier': "EPSG:4326",
1022+
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::4326"
1023+
}, {
1024+
TileMatrix: [{
1025+
'ows:Identifier': 'custom:0'
1026+
}],
1027+
'ows:Identifier': "custom",
1028+
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::900913"
1029+
}]
1030+
}
1031+
];
1032+
const groups = [
1033+
{expanded: true, id: 'Default', name: 'Default', title: 'Default', nodes: ['layer001', 'layer002']},
1034+
{expanded: false, id: 'custom', name: 'custom', title: 'custom',
1035+
nodes: [{expanded: true, id: 'custom.nested001', name: 'nested001', title: 'nested001', nodes: ['layer003']}
1036+
]}
1037+
];
1038+
const mapConfig = {
1039+
center: {x: 0, y: 0, crs: 'EPSG:4326'},
1040+
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
1041+
projection: 'EPSG:900913',
1042+
units: 'm',
1043+
zoom: 10
1044+
};
1045+
const saved = saveMapConfiguration(mapConfig, flat, groups, '', { mapInfoConfiguration: {infoFormat: "text/html", showEmptyMessageGFI: false}});
1046+
expect(saved).toEqual({
1047+
map: {
1048+
center: {crs: 'EPSG:4326', x: 0, y: 0},
1049+
groups: [{
1050+
id: 'Default',
1051+
expanded: true
1052+
}, {
1053+
id: 'custom',
1054+
expanded: false
1055+
}, {
1056+
id: 'custom.nested001',
1057+
expanded: true
1058+
}],
1059+
layers: [{
1060+
allowedSRS: {},
1061+
thumbURL: undefined,
1062+
availableStyles: undefined,
1063+
bbox: {},
1064+
requestEncoding: undefined,
1065+
capabilitiesURL: undefined,
1066+
description: undefined,
1067+
dimensions: [],
1068+
nativeCrs: undefined,
1069+
features: undefined,
1070+
queryable: undefined,
1071+
featureInfo: undefined,
1072+
format: undefined,
1073+
group: undefined,
1074+
hideLoading: false,
1075+
handleClickOnLayer: false,
1076+
id: "layer001",
1077+
matrixIds: ['EPSG:4326'],
1078+
maxZoom: undefined,
1079+
maxNativeZoom: undefined,
1080+
name: "layer001",
1081+
opacity: undefined,
1082+
params: {},
1083+
provider: undefined,
1084+
search: {},
1085+
singleTile: false,
1086+
source: undefined,
1087+
style: undefined,
1088+
styleName: undefined,
1089+
styles: undefined,
1090+
tileMatrixSet: true,
1091+
tiled: undefined,
1092+
title: "layer001",
1093+
transparent: undefined,
1094+
type: "wms",
1095+
url: "http:url001",
1096+
visibility: true,
1097+
catalogURL: "url",
1098+
hidden: false,
1099+
useForElevation: false,
1100+
origin: undefined,
1101+
thematic: undefined,
1102+
tooltipOptions: undefined,
1103+
tooltipPlacement: undefined
1104+
}],
1105+
mapOptions: {},
1106+
maxExtent: [-20037508.34, -20037508.34, 20037508.34, 20037508.34],
1107+
projection: 'EPSG:900913',
1108+
text_serch_config: '',
1109+
units: 'm',
1110+
zoom: 10,
1111+
sources: {
1112+
'http:url001': {
1113+
tileMatrixSet: {
1114+
'EPSG:4326': {
1115+
TileMatrix: [{
1116+
'ows:Identifier': 'EPSG:4326:0'
1117+
}],
1118+
'ows:Identifier': "EPSG:4326",
1119+
'ows:SupportedCRS': "urn:ogc:def:crs:EPSG::4326"
1120+
}
1121+
}
1122+
}
1123+
}
1124+
},
1125+
mapInfoConfiguration: {
1126+
infoFormat: "text/html",
1127+
showEmptyMessageGFI: false
1128+
},
1129+
version: 2
1130+
});
1131+
});
1132+
9721133
it('test getIdFromUri ', () => {
9731134
// /mapstore2/rest/geostore/data/578/raw?decode=datauri
9741135
expect(getIdFromUri('%2Fmapstore2%2Frest%2Fgeostore%2Fdata%2F578%2Fraw%3Fdecode%3Ddatauri')).toBe('578');

web/client/utils/__tests__/TOCUtils-test.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const {
1111
getTooltip,
1212
getTooltipFragment,
1313
flattenGroups,
14-
getTitleAndtooltip
14+
getTitleAndTooltip
1515
} = require('../TOCUtils');
1616
let options = [{label: "lab1", value: "val1"}];
1717
const groups = [{
@@ -157,7 +157,7 @@ describe('TOCUtils', () => {
157157
expect(allGroups[2].value).toBe("first.second.third");
158158
expect(allGroups[2].label).toBe("first/second/third");
159159
});
160-
it('test getTitleAndtooltip', () => {
160+
it('test getTitleAndTooltip both', () => {
161161
const node = {
162162
name: 'layer00',
163163
title: {
@@ -166,16 +166,28 @@ describe('TOCUtils', () => {
166166
},
167167
id: "layer00",
168168
description: "desc",
169-
visibility: true,
170-
storeIndex: 9,
171-
type: 'wms',
172-
url: 'fakeurl',
173169
tooltipOptions: "both"
174170
};
175171
const currentLocale = "it-IT";
176-
const {title, tooltipText} = getTitleAndtooltip({node, currentLocale});
172+
const {title, tooltipText} = getTitleAndTooltip({node, currentLocale});
177173
expect(title).toBe("Livello");
178174
expect(tooltipText).toBe("Livello - desc");
179175

180176
});
177+
it('test getTitleAndTooltip NoTooltip', () => {
178+
const node = {
179+
name: 'layer00',
180+
title: {
181+
'default': 'Layer',
182+
'it-IT': 'Livello'
183+
},
184+
id: "layer00",
185+
description: "desc",
186+
tooltipOptions: "none"
187+
};
188+
const currentLocale = "it-IT";
189+
const {title, tooltipText} = getTitleAndTooltip({node, currentLocale});
190+
expect(title).toBe("Livello");
191+
expect(tooltipText).toBe("");
192+
});
181193
});

0 commit comments

Comments
 (0)