@eeacms/volto-eea-map 0.1.4 → 0.1.7

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,40 @@ 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.7](https://github.com/eea/volto-eea-map/compare/0.1.6...0.1.7)
8
+
9
+ - fix height coming through in view [`39d4d28`](https://github.com/eea/volto-eea-map/commit/39d4d287a4fe86890f5fad8d9050130b496dfe70)
10
+ - Connected visualization view-edit [`52a8e21`](https://github.com/eea/volto-eea-map/commit/52a8e2187cb2e3a7db660ae4b6b5610c88be5083)
11
+ - map_view is map_editor_widget, add view component for content-type [`dc227f9`](https://github.com/eea/volto-eea-map/commit/dc227f9bbb259b59739a3694dc69f0fcca661137)
12
+ - Add map visualization widget [`affd84c`](https://github.com/eea/volto-eea-map/commit/affd84ca8753214c07f2f0756a13f08f5cf0a048)
13
+
14
+ #### [0.1.6](https://github.com/eea/volto-eea-map/compare/0.1.5...0.1.6)
15
+
16
+ > 5 August 2022
17
+
18
+ - Develop [`#6`](https://github.com/eea/volto-eea-map/pull/6)
19
+ - Lint fix [`f5561d1`](https://github.com/eea/volto-eea-map/commit/f5561d1581201bd635b4e53e8a46decaf684438f)
20
+ - Map improvements [`c75d16c`](https://github.com/eea/volto-eea-map/commit/c75d16c265136d9f676e194540e613bb742fb51b)
21
+
22
+ #### [0.1.5](https://github.com/eea/volto-eea-map/compare/0.1.4...0.1.5)
23
+
24
+ > 4 August 2022
25
+
26
+ - Develop [`#5`](https://github.com/eea/volto-eea-map/pull/5)
27
+ - Center on extent only on map load [`b63f586`](https://github.com/eea/volto-eea-map/commit/b63f586e0df68faa755bb0d25e297530e36ef7c9)
28
+ - Configure proxy for all map subdomains [`0f19030`](https://github.com/eea/volto-eea-map/commit/0f19030569e1f77b1ff7657669e876519712840f)
29
+ - Prevent unnecessary rerenders of ma [`8752384`](https://github.com/eea/volto-eea-map/commit/8752384b3bbd7b564a25b3e4347c47692106f556)
30
+ - Prevent unnecessary rerenders of map [`00a3e64`](https://github.com/eea/volto-eea-map/commit/00a3e64585748a36ef476b2d75540bdd43778486)
31
+ - Clear print schema [`29ed979`](https://github.com/eea/volto-eea-map/commit/29ed9795812d6673f8fb91ac73e53e4e132ed55a)
32
+ - Move zoom & print in general tab [`06c4996`](https://github.com/eea/volto-eea-map/commit/06c499651217715e1793d2a75fb72668dc1de223)
33
+ - Clear [`9aa7bf1`](https://github.com/eea/volto-eea-map/commit/9aa7bf1591b22a2941ce0f269ef133d687affc15)
34
+ - Disable url for screenshot atm [`1ef18fc`](https://github.com/eea/volto-eea-map/commit/1ef18fc8b7516c88c743cffb10b5eb340161d58d)
35
+
7
36
  #### [0.1.4](https://github.com/eea/volto-eea-map/compare/0.1.3...0.1.4)
8
37
 
38
+ > 3 August 2022
39
+
40
+ - Map updates [`#4`](https://github.com/eea/volto-eea-map/pull/4)
9
41
  - Configure Privacy protection screenshot data [`49097c0`](https://github.com/eea/volto-eea-map/commit/49097c0b7aa8657e626d5a49dd0eed84f5e71e78)
10
42
  - Expandable Legend [`6edda2f`](https://github.com/eea/volto-eea-map/commit/6edda2fafd8a2a61f3f1f10c47a9ca5bb35a0355)
11
43
  - Catch for no data [`7cef4e6`](https://github.com/eea/volto-eea-map/commit/7cef4e641650ede23e37ca9116130db1ef0a18db)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
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}
@@ -6,14 +6,13 @@ import { PrivacyProtection } from '@eeacms/volto-embed';
6
6
  const View = (props) => {
7
7
  const { data } = props || {};
8
8
 
9
- const { map_data = {} } = data;
9
+ const { map_data = {}, height = '' } = data;
10
10
 
11
11
  if (__SERVER__) return '';
12
-
13
12
  return (
14
13
  <div>
15
14
  <PrivacyProtection data={data} {...props}>
16
- <Webmap data={map_data} />
15
+ <Webmap data={map_data} height={height} />
17
16
  <ExtraViews data={data} />
18
17
  </PrivacyProtection>
19
18
  </div>
@@ -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);
@@ -18,7 +18,7 @@ const ExtraViews = ({ data }) => {
18
18
  } = data;
19
19
 
20
20
  return (
21
- <>
21
+ <div className="extra-eea-map-content">
22
22
  {map_data.layers?.map_layers[0] && (show_download || show_viewer) && (
23
23
  <div
24
24
  style={{ display: 'flex', justifyContent: 'end', margin: '10px 0' }}
@@ -56,7 +56,7 @@ const ExtraViews = ({ data }) => {
56
56
  )}
57
57
  {show_legend && <LegendWidget data={map_data} />}
58
58
  {description && serializeNodes(description)}
59
- </>
59
+ </div>
60
60
  );
61
61
  };
62
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) {
@@ -50,12 +50,13 @@ const LayerLegend = ({ data, name }) => {
50
50
  };
51
51
 
52
52
  const LegendWidget = (props) => {
53
- const { data = {} } = props;
53
+ const data = React.useMemo(() => props.data, [props.data]);
54
54
  const { layers = {} } = data;
55
55
  const { map_layers = [] } = layers;
56
56
  const [legendLayers, setLegendLayers] = React.useState([]);
57
57
 
58
58
  const activeLayer = map_layers.length > 0 ? map_layers[0]?.map_layer : '';
59
+
59
60
  const fetchLegend = async (url) => {
60
61
  let legendData = await fetchArcgisData(url);
61
62
 
@@ -103,4 +104,4 @@ const LegendWidget = (props) => {
103
104
  );
104
105
  };
105
106
 
106
- export default LegendWidget;
107
+ export default React.memo(LegendWidget);
@@ -7,7 +7,10 @@ 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 };
@@ -15,12 +18,12 @@ const MapEditorWidget = (props) => {
15
18
  onChange(id, intValue);
16
19
 
17
20
  //set map data for screenshot
18
- if (intValue.layers?.map_layers[0].map_layer?.map_service_url) {
19
- onChange(
20
- 'url',
21
- `${intValue.layers?.map_layers[0].map_layer?.map_service_url}?f=jsapi`,
22
- );
23
- }
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
+ // }
24
27
  setOpen(false);
25
28
  };
26
29
 
@@ -0,0 +1,94 @@
1
+ import React from 'react';
2
+ import { Modal, Button, Grid } from 'semantic-ui-react';
3
+ import Webmap from '../Webmap';
4
+ import { FormFieldWrapper, InlineForm } from '@plone/volto/components';
5
+ import { VisibilitySensor } from '@eeacms/volto-datablocks/components';
6
+
7
+ import PanelsSchema from './panelsSchema';
8
+
9
+ const VisualizationEditorWidget = (props) => {
10
+ const [open, setOpen] = React.useState(false);
11
+ const { onChange = {}, id } = props;
12
+ const block = React.useMemo(() => props.block, [props.block]);
13
+ const value = React.useMemo(() => props.value, [props.value]);
14
+
15
+ const [intValue, setIntValue] = React.useState(value);
16
+
17
+ const dataForm = { map_data: intValue };
18
+ const handleApplyChanges = () => {
19
+ onChange(id, intValue);
20
+ setOpen(false);
21
+ };
22
+
23
+ const handleClose = () => {
24
+ setIntValue(value);
25
+ setOpen(false);
26
+ };
27
+
28
+ const handleChangeField = (id, fieldVal) => {
29
+ setIntValue(fieldVal);
30
+ };
31
+
32
+ let schema = PanelsSchema({ data: dataForm });
33
+
34
+ return (
35
+ <FormFieldWrapper {...props}>
36
+ <Button
37
+ floated="right"
38
+ size="tiny"
39
+ onClick={(e) => {
40
+ e.preventDefault();
41
+ e.stopPropagation();
42
+ setOpen(true);
43
+ }}
44
+ >
45
+ Open Map Editor
46
+ </Button>
47
+ {open && (
48
+ <Modal
49
+ id="map-editor-modal"
50
+ style={{ width: '95% !important' }}
51
+ open={true}
52
+ >
53
+ <Modal.Content scrolling>
54
+ <Grid>
55
+ <Grid.Row>
56
+ <Grid.Column width={4}>
57
+ <InlineForm
58
+ block={block}
59
+ title={schema.title}
60
+ schema={schema}
61
+ onChangeField={(id, value) => {
62
+ handleChangeField(id, value);
63
+ }}
64
+ formData={dataForm}
65
+ />
66
+ </Grid.Column>
67
+ <Grid.Column width={8}>
68
+ <VisibilitySensor>
69
+ <Webmap data={intValue} editMode={true} />
70
+ </VisibilitySensor>
71
+ </Grid.Column>
72
+ </Grid.Row>
73
+ </Grid>
74
+ </Modal.Content>
75
+ <Modal.Actions>
76
+ <Grid>
77
+ <Grid.Row>
78
+ <Grid.Column width={8}></Grid.Column>
79
+ <Grid.Column width={4}>
80
+ <Button onClick={() => handleClose()}>Close</Button>
81
+ <Button color="green" onClick={() => handleApplyChanges()}>
82
+ Apply changes
83
+ </Button>
84
+ </Grid.Column>
85
+ </Grid.Row>
86
+ </Grid>
87
+ </Modal.Actions>
88
+ </Modal>
89
+ )}
90
+ </FormFieldWrapper>
91
+ );
92
+ };
93
+
94
+ export default VisualizationEditorWidget;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import Webmap from '../Webmap';
3
+
4
+ const VisualizationView = (props) => {
5
+ const { content = {} } = props;
6
+
7
+ const { map_editor_widget = {} } = content;
8
+
9
+ return (
10
+ <div>
11
+ <Webmap data={map_editor_widget} />
12
+ </div>
13
+ );
14
+ };
15
+
16
+ export default VisualizationView;
@@ -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
@@ -3,8 +3,25 @@ import world from '@plone/volto/icons/world.svg';
3
3
  import LayerSelectWidget from './components/Blocks/EEAMap/components/widgets/LayerSelectWidget';
4
4
  import MapEditorWidget from './components/Blocks/EEAMap/components/widgets/MapEditorWidget';
5
5
  import ObjectTypesWidget from './components/Blocks/EEAMap/components/widgets/ObjectTypesWidget';
6
+ import VisualizationEditorWidget from './components/Blocks/EEAMap/components/widgets/VisualizationEditorWidget';
7
+ import VisualizationView from './components/Blocks/EEAMap/components/widgets/VisualizationView';
6
8
 
7
9
  export default (config) => {
10
+ config.settings.allowed_cors_destinations = [
11
+ ...(config.settings.allowed_cors_destinations || []),
12
+ 'land.discomap.eea.europa.eu',
13
+ 'marine.discomap.eea.europa.eu',
14
+ 'climate.discomap.eea.europa.eu',
15
+ 'image.discomap.eea.europa.eu',
16
+ 'ldp.discomap.eea.europa.eu',
17
+ 'bio.discomap.eea.europa.eu',
18
+ 'air.discomap.eea.europa.eu',
19
+ 'maratlas.discomap.eea.europa.eu',
20
+ 'forest.discomap.eea.europa.eu',
21
+ 'water.discomap.eea.europa.eu',
22
+ 'noise.discomap.eea.europa.eu',
23
+ 'copernicus.discomap.eea.europa.eu',
24
+ ];
8
25
  config.blocks.blocksConfig.eea_map_block = {
9
26
  id: 'eea_map_block', // The name (id) of the block
10
27
  title: 'EEA Map', // The display name of the block
@@ -37,5 +54,10 @@ export default (config) => {
37
54
  config.widgets.widget.map_layers_widget = LayerSelectWidget;
38
55
  config.widgets.widget.object_types_widget = ObjectTypesWidget;
39
56
 
57
+ //map editor for the visualization(content-type)
58
+ config.widgets.id.map_editor_widget = VisualizationEditorWidget;
59
+ //map viewer for the visualization(content-type)
60
+ config.views.contentTypesViews.map_visualization = VisualizationView;
61
+
40
62
  return config;
41
63
  };