@eeacms/volto-eea-map 0.1.1 → 0.1.2

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,18 @@ 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.2](https://github.com/eea/volto-eea-map/compare/0.1.1...0.1.2)
8
+
9
+ - Legend only selected layer [`3474d79`](https://github.com/eea/volto-eea-map/commit/3474d7989321f656397c292bddc289f8f6329a8e)
10
+ - Query layer by existing fields [`52363f5`](https://github.com/eea/volto-eea-map/commit/52363f57a9ab4e49c7418e883bdf0c5bb30c1734)
11
+ - Cleanup [`d4e07b2`](https://github.com/eea/volto-eea-map/commit/d4e07b2fb89a5a27f5e4411047cb43e1c8add769)
12
+ - Description is slate [`86c983e`](https://github.com/eea/volto-eea-map/commit/86c983e7a4841ed07826c9015b70dbe931e9081a)
13
+
7
14
  #### [0.1.1](https://github.com/eea/volto-eea-map/compare/0.1.0...0.1.1)
8
15
 
16
+ > 26 July 2022
17
+
18
+ - Repo structure update [`#1`](https://github.com/eea/volto-eea-map/pull/1)
9
19
  - Lint [`d31819d`](https://github.com/eea/volto-eea-map/commit/d31819d98338fbc013dfd4506466e7c20b04aad5)
10
20
  - Remove object pick widget [`40c7bcd`](https://github.com/eea/volto-eea-map/commit/40c7bcd2305bbab1c21919a0ae82af3eb628b09d)
11
21
  - Add group layer [`74fd1af`](https://github.com/eea/volto-eea-map/commit/74fd1af2bce6347ce4a80758947e05b7c4a6d516)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-eea-map",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
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",
@@ -16,9 +16,15 @@
16
16
  "type": "git",
17
17
  "url": "git@github.com:eea/volto-eea-map.git"
18
18
  },
19
+ "addons": [
20
+ "@eeacms/volto-embed",
21
+ "volto-slate"
22
+ ],
19
23
  "dependencies": {
20
24
  "esri-loader": "3.5.0",
21
- "@plone/scripts": "*"
25
+ "@plone/scripts": "*",
26
+ "@eeacms/volto-embed": "^2.0.1",
27
+ "volto-slate": "*"
22
28
  },
23
29
  "devDependencies": {
24
30
  "@cypress/code-coverage": "^3.9.5",
@@ -5,6 +5,10 @@ import { Schema } from './Schema';
5
5
  import Webmap from './components/Webmap';
6
6
  import './styles/map.css';
7
7
  import ExtraViews from './components/widgets/ExtraViews';
8
+ import {
9
+ PrivacyProtection,
10
+ addPrivacyProtectionToSchema,
11
+ } from '@eeacms/volto-embed';
8
12
 
9
13
  const Edit = (props) => {
10
14
  const { block, data, onChangeBlock, selected } = props;
@@ -12,15 +16,18 @@ const Edit = (props) => {
12
16
 
13
17
  const { map_data = {}, height } = data;
14
18
  if (__SERVER__) return '';
19
+
15
20
  return (
16
- <>
17
- <Webmap data={map_data} height={height} />
18
- <ExtraViews data={data} />
21
+ <div>
22
+ <PrivacyProtection data={data} {...props}>
23
+ <Webmap data={map_data} height={height} />
24
+ <ExtraViews data={data} />
25
+ </PrivacyProtection>
19
26
  <SidebarPortal selected={selected}>
20
27
  <BlockDataForm
21
28
  block={block}
22
29
  title={schema.title}
23
- schema={schema}
30
+ schema={addPrivacyProtectionToSchema(schema)}
24
31
  onChangeField={(id, value) => {
25
32
  onChangeBlock(block, {
26
33
  ...data,
@@ -30,7 +37,7 @@ const Edit = (props) => {
30
37
  formData={data}
31
38
  />
32
39
  </SidebarPortal>
33
- </>
40
+ </div>
34
41
  );
35
42
  };
36
43
 
@@ -5,7 +5,7 @@ export const Schema = () => {
5
5
  {
6
6
  id: 'default',
7
7
  title: 'Default',
8
- fields: ['show_description', 'description', 'height', 'map_data'],
8
+ fields: ['description', 'height', 'map_data'],
9
9
  },
10
10
  ],
11
11
  properties: {
@@ -13,13 +13,9 @@ export const Schema = () => {
13
13
  title: 'Height',
14
14
  type: 'number',
15
15
  },
16
- show_description: {
17
- title: 'Show description',
18
- type: 'boolean',
19
- },
20
16
  description: {
21
17
  title: 'Description',
22
- type: 'text',
18
+ widget: 'slate',
23
19
  },
24
20
  map_data: {
25
21
  title: 'Edit map',
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import Webmap from './components/Webmap';
3
3
  import ExtraViews from './components/widgets/ExtraViews';
4
+ import { PrivacyProtection } from '@eeacms/volto-embed';
4
5
 
5
6
  const View = (props) => {
6
7
  const { data } = props || {};
@@ -10,10 +11,12 @@ const View = (props) => {
10
11
  if (__SERVER__) return '';
11
12
 
12
13
  return (
13
- <>
14
- <Webmap data={map_data} />
15
- <ExtraViews data={data} />
16
- </>
14
+ <div>
15
+ <PrivacyProtection data={data} {...props}>
16
+ <Webmap data={map_data} />
17
+ <ExtraViews data={data} />
18
+ </PrivacyProtection>
19
+ </div>
17
20
  );
18
21
  };
19
22
 
@@ -36,6 +36,7 @@ const Webmap = (props) => {
36
36
  const options = {
37
37
  css: true,
38
38
  };
39
+
39
40
  const mapRef = React.useRef();
40
41
  const [modules, setModules] = React.useState({});
41
42
  const modules_loaded = React.useRef(false);
@@ -88,12 +89,10 @@ const Webmap = (props) => {
88
89
  map_layers.length > 0 &&
89
90
  map_layers
90
91
  .filter(({ map_service_url, layer }) => map_service_url && layer)
91
- .map(({ map_service_url, layer }) => {
92
+ .map(({ map_service_url, layer, query = '' }) => {
92
93
  const url = `${map_service_url}/${layer}`;
93
94
 
94
95
  let mapLayer;
95
-
96
- //TODO: add more layers and error catch for unrecognized layer
97
96
  switch (layer.type) {
98
97
  case 'Raster Layer':
99
98
  mapLayer = new MapImageLayer({
@@ -101,7 +100,10 @@ const Webmap = (props) => {
101
100
  });
102
101
  break;
103
102
  case 'Feature Layer':
104
- mapLayer = new FeatureLayer({ url });
103
+ mapLayer = new FeatureLayer({
104
+ url,
105
+ definitionExpression: query,
106
+ });
105
107
  break;
106
108
  case 'Group Layer':
107
109
  mapLayer = new GroupLayer({ url });
@@ -112,10 +114,18 @@ const Webmap = (props) => {
112
114
  return mapLayer;
113
115
  });
114
116
 
117
+ // //this next layer will be used to filter country and intersect with existing layer
118
+ // const allCountriesLayer = new FeatureLayer({
119
+ // url:
120
+ // 'https://trial.discomap.eea.europa.eu/arcgis/rest/services/CLMS/WorldCountries/MapServer/1',
121
+ // definitionExpression: `(CNTR_ID = 'BG')`,
122
+ // });
123
+
115
124
  const map = new Map({
116
125
  basemap: base_layer || 'hybrid',
117
126
  layers,
118
127
  });
128
+
119
129
  const view = new MapView({
120
130
  container: mapRef.current,
121
131
  map,
@@ -2,19 +2,19 @@ import React from 'react';
2
2
  import { Button } from 'semantic-ui-react';
3
3
  import { Icon } from '@plone/volto/components';
4
4
 
5
- import TextView from '../TextView';
6
5
  import LegendWidget from './LegendWidget';
6
+ import { serializeNodes } from 'volto-slate/editor/render';
7
7
 
8
8
  import worldSVG from '@plone/volto/icons/world.svg';
9
9
  import downloadSVG from '@plone/volto/icons/download.svg';
10
10
 
11
11
  const ExtraViews = ({ data }) => {
12
- const { map_data = {}, description, show_description } = data;
12
+ const { map_data = {}, description } = data;
13
13
  const { general = {} } = map_data;
14
14
  return (
15
15
  <>
16
16
  {general.show_legend && <LegendWidget data={map_data} />}
17
- {show_description && description && <TextView text={description} />}
17
+ {description && serializeNodes(description)}
18
18
  {(general.show_download || general.show_viewer) && (
19
19
  <div
20
20
  style={{ display: 'flex', justifyContent: 'end', margin: '10px 0' }}
@@ -10,7 +10,14 @@ import { fetchArcgisData } from '../../utils';
10
10
  const LayerSelectWidget = (props) => {
11
11
  const { onChange, value = {}, id } = props;
12
12
 
13
- const { available_layers, map_data, map_service_url, layer } = value;
13
+ const {
14
+ available_layers,
15
+ map_data,
16
+ map_service_url,
17
+ layer,
18
+ fields = [],
19
+ query = '',
20
+ } = value;
14
21
 
15
22
  const [mapData, setMapData] = React.useState(map_data);
16
23
  const [checkColor, setCheckColor] = React.useState('');
@@ -20,6 +27,7 @@ const LayerSelectWidget = (props) => {
20
27
  const [availableLayers, setAvailableLayers] = React.useState(
21
28
  available_layers,
22
29
  );
30
+ const [layerQuery, setLayerQuery] = React.useState(query);
23
31
 
24
32
  const handleServiceUrlCheck = async () => {
25
33
  // fetch url, save it, populate layers options
@@ -36,6 +44,7 @@ const LayerSelectWidget = (props) => {
36
44
  );
37
45
  }
38
46
  onChange(id, {
47
+ ...value,
39
48
  layer: selectedLayer,
40
49
  map_service_url: serviceUrl,
41
50
  available_layers: availableLayers,
@@ -47,13 +56,32 @@ const LayerSelectWidget = (props) => {
47
56
  }
48
57
  };
49
58
 
50
- const handleSelectLayer = (layer) => {
59
+ const handleLayerFetch = async (service_url, id) => {
60
+ try {
61
+ let fullLayer = await fetchArcgisData(`${service_url}/${id}`);
62
+ return fullLayer;
63
+ } catch (e) {}
64
+ };
65
+
66
+ const handleSelectLayer = async (layer) => {
67
+ const fullLayer = await handleLayerFetch(serviceUrl, layer.id);
51
68
  setSelectedLayer(layer);
52
69
  onChange(id, {
70
+ ...value,
53
71
  layer,
72
+ fields: fullLayer.fields,
54
73
  map_service_url: serviceUrl,
55
74
  available_layers: availableLayers,
56
75
  map_data: mapData,
76
+ query: '',
77
+ });
78
+ setLayerQuery('');
79
+ };
80
+
81
+ const handleQueryLayer = () => {
82
+ onChange(id, {
83
+ ...value,
84
+ query: layerQuery,
57
85
  });
58
86
  };
59
87
 
@@ -104,7 +132,36 @@ const LayerSelectWidget = (props) => {
104
132
  value={selectedLayer}
105
133
  />
106
134
  </Grid.Row>
107
- <Grid.Row stretched></Grid.Row>
135
+ <h4>Query Layer</h4>
136
+ <Grid.Row stretched>
137
+ <Input
138
+ type="text"
139
+ onChange={(e, { value }) => setLayerQuery(value)}
140
+ style={{ width: '100%' }}
141
+ value={layerQuery}
142
+ />
143
+ <Button
144
+ style={{
145
+ margin: '10px 0',
146
+ display: 'flex',
147
+ alignItems: 'center',
148
+ }}
149
+ color={checkColor}
150
+ onClick={handleQueryLayer}
151
+ >
152
+ <p style={{ fontSize: '14px', margin: '0', marginRight: '5px' }}>
153
+ Query Layer
154
+ </p>
155
+ </Button>
156
+ </Grid.Row>
157
+ <p style={{ fontSize: '12px', fontWeight: 'bold' }}>
158
+ Available Fields:
159
+ </p>
160
+ {fields &&
161
+ fields.length > 0 &&
162
+ fields.map((field, id) => (
163
+ <p style={{ fontSize: '12px' }}>{field.alias}</p>
164
+ ))}
108
165
  </Grid>
109
166
  </div>
110
167
  );
@@ -27,13 +27,18 @@ const LegendWidget = (props) => {
27
27
  const activeLayer = map_layers.length > 0 ? map_layers[0]?.map_layer : '';
28
28
  const fetchLegend = async (url) => {
29
29
  let legendData = await fetchArcgisData(url);
30
- const { layers = [] } = legendData;
31
30
 
32
- setLegendLayers(layers);
31
+ //TODO: configure this for multiple layers
32
+ const { layers = [] } = legendData;
33
+ const selectedLayerLedend = layers.filter(
34
+ (l, i) => l.layerId === activeLayer.layer.id,
35
+ );
36
+ setLegendLayers(selectedLayerLedend);
33
37
  };
34
38
 
35
39
  React.useEffect(() => {
36
- fetchLegend(activeLayer.map_service_url + '/legend');
40
+ fetchLegend(`${activeLayer.map_service_url}/legend`);
41
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
42
  }, [data, activeLayer.map_service_url]);
38
43
 
39
44
  return (
@@ -47,7 +52,9 @@ const LegendWidget = (props) => {
47
52
  legendLayers.map((layer, index) => {
48
53
  return (
49
54
  <div style={{ display: 'flex', flexDirection: 'column' }}>
50
- <h5>{layer?.layerName}</h5>
55
+ <h5 style={{ marginTop: '10px', marginBottom: '5px' }}>
56
+ {layer?.layerName}
57
+ </h5>
51
58
  <LayerLegend data={layer.legend} />
52
59
  </div>
53
60
  );
@@ -1,7 +0,0 @@
1
- import React from 'react';
2
-
3
- const TextView = ({ text }) => {
4
- return <p className="map-text-view">{text}</p>;
5
- };
6
-
7
- export default TextView;