@eeacms/volto-eea-map 0.1.10 → 0.1.11

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/CHANGELOG.md CHANGED
@@ -4,10 +4,16 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [0.1.11](https://github.com/eea/volto-eea-map/compare/0.1.10...0.1.11)
8
+
9
+ - Legend for all layers [`2d9285e`](https://github.com/eea/volto-eea-map/commit/2d9285e12ea512b7a1f24300ad2f7b3072e334d5)
10
+
7
11
  #### [0.1.10](https://github.com/eea/volto-eea-map/compare/0.1.9...0.1.10)
8
12
 
13
+ > 17 August 2022
14
+
15
+ - EEA core metadata adaptation [`#10`](https://github.com/eea/volto-eea-map/pull/10)
9
16
  - EEA core metadata adaptation for map block to [`5fb5724`](https://github.com/eea/volto-eea-map/commit/5fb5724164e1e9b1ae5143f9bd565c28118be253)
10
- - EEA core metadata adaptation [`03b62a3`](https://github.com/eea/volto-eea-map/commit/03b62a35165670743d649282ae697dbf71c56a56)
11
17
 
12
18
  #### [0.1.9](https://github.com/eea/volto-eea-map/compare/0.1.8...0.1.9)
13
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "@eeacms/volto-eea-map: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -6,16 +6,33 @@ import { Icon } from '@plone/volto/components';
6
6
  import rightKeySVG from '@plone/volto/icons/right-key.svg';
7
7
  import downKeySVG from '@plone/volto/icons/down-key.svg';
8
8
 
9
- const LayerLegend = ({ data, name }) => {
9
+ const LayerLegend = ({ data }) => {
10
10
  const [expand, setExpand] = React.useState(true);
11
+ const [legendRows, setLegendRows] = React.useState([]);
11
12
 
13
+ const { id, name } = data.layer || {};
14
+
15
+ const fetchLegend = async (url, activeLayerID) => {
16
+ let legendData = await fetchArcgisData(url);
17
+
18
+ const { layers = [] } = legendData;
19
+ const selectedLayer = layers.filter((l, i) => l.layerId === activeLayerID);
20
+ setLegendRows(selectedLayer[0].legend);
21
+ };
22
+
23
+ React.useEffect(() => {
24
+ if (data.map_service_url && id !== undefined) {
25
+ fetchLegend(`${data.map_service_url}/legend`, id);
26
+ }
27
+ // eslint-disable-next-line react-hooks/exhaustive-deps
28
+ }, [id, data.map_service_url]);
12
29
  return (
13
30
  <div style={{ display: 'flex', flexDirection: 'column' }}>
14
31
  <h5
15
32
  role="presentation"
16
33
  onClick={() => setExpand(!expand)}
17
34
  style={{
18
- marginTop: '10px',
35
+ marginTop: '15px',
19
36
  marginBottom: '5px',
20
37
  cursor: 'pointer',
21
38
  display: 'flex',
@@ -30,8 +47,8 @@ const LayerLegend = ({ data, name }) => {
30
47
  </h5>
31
48
  <div style={{ display: 'flex', flexDirection: 'column' }}>
32
49
  {expand &&
33
- data.length > 0 &&
34
- data.map((item, i) => {
50
+ legendRows.length > 0 &&
51
+ legendRows.map((item, i) => {
35
52
  return (
36
53
  <span key={i} style={{ display: 'flex', alignItems: 'center' }}>
37
54
  <img
@@ -53,49 +70,25 @@ const LegendWidget = (props) => {
53
70
  const data = React.useMemo(() => props.data, [props.data]);
54
71
  const { layers = {} } = data;
55
72
  const { map_layers = [] } = layers;
56
- const [legendLayers, setLegendLayers] = React.useState([]);
57
-
58
- const activeLayer = map_layers.length > 0 ? map_layers[0]?.map_layer : '';
59
73
 
60
- const fetchLegend = async (url) => {
61
- let legendData = await fetchArcgisData(url);
62
-
63
- //TODO: configure this for multiple layers
64
- const { layers = [] } = legendData;
65
- const selectedLayerLedend = layers.filter(
66
- (l, i) => l.layerId === activeLayer.layer.id,
67
- );
68
- setLegendLayers(selectedLayerLedend);
69
- };
70
-
71
- React.useEffect(() => {
72
- if (activeLayer) {
73
- fetchLegend(`${activeLayer.map_service_url}/legend`);
74
- }
75
- // eslint-disable-next-line react-hooks/exhaustive-deps
76
- }, [data, activeLayer.map_service_url]);
77
74
  return (
78
75
  <>
79
76
  <div style={{ margin: '10px 0' }}>
80
77
  <Grid>
81
78
  <Grid.Row>
82
79
  <Grid.Column>
83
- <h3>Legend:</h3>
84
- {!activeLayer && (
80
+ <h4>Legend:</h4>
81
+ {map_layers.length === 0 && (
85
82
  <p>
86
83
  No layer found for legend. Please add a map layer from editor.
87
84
  </p>
88
85
  )}
89
- {legendLayers.length > 0 &&
90
- legendLayers.map((layer, i) => {
91
- return (
92
- <LayerLegend
93
- key={i}
94
- name={layer?.layerName}
95
- data={layer?.legend}
96
- />
97
- );
98
- })}
86
+
87
+ {map_layers &&
88
+ map_layers.length > 0 &&
89
+ map_layers.map((l, i) => (
90
+ <LayerLegend key={i} data={l.map_layer} />
91
+ ))}
99
92
  </Grid.Column>
100
93
  </Grid.Row>
101
94
  </Grid>