@eeacms/volto-eea-map 0.1.3 → 0.1.6

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,8 +4,39 @@ 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.6](https://github.com/eea/volto-eea-map/compare/0.1.5...0.1.6)
8
+
9
+ - Lint fix [`f5561d1`](https://github.com/eea/volto-eea-map/commit/f5561d1581201bd635b4e53e8a46decaf684438f)
10
+ - Map improvements [`c75d16c`](https://github.com/eea/volto-eea-map/commit/c75d16c265136d9f676e194540e613bb742fb51b)
11
+
12
+ #### [0.1.5](https://github.com/eea/volto-eea-map/compare/0.1.4...0.1.5)
13
+
14
+ > 4 August 2022
15
+
16
+ - Develop [`#5`](https://github.com/eea/volto-eea-map/pull/5)
17
+ - Center on extent only on map load [`b63f586`](https://github.com/eea/volto-eea-map/commit/b63f586e0df68faa755bb0d25e297530e36ef7c9)
18
+ - Configure proxy for all map subdomains [`0f19030`](https://github.com/eea/volto-eea-map/commit/0f19030569e1f77b1ff7657669e876519712840f)
19
+ - Prevent unnecessary rerenders of ma [`8752384`](https://github.com/eea/volto-eea-map/commit/8752384b3bbd7b564a25b3e4347c47692106f556)
20
+ - Prevent unnecessary rerenders of map [`00a3e64`](https://github.com/eea/volto-eea-map/commit/00a3e64585748a36ef476b2d75540bdd43778486)
21
+ - Clear print schema [`29ed979`](https://github.com/eea/volto-eea-map/commit/29ed9795812d6673f8fb91ac73e53e4e132ed55a)
22
+ - Move zoom & print in general tab [`06c4996`](https://github.com/eea/volto-eea-map/commit/06c499651217715e1793d2a75fb72668dc1de223)
23
+ - Clear [`9aa7bf1`](https://github.com/eea/volto-eea-map/commit/9aa7bf1591b22a2941ce0f269ef133d687affc15)
24
+ - Disable url for screenshot atm [`1ef18fc`](https://github.com/eea/volto-eea-map/commit/1ef18fc8b7516c88c743cffb10b5eb340161d58d)
25
+
26
+ #### [0.1.4](https://github.com/eea/volto-eea-map/compare/0.1.3...0.1.4)
27
+
28
+ > 3 August 2022
29
+
30
+ - Map updates [`#4`](https://github.com/eea/volto-eea-map/pull/4)
31
+ - Configure Privacy protection screenshot data [`49097c0`](https://github.com/eea/volto-eea-map/commit/49097c0b7aa8657e626d5a49dd0eed84f5e71e78)
32
+ - Expandable Legend [`6edda2f`](https://github.com/eea/volto-eea-map/commit/6edda2fafd8a2a61f3f1f10c47a9ca5bb35a0355)
33
+ - Catch for no data [`7cef4e6`](https://github.com/eea/volto-eea-map/commit/7cef4e641650ede23e37ca9116130db1ef0a18db)
34
+
7
35
  #### [0.1.3](https://github.com/eea/volto-eea-map/compare/0.1.2...0.1.3)
8
36
 
37
+ > 2 August 2022
38
+
39
+ - Center map on first layer [`#3`](https://github.com/eea/volto-eea-map/pull/3)
9
40
  - Icons & download/viewer change [`321f538`](https://github.com/eea/volto-eea-map/commit/321f538e9582f9a12db3f64beb26588616e867e2)
10
41
  - Inline inputs actions & styles [`1f4787e`](https://github.com/eea/volto-eea-map/commit/1f4787e3b3f0dc1328ff23cca2459db816188e3a)
11
42
  - more updates for cy10 [`4d5c6a1`](https://github.com/eea/volto-eea-map/commit/4d5c6a1925413b44acc70b5ad3753378830dba2d)
@@ -18,7 +49,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
18
49
  - Clear schema [`4b22f0a`](https://github.com/eea/volto-eea-map/commit/4b22f0aee58cca2bbcd2a8bee9864a01d65e7738)
19
50
  - Center on extent control [`9e8b13d`](https://github.com/eea/volto-eea-map/commit/9e8b13dfd5bbfa5eb2419c54444a15fefa384de4)
20
51
  - Clear consoles [`798bc2f`](https://github.com/eea/volto-eea-map/commit/798bc2fbf6f77ffadcedcf1e4666b315bc71ea6c)
21
- - Center map on first layer [`8fbc1ca`](https://github.com/eea/volto-eea-map/commit/8fbc1ca711ceba09e38e841cd7f551c1a8787027)
22
52
 
23
53
  #### [0.1.2](https://github.com/eea/volto-eea-map/compare/0.1.1...0.1.2)
24
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
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",
@@ -2,27 +2,18 @@ import React from 'react';
2
2
  import { SidebarPortal } from '@plone/volto/components';
3
3
  import BlockDataForm from '@plone/volto/components/manage/Form/BlockDataForm';
4
4
  import { Schema } from './Schema';
5
- import Webmap from './components/Webmap';
5
+ import View from './View';
6
+ import { addPrivacyProtectionToSchema } from '@eeacms/volto-embed';
6
7
  import './styles/map.css';
7
- import ExtraViews from './components/widgets/ExtraViews';
8
- import {
9
- PrivacyProtection,
10
- addPrivacyProtectionToSchema,
11
- } from '@eeacms/volto-embed';
12
8
 
13
9
  const Edit = (props) => {
14
10
  const { block, data, onChangeBlock, selected } = props;
15
11
  const schema = React.useMemo(() => Schema(props), [props]);
16
12
 
17
- const { map_data = {}, height } = data;
18
13
  if (__SERVER__) return '';
19
-
20
14
  return (
21
15
  <div>
22
- <PrivacyProtection data={data} {...props}>
23
- <Webmap data={map_data} height={height} />
24
- <ExtraViews data={data} />
25
- </PrivacyProtection>
16
+ <View data={data} />
26
17
  <SidebarPortal selected={selected}>
27
18
  <BlockDataForm
28
19
  block={block}
@@ -15,15 +15,11 @@ const MODULES = [
15
15
  ];
16
16
 
17
17
  const Webmap = (props) => {
18
- const { data = {}, editMode, height } = props;
19
- const {
20
- base = {},
21
- layers = {},
22
- id,
23
- legend = {},
24
- print = {},
25
- zoom = {},
26
- } = data;
18
+ const { editMode, height } = props;
19
+
20
+ const data = React.useMemo(() => props.data || {}, [props.data]);
21
+
22
+ const { base = {}, layers = {}, legend = {}, general = {} } = data;
27
23
 
28
24
  const { base_layer = '' } = base;
29
25
 
@@ -39,6 +35,7 @@ const Webmap = (props) => {
39
35
 
40
36
  const mapRef = React.useRef();
41
37
  const [modules, setModules] = React.useState({});
38
+
42
39
  const modules_loaded = React.useRef(false);
43
40
 
44
41
  React.useEffect(() => {
@@ -71,6 +68,7 @@ const Webmap = (props) => {
71
68
  }
72
69
  }, [setModules, options]);
73
70
 
71
+ // eslint-disable-next-line no-unused-vars
74
72
  const esri = React.useMemo(() => {
75
73
  if (Object.keys(modules).length === 0) return {};
76
74
  const {
@@ -122,30 +120,28 @@ const Webmap = (props) => {
122
120
  const view = new MapView({
123
121
  container: mapRef.current,
124
122
  map,
125
- center: zoom?.long && zoom?.lat ? [zoom.long, zoom.lat] : [0, 40],
126
- zoom: zoom?.zoom_level ? zoom?.zoom_level : 2,
123
+ center:
124
+ general?.long && general?.lat ? [general.long, general.lat] : [0, 40],
125
+ zoom: general?.zoom_level ? general?.zoom_level : 2,
127
126
  ui: {
128
127
  components: ['attribution'],
129
128
  },
130
129
  });
131
130
 
132
- if (layers && layers[0] && zoom && zoom.centerOnExtent) {
133
- view.whenLayerView(layers[0]).then(function (layerView) {
134
- layerView.watch('updating', function (val) {
135
- // view.goTo(response.extent);
136
-
137
- if (!val && layerView) {
138
- layerView.queryExtent().then(function (response) {
139
- ///go to the extent of all the graphics in the layer view
140
- if (response.extent) view.goTo(response.extent);
141
- });
142
- }
131
+ if (layers && layers[0] && general && general.centerOnExtent) {
132
+ const firstLayer = layers[0];
133
+ firstLayer
134
+ .when(() => {
135
+ return firstLayer.queryExtent();
136
+ })
137
+ .then((response) => {
138
+ view.goTo(response.extent);
143
139
  });
144
- });
145
140
  }
146
141
 
147
- if (zoom?.show_zoom) {
148
- const zoomPosition = zoom && zoom.position ? zoom.position : 'top-right';
142
+ if (general?.show_zoom) {
143
+ const zoomPosition =
144
+ general && general.zoom_position ? general.zoom_position : 'top-right';
149
145
  const zoomWidget = new Zoom({
150
146
  view: view,
151
147
  });
@@ -161,7 +157,7 @@ const Webmap = (props) => {
161
157
  const legendWidget = new Expand({
162
158
  content: new Legend({
163
159
  view: view,
164
- style: 'classic', // other styles include 'classic'
160
+ style: 'classic',
165
161
  }),
166
162
  view: view,
167
163
  expanded: false,
@@ -172,9 +168,11 @@ const Webmap = (props) => {
172
168
  view.ui.add(legendWidget, legendPosition);
173
169
  }
174
170
 
175
- if (print?.show_print) {
171
+ if (general?.show_print) {
176
172
  const printPosition =
177
- print && print.position ? print.position : 'top-right';
173
+ general && general.print_position
174
+ ? general.print_position
175
+ : 'top-right';
178
176
  const printWidget = new Expand({
179
177
  content: new Print({
180
178
  view: view,
@@ -193,9 +191,8 @@ const Webmap = (props) => {
193
191
  });
194
192
  }
195
193
  return { view, map };
196
- }, [modules, base_layer, map_layers]);
194
+ }, [modules, base_layer, map_layers, general, legend]);
197
195
 
198
- const currentLayerView = esri.view?.layerViews?.items?.[0];
199
196
  return (
200
197
  <div>
201
198
  <div
@@ -209,4 +206,4 @@ const Webmap = (props) => {
209
206
  );
210
207
  };
211
208
 
212
- export default Webmap;
209
+ export default React.memo(Webmap);
@@ -16,9 +16,10 @@ const ExtraViews = ({ data }) => {
16
16
  show_download,
17
17
  show_viewer,
18
18
  } = data;
19
+
19
20
  return (
20
- <>
21
- {(show_download || show_viewer) && (
21
+ <div className="extra-eea-map-content">
22
+ {map_data.layers?.map_layers[0] && (show_download || show_viewer) && (
22
23
  <div
23
24
  style={{ display: 'flex', justifyContent: 'end', margin: '10px 0' }}
24
25
  >
@@ -55,7 +56,7 @@ const ExtraViews = ({ data }) => {
55
56
  )}
56
57
  {show_legend && <LegendWidget data={map_data} />}
57
58
  {description && serializeNodes(description)}
58
- </>
59
+ </div>
59
60
  );
60
61
  };
61
62
 
@@ -9,7 +9,9 @@ import aheadSVG from '@plone/volto/icons/ahead.svg';
9
9
  import { fetchArcgisData } from '../../utils';
10
10
 
11
11
  const LayerSelectWidget = (props) => {
12
- const { onChange, value = {}, id } = props;
12
+ const { onChange, id } = props;
13
+
14
+ const value = React.useMemo(() => props.value || {}, [props.value]);
13
15
 
14
16
  const {
15
17
  available_layers,
@@ -3,7 +3,9 @@ import { Button } from 'semantic-ui-react';
3
3
  import LayerSelectWidget from './LayerSelectWidget';
4
4
 
5
5
  const LayersPanel = ({ data, onChange, block }) => {
6
- const { map_layers } = data || {};
6
+ const map_layers = React.useMemo(() => data.map_layers || [], [
7
+ data.map_layers,
8
+ ]);
7
9
 
8
10
  React.useEffect(() => {
9
11
  if (!data.map_layers) {
@@ -1,30 +1,62 @@
1
1
  import React from 'react';
2
2
  import { Grid } from 'semantic-ui-react';
3
3
  import { fetchArcgisData } from '../../utils';
4
+ import { Icon } from '@plone/volto/components';
5
+
6
+ import rightKeySVG from '@plone/volto/icons/right-key.svg';
7
+ import downKeySVG from '@plone/volto/icons/down-key.svg';
8
+
9
+ const LayerLegend = ({ data, name }) => {
10
+ const [expand, setExpand] = React.useState(true);
4
11
 
5
- const LayerLegend = ({ data }) => {
6
12
  return (
7
13
  <div style={{ display: 'flex', flexDirection: 'column' }}>
8
- {data.length > 0 &&
9
- data.map((item, i) => {
10
- return (
11
- <span key={i} style={{ display: 'flex', alignItems: 'center' }}>
12
- <img alt="alt" src={`data:image/png;base64,${item.imageData}`} />
13
- <span style={{ fontSize: '13px' }}>{item.label}</span>
14
- </span>
15
- );
16
- })}
14
+ <h5
15
+ role="presentation"
16
+ onClick={() => setExpand(!expand)}
17
+ style={{
18
+ marginTop: '10px',
19
+ marginBottom: '5px',
20
+ cursor: 'pointer',
21
+ display: 'flex',
22
+ }}
23
+ >
24
+ <Icon
25
+ name={expand ? downKeySVG : rightKeySVG}
26
+ title={expand ? 'Collapse' : 'Expand'}
27
+ size="17px"
28
+ />
29
+ {name}
30
+ </h5>
31
+ <div style={{ display: 'flex', flexDirection: 'column' }}>
32
+ {expand &&
33
+ data.length > 0 &&
34
+ data.map((item, i) => {
35
+ return (
36
+ <span key={i} style={{ display: 'flex', alignItems: 'center' }}>
37
+ <img
38
+ alt="alt"
39
+ src={`data:image/png;base64,${item.imageData}`}
40
+ />
41
+ <span style={{ fontSize: '13px', marginLeft: '5px' }}>
42
+ {item.label}
43
+ </span>
44
+ </span>
45
+ );
46
+ })}
47
+ </div>
17
48
  </div>
18
49
  );
19
50
  };
20
51
 
21
52
  const LegendWidget = (props) => {
22
- const { data = {} } = props;
53
+ const data = React.useMemo(() => props.data, [props.data]);
23
54
  const { layers = {} } = data;
24
55
  const { map_layers = [] } = layers;
25
56
  const [legendLayers, setLegendLayers] = React.useState([]);
26
57
 
27
58
  const activeLayer = map_layers.length > 0 ? map_layers[0]?.map_layer : '';
59
+
28
60
  const fetchLegend = async (url) => {
29
61
  let legendData = await fetchArcgisData(url);
30
62
 
@@ -37,10 +69,11 @@ const LegendWidget = (props) => {
37
69
  };
38
70
 
39
71
  React.useEffect(() => {
40
- fetchLegend(`${activeLayer.map_service_url}/legend`);
72
+ if (activeLayer) {
73
+ fetchLegend(`${activeLayer.map_service_url}/legend`);
74
+ }
41
75
  // eslint-disable-next-line react-hooks/exhaustive-deps
42
76
  }, [data, activeLayer.map_service_url]);
43
-
44
77
  return (
45
78
  <>
46
79
  <div style={{ margin: '10px 0' }}>
@@ -48,18 +81,19 @@ const LegendWidget = (props) => {
48
81
  <Grid.Row>
49
82
  <Grid.Column>
50
83
  <h3>Legend:</h3>
84
+ {!activeLayer && (
85
+ <p>
86
+ No layer found for legend. Please add a map layer from editor.
87
+ </p>
88
+ )}
51
89
  {legendLayers.length > 0 &&
52
90
  legendLayers.map((layer, i) => {
53
91
  return (
54
- <div
92
+ <LayerLegend
55
93
  key={i}
56
- style={{ display: 'flex', flexDirection: 'column' }}
57
- >
58
- <h5 style={{ marginTop: '10px', marginBottom: '5px' }}>
59
- {layer?.layerName}
60
- </h5>
61
- <LayerLegend data={layer.legend} />
62
- </div>
94
+ name={layer?.layerName}
95
+ data={layer?.legend}
96
+ />
63
97
  );
64
98
  })}
65
99
  </Grid.Column>
@@ -70,4 +104,4 @@ const LegendWidget = (props) => {
70
104
  );
71
105
  };
72
106
 
73
- export default LegendWidget;
107
+ export default React.memo(LegendWidget);
@@ -7,13 +7,23 @@ import PanelsSchema from './panelsSchema';
7
7
 
8
8
  const MapEditorWidget = (props) => {
9
9
  const [open, setOpen] = React.useState(false);
10
- const { onChange = {}, block = {}, value = {}, id } = props;
10
+ const { onChange = {}, id } = props;
11
+ const block = React.useMemo(() => props.block, [props.block]);
12
+ const value = React.useMemo(() => props.value, [props.value]);
13
+
11
14
  const [intValue, setIntValue] = React.useState(value);
12
15
 
13
16
  const dataForm = { map_data: intValue };
14
-
15
17
  const handleApplyChanges = () => {
16
18
  onChange(id, intValue);
19
+
20
+ //set map data for screenshot
21
+ // if (intValue.layers?.map_layers[0].map_layer?.map_service_url) {
22
+ // onChange(
23
+ // 'url',
24
+ // `${intValue.layers?.map_layers[0].map_layer?.map_service_url}?f=jsapi`,
25
+ // );
26
+ // }
17
27
  setOpen(false);
18
28
  };
19
29
 
@@ -56,45 +56,21 @@ const MapLayersSchema = {
56
56
  required: [],
57
57
  };
58
58
 
59
- const PrintSchema = {
60
- title: 'Print',
61
- fieldsets: [
62
- {
63
- id: 'default',
64
- title: 'Print',
65
- fields: ['show_print', 'position'],
66
- },
67
- ],
68
- properties: {
69
- show_print: {
70
- title: 'Show print',
71
- type: 'boolean',
72
- },
73
- position: {
74
- title: 'Print position',
75
- choices: ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map(
76
- (n) => {
77
- return [n, n];
78
- },
79
- ),
80
- },
81
- },
82
- required: [],
83
- };
84
-
85
- const ZoomSchema = ({ data = {} }) => {
86
- const centerOnExtent = data?.map_data?.zoom?.centerOnExtent;
59
+ const GeneralSchema = ({ data = {} }) => {
60
+ const centerOnExtent = data?.map_data?.general?.centerOnExtent;
87
61
 
88
62
  return {
89
- title: 'Zoom',
63
+ title: 'General',
90
64
  fieldsets: [
91
65
  {
92
66
  id: 'default',
93
67
  title: 'Zoom',
94
68
  fields: [
69
+ 'show_print',
70
+ 'print_position',
95
71
  'show_zoom',
96
72
  'centerOnExtent',
97
- 'position',
73
+ 'zoom_position',
98
74
  ...(!centerOnExtent ? ['zoom_level', 'long', 'lat'] : []),
99
75
  ],
100
76
  },
@@ -107,9 +83,10 @@ const ZoomSchema = ({ data = {} }) => {
107
83
  centerOnExtent: {
108
84
  title: 'Center on extent',
109
85
  type: 'boolean',
110
- description: 'This will override latitude/longitude/zoom level',
86
+ description:
87
+ 'This will override latitude/longitude/zoom level and will lock zoom/moving the map.',
111
88
  },
112
- position: {
89
+ zoom_position: {
113
90
  title: 'Zoom position',
114
91
  choices: ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map(
115
92
  (n) => {
@@ -129,13 +106,25 @@ const ZoomSchema = ({ data = {} }) => {
129
106
  title: 'Latitude',
130
107
  type: 'number',
131
108
  },
109
+ show_print: {
110
+ title: 'Show print',
111
+ type: 'boolean',
112
+ },
113
+ print_position: {
114
+ title: 'Print position',
115
+ choices: ['bottom-right', 'bottom-left', 'top-right', 'top-left'].map(
116
+ (n) => {
117
+ return [n, n];
118
+ },
119
+ ),
120
+ },
132
121
  },
133
122
  required: [],
134
123
  };
135
124
  };
136
125
 
137
126
  export default ({ data = {} }) => {
138
- const zoomSchema = ZoomSchema({ data });
127
+ const generalSchema = GeneralSchema({ data });
139
128
 
140
129
  return {
141
130
  title: 'Map Editor',
@@ -151,6 +140,10 @@ export default ({ data = {} }) => {
151
140
  title: 'Panels',
152
141
  widget: 'object_types_widget',
153
142
  schemas: [
143
+ {
144
+ id: 'general',
145
+ schema: generalSchema,
146
+ },
154
147
  {
155
148
  id: 'base',
156
149
  schema: BaseLayerSchema,
@@ -159,14 +152,6 @@ export default ({ data = {} }) => {
159
152
  id: 'layers',
160
153
  schema: MapLayersSchema,
161
154
  },
162
- {
163
- id: 'print',
164
- schema: PrintSchema,
165
- },
166
- {
167
- id: 'zoom',
168
- schema: zoomSchema,
169
- },
170
155
  ],
171
156
  },
172
157
  },
package/src/index.js CHANGED
@@ -5,6 +5,21 @@ import MapEditorWidget from './components/Blocks/EEAMap/components/widgets/MapEd
5
5
  import ObjectTypesWidget from './components/Blocks/EEAMap/components/widgets/ObjectTypesWidget';
6
6
 
7
7
  export default (config) => {
8
+ config.settings.allowed_cors_destinations = [
9
+ ...(config.settings.allowed_cors_destinations || []),
10
+ 'land.discomap.eea.europa.eu',
11
+ 'marine.discomap.eea.europa.eu',
12
+ 'climate.discomap.eea.europa.eu',
13
+ 'image.discomap.eea.europa.eu',
14
+ 'ldp.discomap.eea.europa.eu',
15
+ 'bio.discomap.eea.europa.eu',
16
+ 'air.discomap.eea.europa.eu',
17
+ 'maratlas.discomap.eea.europa.eu',
18
+ 'forest.discomap.eea.europa.eu',
19
+ 'water.discomap.eea.europa.eu',
20
+ 'noise.discomap.eea.europa.eu',
21
+ 'copernicus.discomap.eea.europa.eu',
22
+ ];
8
23
  config.blocks.blocksConfig.eea_map_block = {
9
24
  id: 'eea_map_block', // The name (id) of the block
10
25
  title: 'EEA Map', // The display name of the block