@eeacms/volto-arcgis-block 0.1.13 → 0.1.14

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,20 @@ 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.14](https://github.com/eea/volto-arcgis-block/compare/0.1.13...0.1.14)
8
+
9
+ - Bugfix on popup [`#34`](https://github.com/eea/volto-arcgis-block/pull/34)
10
+ - Removed setTimeout [`8de18d1`](https://github.com/eea/volto-arcgis-block/commit/8de18d1991294bb7a5ff56afd320160fb038bad2)
11
+ - Update 'const' & 'let', extracted variables to a config file [`f11b76c`](https://github.com/eea/volto-arcgis-block/commit/f11b76c8443353287850437f1c5299ae41fee187)
12
+ - Fixed popup data when changing continent [`3329795`](https://github.com/eea/volto-arcgis-block/commit/33297951141425738cd40a588ae861226a743e25)
13
+ - Code refactorization [`1e144a8`](https://github.com/eea/volto-arcgis-block/commit/1e144a802dd40cba572d6711e166d31c82b164ef)
14
+ - Added selectedPoint to be able to go back [`4c61116`](https://github.com/eea/volto-arcgis-block/commit/4c611163a9b23afb57a52cb39e345614e2824d92)
15
+
7
16
  #### [0.1.13](https://github.com/eea/volto-arcgis-block/compare/0.1.12...0.1.13)
8
17
 
18
+ > 21 October 2021
19
+
20
+ - Develop [`#33`](https://github.com/eea/volto-arcgis-block/pull/33)
9
21
  - Bugfix and improvements on use-cases [`#32`](https://github.com/eea/volto-arcgis-block/pull/32)
10
22
  - Map bottom margin [`0790f2c`](https://github.com/eea/volto-arcgis-block/commit/0790f2c870fb87073aa2b15d57edf66a9548b41e)
11
23
  - Calculate corresponding zoom with given bbox [`a766e7c`](https://github.com/eea/volto-arcgis-block/commit/a766e7cb04e957eb1d8d08e403dfd4995690bc7c)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-arcgis-block",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "volto-arcgis-block: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: CodeSyntax",
@@ -77,7 +77,7 @@ class InfoWidget extends React.Component {
77
77
  * @returns useCasesRegion
78
78
  */
79
79
  getDataBrief(data) {
80
- const children = data.map((val) => {
80
+ let children = data.map((val) => {
81
81
  return (
82
82
  <>
83
83
  <div
@@ -113,7 +113,7 @@ class InfoWidget extends React.Component {
113
113
  * @returns useCasesDOM
114
114
  */
115
115
  showBrief(selectedRegion) {
116
- const regionFeatures = [];
116
+ let regionFeatures = [];
117
117
  if (mapViewer.state.useCaseLevel === 2) {
118
118
  for (let feature in this.features) {
119
119
  if (this.features[feature].attributes.Region === selectedRegion) {
@@ -183,8 +183,8 @@ class InfoWidget extends React.Component {
183
183
  * Transfrom raw data to ordered data by Service products
184
184
  */
185
185
  proccessDataSummary() {
186
- const serviceProducts = this.getDifferentproductUsed(this.features);
187
- const elements = [];
186
+ let serviceProducts = this.getDifferentproductUsed(this.features);
187
+ let elements = [];
188
188
 
189
189
  for (let serviceProduct in serviceProducts) {
190
190
  processedData[serviceProducts[serviceProduct]] = [];
@@ -208,7 +208,7 @@ class InfoWidget extends React.Component {
208
208
  * @returns lateralMenuDOM
209
209
  */
210
210
  getDataSummary(data, Copernicus_Land_Monitoring_Service_products_used) {
211
- const children = this.getDataBrief(data);
211
+ let children = this.getDataBrief(data);
212
212
 
213
213
  return (
214
214
  <>
@@ -247,7 +247,7 @@ class InfoWidget extends React.Component {
247
247
  */
248
248
  setDOMSummary() {
249
249
  this.proccessDataSummary();
250
- const DOMElements = [];
250
+ let DOMElements = [];
251
251
  for (let product_use_name in processedData)
252
252
  DOMElements.push(
253
253
  this.getDataSummary(processedData[product_use_name], product_use_name),
@@ -326,17 +326,6 @@ class InfoWidget extends React.Component {
326
326
  }
327
327
  }
328
328
 
329
- /**
330
- * It highlights the information displayed for a use case on the infoWidget.
331
- * */
332
- highligtInfo() {}
333
-
334
- /**
335
- * Highlights the point on the map corresponding to the use case
336
- * @param {*} coords
337
- */
338
- highligtPoint(coords) {}
339
-
340
329
  /**
341
330
  * This method will return the corresponding lateral menu depending on layers.
342
331
  * @returns HTML
@@ -350,10 +339,10 @@ class InfoWidget extends React.Component {
350
339
  case 3:
351
340
  return this.showBrief(mapViewer.state.selectedUseCases);
352
341
  case 4:
353
- const title = mapViewer.state.selectedUseCase.Use_case_title;
354
- const bbox = mapViewer.state.selectedUseCase.BBOX;
355
- const region = mapViewer.state.selectedUseCase.Region;
356
- const country = mapViewer.state.selectedUseCase.Spatial_coverage;
342
+ let title = mapViewer.state.selectedUseCase.Use_case_title;
343
+ let bbox = mapViewer.state.selectedUseCase.BBOX;
344
+ let region = mapViewer.state.selectedUseCase.Region;
345
+ let country = mapViewer.state.selectedUseCase.Spatial_coverage;
357
346
  navigationControl.navigateToLocation(
358
347
  bbox,
359
348
  title,
@@ -3,6 +3,8 @@ class LayerControl {
3
3
  constructor(props) {
4
4
  this.map = props.map;
5
5
  this.view = props.view;
6
+ this.worldDimensions = props.worldDimensions;
7
+ this.maxZoom = props.maxZoom;
6
8
  mapViewer = props.mapViewer;
7
9
  FeatureLayer = props.FeatureLayer;
8
10
  Extent = props.Extent;
@@ -14,7 +16,7 @@ class LayerControl {
14
16
  * @returns FeatureLayer
15
17
  */
16
18
  createLayer(layerInfo) {
17
- const newLayer = new FeatureLayer({
19
+ let newLayer = new FeatureLayer({
18
20
  url: layerInfo.url,
19
21
  id: layerInfo.id,
20
22
  outFields: ['*'],
@@ -37,7 +39,7 @@ class LayerControl {
37
39
  * @param {String} id
38
40
  */
39
41
  showLayer(id) {
40
- const items = this.map.layers.items;
42
+ let items = this.map.layers.items;
41
43
  for (let layer in items)
42
44
  items[layer].id === id && (items[layer].visible = true);
43
45
  }
@@ -47,7 +49,7 @@ class LayerControl {
47
49
  * @param {String} id
48
50
  */
49
51
  hideLayer(id) {
50
- const items = this.map.layers.items;
52
+ let items = this.map.layers.items;
51
53
  for (let layer in items) {
52
54
  items[layer].id === id && (items[layer].visible = false);
53
55
  }
@@ -58,7 +60,7 @@ class LayerControl {
58
60
  * @param {String} id
59
61
  */
60
62
  removeLayer(id) {
61
- const items = this.map.layers.items;
63
+ let items = this.map.layers.items;
62
64
  for (let layer in items)
63
65
  items[layer].id === id && this.map.remove(items[layer]);
64
66
  }
@@ -68,39 +70,45 @@ class LayerControl {
68
70
  * @param {Array} boundingBox
69
71
  */
70
72
  zoomToExtent(boundingBox) {
71
- const newExtent = new Extent(
73
+ let newExtent = new Extent(
72
74
  boundingBox[0],
73
75
  boundingBox[1],
74
76
  boundingBox[2],
75
77
  boundingBox[3],
76
78
  );
77
- const zoomOnBounding = this.getBoundsZoomLevel(boundingBox);
79
+ let zoomOnBounding = this.getBoundsZoomLevel(boundingBox);
78
80
  this.view.zoom = zoomOnBounding;
79
81
  this.view.extent = newExtent;
80
82
  }
81
83
 
82
84
  getBoundsZoomLevel(bounds) {
83
- const mapDim = { height: this.view.height, width: this.view.width };
84
- const WORLD_DIM = { height: 256, width: 256 };
85
- const ZOOM_MAX = 5;
85
+ let mapDim = { height: this.view.height, width: this.view.width };
86
86
 
87
- const ne = [bounds[2], bounds[3]];
88
- const sw = [bounds[0], bounds[1]];
87
+ let ne = [bounds[2], bounds[3]];
88
+ let sw = [bounds[0], bounds[1]];
89
89
 
90
- const latFraction = (this.latRad(ne[1]) - this.latRad(sw[1])) / Math.PI;
90
+ let latFraction = (this.latRad(ne[1]) - this.latRad(sw[1])) / Math.PI;
91
91
 
92
- const lngDiff = ne[0] - sw[0];
93
- const lngFraction = (lngDiff < 0 ? lngDiff + 360 : lngDiff) / 360;
92
+ let lngDiff = ne[0] - sw[0];
93
+ let lngFraction = (lngDiff < 0 ? lngDiff + 360 : lngDiff) / 360;
94
94
 
95
- const latZoom = this.zoom(mapDim.height, WORLD_DIM.height, latFraction);
96
- const lngZoom = this.zoom(mapDim.width, WORLD_DIM.width, lngFraction);
95
+ let latZoom = this.zoom(
96
+ mapDim.height,
97
+ this.worldDimensions.height,
98
+ latFraction,
99
+ );
100
+ let lngZoom = this.zoom(
101
+ mapDim.width,
102
+ this.worldDimensions.width,
103
+ lngFraction,
104
+ );
97
105
 
98
- return Math.min(latZoom, lngZoom, ZOOM_MAX);
106
+ return Math.min(latZoom, lngZoom, this.zoomMax);
99
107
  //TODO calculate the corresponding level of zoom automatically
100
108
  }
101
109
  latRad(lat) {
102
- const sin = Math.sin((lat * Math.PI) / 180);
103
- const radX2 = Math.log((1 + sin) / (1 - sin)) / 2;
110
+ let sin = Math.sin((lat * Math.PI) / 180);
111
+ let radX2 = Math.log((1 + sin) / (1 - sin)) / 2;
104
112
  return Math.max(Math.min(radX2, Math.PI), -Math.PI) / 2;
105
113
  }
106
114
 
@@ -115,11 +123,11 @@ class LayerControl {
115
123
  * @returns
116
124
  */
117
125
  async getPointInfo(screenPoint, options) {
118
- const pointInformation = await this.view
126
+ let pointInformation = await this.view
119
127
  .hitTest(screenPoint, options && options)
120
128
  .then(function (response) {
121
129
  if (response.results.length) {
122
- const graphic = response.results.filter(function (result) {
130
+ let graphic = response.results.filter(function (result) {
123
131
  return result.graphic;
124
132
  });
125
133
  return graphic[0].graphic.attributes;
@@ -129,7 +137,7 @@ class LayerControl {
129
137
  }
130
138
 
131
139
  getRegionInfo(region, callback) {
132
- const xmlhttp = new XMLHttpRequest();
140
+ let xmlhttp = new XMLHttpRequest();
133
141
  const url = `${mapViewer.spatialConfig.url}/query?where=Region+%3D+%27${region}%27&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&having=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&queryByDistance=&returnExtentOnly=false&datumTransformation=&parameterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson`;
134
142
  xmlhttp.onreadystatechange = () => {
135
143
  if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
@@ -140,7 +148,7 @@ class LayerControl {
140
148
  }
141
149
 
142
150
  checkIfMorePoints(latLon, callback) {
143
- const xmlhttp = new XMLHttpRequest();
151
+ let xmlhttp = new XMLHttpRequest();
144
152
  const url = `${mapViewer.spatialConfig.url}/query?where=Latitude%3D+${latLon.latitude}+AND+Longitude%3D+${latLon.longitude}&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=*&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=&having=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&queryByDistance=&returnExtentOnly=false&datumTransformation=&parameterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson`;
145
153
  xmlhttp.onreadystatechange = () => {
146
154
  if (xmlhttp.readyState === 4 && xmlhttp.status === 200)
@@ -154,6 +162,33 @@ class LayerControl {
154
162
  return JSON.parse(xmlhttp.responseText);
155
163
  }
156
164
 
165
+ /**
166
+ * It highlights the information displayed for a use case on the infoWidget.
167
+ * */
168
+ highlightInfo(response) {
169
+ if (response.results.length > 1) {
170
+ if (
171
+ response.results[0].graphic.geometry !== null &&
172
+ mapViewer.popupOnce
173
+ ) {
174
+ mapViewer.popupOnce = false;
175
+ document.querySelector('.map').style.cursor = 'pointer';
176
+ document
177
+ .querySelector(
178
+ '#use_case_' + response.results[0].graphic.attributes.OBJECTID,
179
+ )
180
+ .classList.add('selected');
181
+ }
182
+ } else {
183
+ mapViewer.popupOnce = true;
184
+ document.querySelector('.map').style.cursor = '';
185
+ if (document.querySelector('.use-case-element.selected'))
186
+ document
187
+ .querySelector('.use-case-element.selected')
188
+ .classList.remove('selected');
189
+ }
190
+ }
191
+
157
192
  /**
158
193
  * Order retreived features by Service product name
159
194
  * @param {Object} features
@@ -36,7 +36,7 @@ class NavigationControl extends React.Component {
36
36
  * @param {FeatureLayer} layer
37
37
  */
38
38
  navigateToRegion(bBox, region, layer) {
39
- const boundingBox = this.clearBBOX(bBox);
39
+ let boundingBox = this.clearBBOX(bBox);
40
40
  this.layerControl.zoomToExtent(boundingBox);
41
41
  this.layerControl.hideLayer(layerRegion.id);
42
42
  this.layerControl.showLayer(layerSpatial.id);
@@ -64,7 +64,7 @@ class NavigationControl extends React.Component {
64
64
  * @returns Array BBox
65
65
  */
66
66
  clearBBOX(stringBbox) {
67
- const floatBbox = [];
67
+ let floatBbox = [];
68
68
  // typeof stringBbox !== 'string' && (stringBbox = stringBbox.toString());
69
69
  stringBbox = stringBbox.replace('[', '');
70
70
  stringBbox = stringBbox.replace(']', '');
@@ -28,6 +28,7 @@ class UseCasesMapViewer extends React.Component {
28
28
  this.map = null;
29
29
  this.id = props.id;
30
30
  this.popupOnce = false;
31
+ this.popupRegion = '';
31
32
  this.mapClass = classNames('map-container', {
32
33
  [`${props.customClass}`]: props.customClass || null,
33
34
  });
@@ -123,6 +124,8 @@ class UseCasesMapViewer extends React.Component {
123
124
  map: this.map,
124
125
  view: this.view,
125
126
  mapViewer: this,
127
+ worldDimensions: this.mapCfg.worldDimensions,
128
+ maxZoom: this.mapCfg.maxZoom,
126
129
  FeatureLayer: FeatureLayer,
127
130
  Extent: Extent,
128
131
  });
@@ -134,7 +137,7 @@ class UseCasesMapViewer extends React.Component {
134
137
 
135
138
  layerSpatial.renderer = this.spatialConfig.render;
136
139
 
137
- const layerRegion = layerControl.createLayer({
140
+ let layerRegion = layerControl.createLayer({
138
141
  id: this.regionConfig.id,
139
142
  url: this.regionConfig.url,
140
143
  });
@@ -179,17 +182,7 @@ class UseCasesMapViewer extends React.Component {
179
182
  * @param {FeatureLayer} layerSpatial
180
183
  */
181
184
  setMapFunctions(view, layerControl, navigationControl, layerSpatial) {
182
- const prohibitedKeys = [
183
- '+',
184
- '-',
185
- 'Shift',
186
- '_',
187
- '=',
188
- 'ArrowUp',
189
- 'ArrowDown',
190
- 'ArrowLeft',
191
- 'ArrowRight',
192
- ];
185
+ const prohibitedKeys = this.mapCfg.prohibitedKeys;
193
186
 
194
187
  view.on('mouse-wheel', function (event) {
195
188
  event.stopPropagation();
@@ -214,27 +207,27 @@ class UseCasesMapViewer extends React.Component {
214
207
  event.stopPropagation();
215
208
  });
216
209
  view.on('key-down', function (event) {
217
- const keyPressed = event.key;
210
+ let keyPressed = event.key;
218
211
  if (prohibitedKeys.indexOf(keyPressed) !== -1) {
219
212
  event.stopPropagation();
220
213
  }
221
214
  });
222
215
  view.on('key-down', ['Shift'], function (event) {
223
- const keyPressed = event.key;
216
+ let keyPressed = event.key;
224
217
  if (prohibitedKeys.indexOf(keyPressed) !== -1) {
225
218
  event.stopPropagation();
226
219
  }
227
220
  });
228
221
  view.on('click', (e) => {
229
- const screenPoint = { x: e.x, y: e.y };
222
+ let screenPoint = { x: e.x, y: e.y };
230
223
 
231
224
  (async () => {
232
225
  let selectedPoint = await layerControl.getPointInfo(screenPoint);
233
226
  if (selectedPoint.BBOX) {
234
- const selectedRegion = selectedPoint.Region;
235
- const boundingBox = selectedPoint.BBOX;
236
- const selectedTitle = selectedPoint.Use_case_title;
237
- const selectedSpatial = selectedPoint.Spatial_coverage;
227
+ let selectedRegion = selectedPoint.Region;
228
+ let boundingBox = selectedPoint.BBOX;
229
+ let selectedTitle = selectedPoint.Use_case_title;
230
+ let selectedSpatial = selectedPoint.Spatial_coverage;
238
231
  if (this.state.useCaseLevel === 1 && selectedPoint.COUNT > 1) {
239
232
  navigationControl.navigateToRegion(
240
233
  boundingBox,
@@ -244,6 +237,7 @@ class UseCasesMapViewer extends React.Component {
244
237
  this.setState((prevState) => {
245
238
  return {
246
239
  useCaseLevel: 2,
240
+ selectedUseCase: selectedPoint,
247
241
  region: selectedRegion,
248
242
  previousState: prevState.useCaseLevel,
249
243
  };
@@ -274,7 +268,7 @@ class UseCasesMapViewer extends React.Component {
274
268
  },
275
269
  );
276
270
  } else {
277
- const latLon = {
271
+ let latLon = {
278
272
  latitude: selectedPoint.Latitude,
279
273
  longitude: selectedPoint.Longitude,
280
274
  };
@@ -283,6 +277,7 @@ class UseCasesMapViewer extends React.Component {
283
277
  MapViewerThis.setState((prevState) => {
284
278
  return {
285
279
  useCaseLevel: 3,
280
+ selectedUseCase: selectedPoint,
286
281
  selectedUseCases: data.features,
287
282
  previousState: prevState.useCaseLevel,
288
283
  };
@@ -318,13 +313,13 @@ class UseCasesMapViewer extends React.Component {
318
313
  x: e.x,
319
314
  y: e.y,
320
315
  };
321
-
322
316
  if (this.state.useCaseLevel === 1) {
323
317
  view.hitTest(screenPoint).then((response) => {
324
318
  if (response.results.length > 1) {
325
319
  if (
326
320
  response.results[0].graphic.geometry !== null &&
327
- this.popupOnce
321
+ this.popupOnce &&
322
+ this.popupRegion === response.results[0].graphic.attributes.Region
328
323
  ) {
329
324
  this.popupOnce = false;
330
325
  document.querySelector('.map').style.cursor = 'pointer';
@@ -369,37 +364,23 @@ class UseCasesMapViewer extends React.Component {
369
364
  content: string,
370
365
  });
371
366
  });
367
+ } else {
368
+ this.popupRegion = response.results[0].graphic.attributes.Region;
369
+ this.popupOnce = true;
370
+ if (response.results[0].graphic.attributes.Region === undefined) {
371
+ view.popup.close();
372
+ document.querySelector('.map').style.cursor = '';
373
+ }
372
374
  }
373
375
  } else {
374
- view.popup.close();
375
376
  this.popupOnce = true;
376
377
  document.querySelector('.map').style.cursor = '';
378
+ view.popup.close();
377
379
  }
378
380
  });
379
381
  } else if (this.state.useCaseLevel === 2) {
380
382
  view.hitTest(screenPoint).then((response) => {
381
- if (response.results.length > 1) {
382
- if (
383
- response.results[0].graphic.geometry !== null &&
384
- this.popupOnce
385
- ) {
386
- this.popupOnce = false;
387
- document.querySelector('.map').style.cursor = 'pointer';
388
- document
389
- .querySelector(
390
- '#use_case_' +
391
- response.results[0].graphic.attributes.OBJECTID,
392
- )
393
- .classList.add('selected');
394
- }
395
- } else {
396
- this.popupOnce = true;
397
- document.querySelector('.map').style.cursor = '';
398
- if (document.querySelector('.use-case-element.selected'))
399
- document
400
- .querySelector('.use-case-element.selected')
401
- .classList.remove('selected');
402
- }
383
+ layerControl.highlightInfo(response);
403
384
  });
404
385
  }
405
386
  });
@@ -17,6 +17,19 @@ const config = {
17
17
  div: 'mapDiv',
18
18
  center: [10.78, 30],
19
19
  zoom: 0,
20
+ maxZoom: 5,
21
+ worldDimensions: { height: 256, width: 256 },
22
+ prohibitedKeys: [
23
+ '+',
24
+ '-',
25
+ 'Shift',
26
+ '_',
27
+ '=',
28
+ 'ArrowUp',
29
+ 'ArrowDown',
30
+ 'ArrowLeft',
31
+ 'ArrowRight',
32
+ ],
20
33
  },
21
34
  Services: {
22
35
  RegionLayer: