-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathAddWmsLayerEntry.tsx
113 lines (99 loc) · 2.72 KB
/
AddWmsLayerEntry.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as React from 'react';
import OlLayerTile from 'ol/layer/Tile';
import OlLayerImage from 'ol/layer/Image';
import { Checkbox, Tooltip } from 'antd';
import { Icon } from 'react-fa';
import './AddWmsLayerEntry.less';
interface DefaultProps {
/**
* Function returning a span with the textual representation of this layer
* Default: Title of the layer and its abstract (if available)
*/
layerTextTemplateFn: (layer: OlLayerTile | OlLayerImage) => React.ReactNode;
/**
* Optional text to be shown in Tooltip for a layer that can be queried
*/
layerQueryableText: string;
}
interface BaseProps {
/**
* Object containing layer information
*/
wmsLayer: OlLayerTile | OlLayerImage;
}
interface AddWmsLayerEntryState {
copyright: string;
queryable: boolean;
}
export type AddWmsLayerEntryProps = BaseProps & Partial<DefaultProps>;
/**
* Class representing a layer parsed from capabilities document.
* This componment is used in AddWmsPanel
*
* @class AddWmsLayerEntry
* @extends React.Component
*/
export class AddWmsLayerEntry extends React.Component<AddWmsLayerEntryProps, AddWmsLayerEntryState> {
/**
* Create the AddWmsLayerEntry.
*
* @constructs AddWmsLayerEntry
*/
constructor(props: AddWmsLayerEntryProps) {
super(props);
this.state = {
copyright: props.wmsLayer.getSource().getAttributions(),
queryable: props.wmsLayer.get('queryable')
};
}
/**
* The defaultProps.
*/
static defaultProps: DefaultProps = {
layerQueryableText: 'Layer is queryable',
layerTextTemplateFn: (wmsLayer) => {
const title = wmsLayer.get('title');
const abstract = wmsLayer.get('abstract');
const abstractTextSpan = abstract ?
<span>{`${title} - ${abstract}:`}</span> :
<span>{`${title}`}</span>;
return abstractTextSpan;
}
};
/**
* The render function
*/
render() {
const {
wmsLayer,
layerTextTemplateFn,
layerQueryableText
} = this.props;
const {
copyright,
queryable
} = this.state;
const title = wmsLayer.get('title');
const layerTextSpan = layerTextTemplateFn(wmsLayer);
return (
<Checkbox value={title} className="add-wms-layer-checkbox-line">
<div className="add-wms-layer-entry">
{layerTextSpan}
{
copyright
? <Icon className="add-wms-add-info-icon" name="copyright" />
: null
}
{
queryable
? <Tooltip title={layerQueryableText}>
<Icon className="add-wms-add-info-icon" name="info" />
</Tooltip>
: null
}
</div>
</Checkbox>
);
}
}
export default AddWmsLayerEntry;