@eeacms/volto-arcgis-block 0.1.352 → 0.1.353

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,6 +4,12 @@ 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.353](https://github.com/eea/volto-arcgis-block/compare/0.1.352...0.1.353) - 15 April 2025
8
+
9
+ #### :hammer_and_wrench: Others
10
+
11
+ - CLMS-286928 (bug): linter error fixed. [Unai Bolivar - [`d7afc23`](https://github.com/eea/volto-arcgis-block/commit/d7afc238ad25575b7e4857bb8ef6f693b3f1f736)]
12
+ - CLMS-286928 (bug): Fixed issues pertaining user upload wms services for logged in users [Unai Bolivar - [`49eaf4c`](https://github.com/eea/volto-arcgis-block/commit/49eaf4cfa94fdd406709cd50b50aafd18a13f25e)]
7
13
  ### [0.1.352](https://github.com/eea/volto-arcgis-block/compare/0.1.351...0.1.352) - 11 April 2025
8
14
 
9
15
  #### :hammer_and_wrench: Others
@@ -187,7 +193,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
187
193
 
188
194
  #### :house: Internal changes
189
195
 
190
- - chore: [JENKINSFILE] remove unused code [valentinab25 - [`c62af37`](https://github.com/eea/volto-arcgis-block/commit/c62af37e5c81f7b6b1d204de8a724499d00420d9)]
191
196
 
192
197
  #### :house: Documentation changes
193
198
 
@@ -506,13 +511,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
506
511
  #### :hammer_and_wrench: Others
507
512
 
508
513
  - CLMS-2916 (bug): Map Viewer / Products and Datasets tab / Layer - The information icon links to localhost in demo environment [Unai Bolivar - [`eda000a`](https://github.com/eea/volto-arcgis-block/commit/eda000a72278ab073033e520b868ded75dcc2904)]
509
- - test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`8a0855d`](https://github.com/eea/volto-arcgis-block/commit/8a0855dfe47ec58a596ae0ec360ba8f8d075e991)]
510
- - test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`3cfe9be`](https://github.com/eea/volto-arcgis-block/commit/3cfe9be4c6d4ace0ef83b452ebdd5b06025123aa)]
511
514
  ### [0.1.245](https://github.com/eea/volto-arcgis-block/compare/0.1.244...0.1.245) - 4 January 2024
512
515
 
513
516
  #### :hammer_and_wrench: Others
514
517
 
515
- - test: [JENKINS] fix jest config, fail with logs on coverage [valentinab25 - [`a93b081`](https://github.com/eea/volto-arcgis-block/commit/a93b0819eaa765c92bc25cf195f7a43fcd1dddbd)]
516
518
  ### [0.1.244](https://github.com/eea/volto-arcgis-block/compare/0.1.243...0.1.244) - 19 December 2023
517
519
 
518
520
  ### [0.1.243](https://github.com/eea/volto-arcgis-block/compare/0.1.242...0.1.243) - 15 December 2023
@@ -552,7 +554,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
552
554
 
553
555
  #### :hammer_and_wrench: Others
554
556
 
555
- - test: [JENKINS] Use java17 for sonarqube scanner [valentinab25 - [`f45d4bf`](https://github.com/eea/volto-arcgis-block/commit/f45d4bf42061d13d9c18554bef692cb40b3a6fb7)]
556
557
  ### [0.1.235](https://github.com/eea/volto-arcgis-block/compare/0.1.234...0.1.235) - 16 November 2023
557
558
 
558
559
  ### [0.1.234](https://github.com/eea/volto-arcgis-block/compare/0.1.233...0.1.234) - 15 November 2023
@@ -1626,13 +1627,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1626
1627
  #### :hammer_and_wrench: Others
1627
1628
 
1628
1629
  - Merge pull request #148 from eea/develop [KCarpinteroBM - [`24266fb`](https://github.com/eea/volto-arcgis-block/commit/24266fb3a0c1662d22ae0529dc1d5a25c711cf97)]
1629
- - Revert "[JENKINS] Use eeacms/plone-backend and Volto alpha version- Refs #151967" [Mikel Larreategi - [`f751f69`](https://github.com/eea/volto-arcgis-block/commit/f751f69f652f0340ae55af6a4dab89d6bdc80906)]
1630
1630
  - Revert "Revert "Mapviewer menu and map viewer options persistence"" [Mikel Larreategi - [`ad6e440`](https://github.com/eea/volto-arcgis-block/commit/ad6e440cdc160cffb1e86e1b26e501dbe648476c)]
1631
1631
  - Revert "code coverage removal" [Mikel Larreategi - [`376f2d1`](https://github.com/eea/volto-arcgis-block/commit/376f2d1cd6e4e5110b3b63d5114af1bcfebe094b)]
1632
1632
  - Revert "Update cypress.json" [Mikel Larreategi - [`43d01a0`](https://github.com/eea/volto-arcgis-block/commit/43d01a0a95a58ef5215c6cbf18223ca30a11b9cc)]
1633
1633
  - Revert "Update cypress.json" [Mikel Larreategi - [`054c4ae`](https://github.com/eea/volto-arcgis-block/commit/054c4ae1767e1f26e6ec7e96a0e26a9711f29f04)]
1634
- - Revert "revert [JENKINS] Use eeacms/plone-backend and Volto alpha version- Refs #151967" [Mikel Larreategi - [`64ab56e`](https://github.com/eea/volto-arcgis-block/commit/64ab56e0f1f8dddc26f26039509a028e34653e64)]
1635
- - revert [JENKINS] Use eeacms/plone-backend and Volto alpha version- Refs #151967 [Mikel Larreategi - [`85ee194`](https://github.com/eea/volto-arcgis-block/commit/85ee1941e029df2b7dc910bf75231c75ffeca8c2)]
1636
1634
  - Update cypress.json [KCarpinteroBM - [`be285ff`](https://github.com/eea/volto-arcgis-block/commit/be285fff0c53e06a0180d5318cce81195eabcf80)]
1637
1635
  - Update cypress.json [KCarpinteroBM - [`a7f2118`](https://github.com/eea/volto-arcgis-block/commit/a7f2118acb7b048b4cef85aa9663c2244a1c9ca0)]
1638
1636
  - linting fix [KCarpinteroBM - [`27e969a`](https://github.com/eea/volto-arcgis-block/commit/27e969a7a411fd4646e0e742ce846efc0d79703e)]
@@ -1692,7 +1690,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1692
1690
  - UX improvements [rodriama - [`151dc4b`](https://github.com/eea/volto-arcgis-block/commit/151dc4b02d0a73fdd66de9d594620ac0fa5f1dbf)]
1693
1691
  - deleted failing tests [KCarpinteroBM - [`ddaa9e6`](https://github.com/eea/volto-arcgis-block/commit/ddaa9e6f06db6960a4c214d3be2420c48b26715d)]
1694
1692
  - cleaning unnecessary files [KCarpinteroBM - [`2c02199`](https://github.com/eea/volto-arcgis-block/commit/2c021990912beb02b603a1de89aecd62e0063769)]
1695
- - Reverting to Automated release 0.1.39 [KCarpinteroBM - [`fb9f317`](https://github.com/eea/volto-arcgis-block/commit/fb9f3176ccdea18fceb329eaac13ced0566ee648)]
1696
1693
  - commands added [KCarpinteroBM - [`049e60b`](https://github.com/eea/volto-arcgis-block/commit/049e60b7d124d1c05abd0b2775b510795f4ed59f)]
1697
1694
  - Mapviewer testing implementation [KCarpinteroBM - [`0103002`](https://github.com/eea/volto-arcgis-block/commit/0103002869eea108e16e3b5ff2e77a725dcc7c4b)]
1698
1695
  ### [0.1.39](https://github.com/eea/volto-arcgis-block/compare/0.1.38...0.1.39) - 24 March 2022
@@ -1712,7 +1709,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1712
1709
  - ESLint fix [rodriama - [`75dae9b`](https://github.com/eea/volto-arcgis-block/commit/75dae9b5bba18ab6d9624f6c99714b4bd2179003)]
1713
1710
  - Remove section title [rodriama - [`ece860e`](https://github.com/eea/volto-arcgis-block/commit/ece860eae3519c7e611abac16e8d53c9a9408b34)]
1714
1711
  - Es-Lint [manuelmartinezbilbomatica - [`39d8d11`](https://github.com/eea/volto-arcgis-block/commit/39d8d11b9096fd603df8510c119d2e12817415d6)]
1715
- - Add Sonarqube tag using clms-frontend addons list [EEA Jenkins - [`bf9f683`](https://github.com/eea/volto-arcgis-block/commit/bf9f683dd35a9edb4cfd9111affcb8f8edbeae89)]
1716
1712
  - FEAT: Parser Time implemented [manuelmartinezbilbomatica - [`689c99e`](https://github.com/eea/volto-arcgis-block/commit/689c99e55221fee6c7c7fafc4ab95ae7a646d3dd)]
1717
1713
  ### [0.1.38](https://github.com/eea/volto-arcgis-block/compare/0.1.37...0.1.38) - 18 March 2022
1718
1714
 
@@ -1807,7 +1803,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
1807
1803
  - ESLint fix [rodriama - [`5fd3772`](https://github.com/eea/volto-arcgis-block/commit/5fd3772f197a3a380067962a5638dbf901a4624e)]
1808
1804
  - Pixel info [rodriama - [`1ccef39`](https://github.com/eea/volto-arcgis-block/commit/1ccef39a9adcc3ee94655c77a5a166b613600a08)]
1809
1805
  - NUTS bug fix [rodriama - [`37fe7f3`](https://github.com/eea/volto-arcgis-block/commit/37fe7f3fad2c005e3b7c234b3b0564d5df92fa8c)]
1810
- - Add Sonarqube tag using freshwater-frontend addons list [EEA Jenkins - [`ea5af8b`](https://github.com/eea/volto-arcgis-block/commit/ea5af8b02a5f2ee25b9b0be67cf3792bbbe84ed7)]
1811
1806
  ### [0.1.23](https://github.com/eea/volto-arcgis-block/compare/0.1.22...0.1.23) - 17 December 2021
1812
1807
 
1813
1808
  #### :hammer_and_wrench: Others
@@ -2052,7 +2047,6 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
2052
2047
  - Trying to delay ArcGIS modules load [gonzalezsd - [`ff16985`](https://github.com/eea/volto-arcgis-block/commit/ff169858e42d30bfcacc423ffc27762bb9ef05a4)]
2053
2048
  - Run bootstrap to fix files [valentinab25 - [`236893f`](https://github.com/eea/volto-arcgis-block/commit/236893f03314eb638b7667f81b1f91491a98ee17)]
2054
2049
  - fix git_name [valentinab25 - [`c7806c3`](https://github.com/eea/volto-arcgis-block/commit/c7806c312964425dc23e5d4c6973de8b81ddaeac)]
2055
- - Add Sonarqube tag using frontend addons list [EEA Jenkins - [`e3afb51`](https://github.com/eea/volto-arcgis-block/commit/e3afb515dda459ee03e2b5d4b56465d2d4ad1503)]
2056
2050
  - Trying to change imports [gonzalezsd - [`d83d7e2`](https://github.com/eea/volto-arcgis-block/commit/d83d7e2f68da4b2a284735847f93c0763a7e13b6)]
2057
2051
  - default design [bipoza - [`88fbe0b`](https://github.com/eea/volto-arcgis-block/commit/88fbe0b2bc73e732e2993324a567f53902e85506)]
2058
2052
  - cleanup of unused code [bipoza - [`b167677`](https://github.com/eea/volto-arcgis-block/commit/b1676771f637f056cad50cb0bc186f2ea79e8517)]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-arcgis-block",
3
- "version": "0.1.352",
3
+ "version": "0.1.353",
4
4
  "description": "volto-arcgis-block: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: CodeSyntax",
@@ -2035,15 +2035,25 @@ class MenuWidget extends React.Component {
2035
2035
  layerId = title.toUpperCase().replace(/ /g, '_');
2036
2036
  const constructedSublayers = resourceLayer.sublayers?.items?.map(
2037
2037
  (sublayer) => {
2038
- const { index, name, title, legendUrl, featureInfoUrl } = sublayer;
2038
+ const {
2039
+ index,
2040
+ name,
2041
+ title,
2042
+ legendUrl,
2043
+ featureInfoUrl,
2044
+ queryable,
2045
+ popupEnabled,
2046
+ visible,
2047
+ legendEnabled,
2048
+ } = sublayer;
2039
2049
  return {
2040
2050
  index,
2041
2051
  name,
2042
2052
  title,
2043
- popupEnabled: true,
2044
- queryable: true,
2045
- visible: true,
2046
- legendEnabled: true,
2053
+ popupEnabled,
2054
+ queryable,
2055
+ visible,
2056
+ legendEnabled,
2047
2057
  legendUrl: legendUrl
2048
2058
  ? legendUrl
2049
2059
  : viewService + legendRequest + name,
@@ -2202,7 +2212,9 @@ class MenuWidget extends React.Component {
2202
2212
  const newWmsUserServiceLayers = prevState.wmsUserServiceLayers.filter(
2203
2213
  (layer) => layer.LayerId !== elemId,
2204
2214
  );
2205
- this.saveUserServicesToStorage(newWmsUserServiceLayers);
2215
+ if (this.userID && this.userID !== null) {
2216
+ this.saveUserServicesToStorage(newWmsUserServiceLayers);
2217
+ }
2206
2218
  return { wmsUserServiceLayers: newWmsUserServiceLayers };
2207
2219
  }
2208
2220
  return null;
@@ -2214,6 +2226,11 @@ class MenuWidget extends React.Component {
2214
2226
 
2215
2227
  try {
2216
2228
  const layersToSave = layers.map((layer) => {
2229
+ // First, see if this layer exists in previous saved services to retain checked state
2230
+ const checkedLayers =
2231
+ JSON.parse(sessionStorage.getItem('checkedLayers')) || [];
2232
+ const isChecked = checkedLayers.includes(layer.LayerId);
2233
+
2217
2234
  // Create a simplified object for storage
2218
2235
  return {
2219
2236
  url: layer.url,
@@ -2234,6 +2251,9 @@ class MenuWidget extends React.Component {
2234
2251
  })),
2235
2252
  ViewService: layer.ViewService,
2236
2253
  LayerId: layer.LayerId,
2254
+ visibility: layer.visible !== false,
2255
+ opacity: layer.opacity || 1,
2256
+ checked: isChecked || layer.checked || false,
2237
2257
  };
2238
2258
  });
2239
2259
 
@@ -2246,6 +2266,7 @@ class MenuWidget extends React.Component {
2246
2266
 
2247
2267
  async loadUserServicesFromStorage() {
2248
2268
  if (this.userID != null) {
2269
+ sessionStorage.clear();
2249
2270
  try {
2250
2271
  const savedServices = JSON.parse(
2251
2272
  localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
@@ -2258,6 +2279,20 @@ class MenuWidget extends React.Component {
2258
2279
  try {
2259
2280
  // Create a new WMSLayer with the saved properties
2260
2281
  const newLayer = new WMSLayer(serviceData);
2282
+
2283
+ // Set visibility property based on saved value
2284
+ newLayer.visible = serviceData.visibility !== false;
2285
+
2286
+ // Remember the original checked state and visibility
2287
+ newLayer.checked = serviceData.checked;
2288
+
2289
+ // Initialize visibleLayers for this layer
2290
+ if (!this.visibleLayers) this.visibleLayers = {};
2291
+ this.visibleLayers[serviceData.LayerId] =
2292
+ serviceData.visibility !== false
2293
+ ? ['fas', 'eye']
2294
+ : ['fas', 'eye-slash'];
2295
+
2261
2296
  // Add to this.layers
2262
2297
  this.layers[serviceData.LayerId] = newLayer;
2263
2298
  return newLayer;
@@ -2271,27 +2306,87 @@ class MenuWidget extends React.Component {
2271
2306
  const validLayers = recreatedLayers.filter((layer) => layer !== null);
2272
2307
 
2273
2308
  // Update state with recreated layers
2274
- this.setState({ wmsUserServiceLayers: validLayers });
2275
- // Get checked layers from session storage
2276
- // const checkedLayers =
2277
- // JSON.parse(sessionStorage.getItem('checkedLayers')) || [];
2278
-
2279
- // For each valid layer that was previously checked, make it visible
2280
- validLayers.forEach((layer) => {
2281
- // if (checkedLayers.includes(layer.LayerId)) {
2282
- const node = document.getElementById(layer.LayerId);
2283
- if (node) {
2284
- layer.visible === true
2285
- ? (node.checked = true)
2286
- : (node.checked = false);
2287
- this.toggleLayer(node);
2288
- }
2309
+ this.setState({ wmsUserServiceLayers: validLayers }, () => {
2310
+ // For each layer, update the checkbox state based on localStorage
2311
+ setTimeout(() => {
2312
+ validLayers.forEach((layer) => {
2313
+ const node = document.getElementById(layer.LayerId);
2314
+ if (node) {
2315
+ // Check the checkbox if it was saved as checked
2316
+ if (layer.checked === true) {
2317
+ // First add to checkedLayers in sessionStorage if not already there
2318
+ const checkedLayers =
2319
+ JSON.parse(sessionStorage.getItem('checkedLayers')) || [];
2320
+
2321
+ if (!checkedLayers.includes(layer.LayerId)) {
2322
+ checkedLayers.unshift(layer.LayerId);
2323
+ sessionStorage.setItem(
2324
+ 'checkedLayers',
2325
+ JSON.stringify(checkedLayers),
2326
+ );
2327
+ window.dispatchEvent(new Event('storage'));
2328
+ }
2329
+
2330
+ // Then check the checkbox and call toggleLayer with a flag to preserve visibility
2331
+ node.checked = true;
2332
+
2333
+ // Custom addition to toggleLayer to bypass visibility override
2334
+ this.toggleLayerWithoutVisibilityReset(node);
2335
+ }
2336
+ }
2337
+ });
2338
+ }, 100);
2289
2339
  });
2290
2340
  }
2291
2341
  } catch (error) {}
2292
2342
  }
2293
2343
  }
2294
2344
 
2345
+ toggleLayerWithoutVisibilityReset(elem) {
2346
+ // Copy most of toggleLayer behavior but don't set this.visibleLayers[elem.id]
2347
+ if (this.layers[elem.id] === undefined) return;
2348
+ if (!this.visibleLayers) this.visibleLayers = {};
2349
+ if (!this.timeLayers) this.timeLayers = {};
2350
+
2351
+ // Add the layer to the map
2352
+ this.layers[elem.id].visible = this.visibleLayers[elem.id][1] === 'eye';
2353
+ this.map.add(this.layers[elem.id]);
2354
+
2355
+ // Continue with other toggleLayer operations
2356
+ this.timeLayers[elem.id] = ['far', 'clock'];
2357
+
2358
+ // Add to active layers
2359
+ this.activeLayersJSON[elem.id] = this.addActiveLayer(
2360
+ elem,
2361
+ Object.keys(this.activeLayersJSON).length,
2362
+ );
2363
+
2364
+ this.saveCheckedLayer(elem.id);
2365
+
2366
+ // Reorder layers
2367
+ let nuts = this.map.layers.items.find((layer) => layer.title === 'nuts');
2368
+ if (nuts) {
2369
+ this.map.reorder(nuts, this.map.layers.items.length + 1);
2370
+ }
2371
+
2372
+ this.layersReorder();
2373
+ this.checkInfoWidget();
2374
+
2375
+ // Toggle custom legend
2376
+ if (
2377
+ this.layers[elem.id].ViewService?.toLowerCase().includes('wmts') ||
2378
+ this.layers[elem.id].ViewService?.toLowerCase().endsWith('file')
2379
+ ) {
2380
+ this.toggleCustomLegendItem(this.layers[elem.id]);
2381
+ }
2382
+
2383
+ if (!this.props.download && this.props.hotspotData) {
2384
+ this.activeLayersToHotspotData(elem.id);
2385
+ }
2386
+
2387
+ this.renderHotspot();
2388
+ }
2389
+
2295
2390
  /**
2296
2391
  * Method to show/hide a layer. Update checkboxes from dataset and products
2297
2392
  * @param {*} elem Is the checkbox
@@ -4033,22 +4128,28 @@ class MenuWidget extends React.Component {
4033
4128
  let layerOpacities = JSON.parse(sessionStorage.getItem('layerOpacities'));
4034
4129
  if (layerOpacities === null) {
4035
4130
  layerOpacities = {};
4036
- layerOpacities[layer] = value;
4037
- sessionStorage.setItem('layerOpacities', JSON.stringify(layerOpacities));
4038
- } else {
4039
- layerOpacities[layer] = value;
4040
- sessionStorage.setItem('layerOpacities', JSON.stringify(layerOpacities));
4041
4131
  }
4042
- let savedServices = JSON.parse(
4132
+ layerOpacities[layer] = value;
4133
+ sessionStorage.setItem('layerOpacities', JSON.stringify(layerOpacities));
4134
+
4135
+ // Save to localStorage for user service layers
4136
+ const savedServices = JSON.parse(
4043
4137
  localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4044
4138
  );
4045
- if (savedServices === null) {
4046
- return;
4047
- } else {
4048
- for (const service of Object.values(savedServices)) {
4139
+
4140
+ if (savedServices && Array.isArray(savedServices)) {
4141
+ let servicesUpdated = false;
4142
+
4143
+ // Update opacity for matching layer in user services
4144
+ savedServices.forEach((service) => {
4049
4145
  if (service.LayerId === layer) {
4050
4146
  service.opacity = value;
4147
+ servicesUpdated = true;
4051
4148
  }
4149
+ });
4150
+
4151
+ // Only save if we made changes
4152
+ if (servicesUpdated) {
4052
4153
  localStorage.setItem(
4053
4154
  USER_SERVICES_KEY + '_' + this.userID,
4054
4155
  JSON.stringify(savedServices),
@@ -4065,43 +4166,44 @@ class MenuWidget extends React.Component {
4065
4166
  loadOpacity() {
4066
4167
  let layerOpacities =
4067
4168
  JSON.parse(sessionStorage.getItem('layerOpacities')) || {};
4169
+
4170
+ // Load from localStorage for user service layers
4068
4171
  const savedUserServices = JSON.parse(
4069
4172
  localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4070
4173
  );
4071
- if (savedUserServices) {
4072
- Object.values(savedUserServices).forEach((service) => {
4073
- let layer = service.LayerId;
4074
- let value = service.opacity;
4075
- // Check if the layer is already in layerOpacities
4076
- if (layerOpacities[layer] === undefined) {
4077
- //add to layerOpacties
4078
- layerOpacities[layer] = value;
4079
- // if (this.layers[service]) {
4080
- // // set map
4081
- // this.layers[service].opacity = value;
4082
- // // set slider
4083
- // let nodeValue = `.active-layer[layer-id="${layer}"] .active-layer-opacity`;
4084
- // let node = document.querySelector(nodeValue);
4085
- // if (node) {
4086
- // node.dataset.opacity = value * 100;
4087
- // }
4088
- // }
4174
+
4175
+ // Import opacity values from user services if not already in session storage
4176
+ if (savedUserServices && Array.isArray(savedUserServices)) {
4177
+ savedUserServices.forEach((service) => {
4178
+ const layerId = service.LayerId;
4179
+ const opacity = service.opacity;
4180
+
4181
+ // If this layer's opacity isn't in session storage yet, add it
4182
+ if (
4183
+ layerId &&
4184
+ opacity !== undefined &&
4185
+ layerOpacities[layerId] === undefined
4186
+ ) {
4187
+ layerOpacities[layerId] = opacity;
4089
4188
  }
4090
4189
  });
4091
4190
  }
4092
- if (layerOpacities) {
4093
- for (const layer in layerOpacities) {
4094
- if (this.layers[layer]) {
4095
- let value = layerOpacities[layer];
4096
- // set map
4097
- this.layers[layer].opacity = value;
4098
- // set slider
4099
- let node = document.querySelector(
4100
- '.active-layer[layer-id="' + layer + '"] .active-layer-opacity',
4101
- );
4102
- if (node) {
4103
- node.dataset.opacity = value * 100;
4104
- }
4191
+ //save layerOpacities to sessionStorage
4192
+ sessionStorage.setItem('layerOpacities', JSON.stringify(layerOpacities));
4193
+ // Apply opacity values to layers and UI
4194
+ for (const layerId in layerOpacities) {
4195
+ if (this.layers[layerId]) {
4196
+ const value = layerOpacities[layerId];
4197
+
4198
+ // Set opacity on the map layer
4199
+ this.layers[layerId].opacity = value;
4200
+
4201
+ // Update UI opacity slider
4202
+ const node = document.querySelector(
4203
+ `.active-layer[layer-id="${layerId}"] .active-layer-opacity`,
4204
+ );
4205
+ if (node) {
4206
+ node.dataset.opacity = value * 100;
4105
4207
  }
4106
4208
  }
4107
4209
  }
@@ -4287,7 +4389,13 @@ class MenuWidget extends React.Component {
4287
4389
  }
4288
4390
  this.setLegendOpacity();
4289
4391
  this.loadOpacity();
4290
- this.loadVisibility();
4392
+ if (
4393
+ prevProps.hotspotData !== this.props.hotspotData ||
4394
+ !this._visibilityInitialized
4395
+ ) {
4396
+ this.loadVisibility();
4397
+ this._visibilityInitialized = true;
4398
+ }
4291
4399
  }
4292
4400
 
4293
4401
  /**
@@ -4295,6 +4403,34 @@ class MenuWidget extends React.Component {
4295
4403
  */
4296
4404
  saveVisibility() {
4297
4405
  if (this.props.download) return;
4406
+
4407
+ // Get services from localStorage - it's an array of objects
4408
+ const savedServices = JSON.parse(
4409
+ localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4410
+ );
4411
+
4412
+ if (savedServices && Array.isArray(savedServices)) {
4413
+ let servicesUpdated = false;
4414
+
4415
+ // Update visibility state for each service in the array
4416
+ savedServices.forEach((service) => {
4417
+ const layerId = service.LayerId;
4418
+ if (layerId && this.visibleLayers[layerId]) {
4419
+ // Update visibility based on eye icon state
4420
+ service.visibility =
4421
+ this.visibleLayers[layerId][1] === 'eye' ? true : false;
4422
+ servicesUpdated = true;
4423
+ }
4424
+ });
4425
+
4426
+ // Only save if we made changes
4427
+ if (servicesUpdated) {
4428
+ localStorage.setItem(
4429
+ USER_SERVICES_KEY + '_' + this.userID,
4430
+ JSON.stringify(savedServices),
4431
+ );
4432
+ }
4433
+ }
4298
4434
  sessionStorage.setItem('visibleLayers', JSON.stringify(this.visibleLayers));
4299
4435
  }
4300
4436
 
@@ -4304,6 +4440,8 @@ class MenuWidget extends React.Component {
4304
4440
  loadVisibility() {
4305
4441
  if (this.props.download) return;
4306
4442
 
4443
+ let hasChanges = false;
4444
+
4307
4445
  // Load visibility settings from sessionStorage
4308
4446
  let vl = JSON.parse(sessionStorage.getItem('visibleLayers'));
4309
4447
  if (vl) {
@@ -4317,44 +4455,52 @@ class MenuWidget extends React.Component {
4317
4455
  localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4318
4456
  );
4319
4457
 
4320
- if (savedUserServices) {
4321
- Object.values(savedUserServices).forEach((service) => {
4322
- let layerId = service.LayerId;
4323
- let visibility = service.visibility;
4324
- // Only add visibility from localStorage if not already in sessionStorage
4325
- if (this.visibleLayers[layerId] === undefined) {
4326
- if (visibility) {
4327
- this.visibleLayers[layerId] = ['fas', 'eye'];
4328
- } else {
4329
- this.visibleLayers[layerId] = ['fas', 'eye-slash'];
4330
- }
4458
+ if (savedUserServices && Array.isArray(savedUserServices)) {
4459
+ savedUserServices.forEach((service) => {
4460
+ const layerId = service.LayerId;
4461
+ // Check if visibility is explicitly defined (could be true, false, or undefined)
4462
+ if (
4463
+ layerId &&
4464
+ this.visibleLayers[layerId] === undefined &&
4465
+ service.visibility !== undefined
4466
+ ) {
4467
+ // Set visible icon based on saved visibility boolean value
4468
+ this.visibleLayers[layerId] =
4469
+ service.visibility === true ? ['fas', 'eye'] : ['fas', 'eye-slash'];
4470
+ hasChanges = true;
4331
4471
  }
4332
4472
  });
4333
4473
  }
4334
-
4335
- // Apply visibility settings to layers
4474
+ //add this.visibleLayers to session storage
4475
+ sessionStorage.setItem('visibleLayers', JSON.stringify(this.visibleLayers));
4336
4476
  for (const key in this.visibleLayers) {
4337
4477
  if (this.layers[key]) {
4338
- if (this.visibleLayers[key][1] === 'eye') {
4339
- this.layers[key].visible = true;
4340
- } else {
4341
- this.layers[key].visible = false;
4342
- }
4478
+ // Set layer visibility based on eye/eye-slash
4479
+ const shouldBeVisible = this.visibleLayers[key][1] === 'eye';
4480
+ this.layers[key].visible = shouldBeVisible;
4343
4481
 
4482
+ // Update the active layer UI if it exists
4344
4483
  let elem = document.getElementById(key);
4345
4484
  if (elem && this.activeLayersJSON[key]) {
4485
+ // Get the current order of the active layer
4346
4486
  let order = this.activeLayersJSON[key].props['layer-order'];
4347
- // add active layer to DOM
4487
+
4488
+ // Force recreate the active layer component with the correct visibility state
4348
4489
  this.activeLayersJSON[key] = this.addActiveLayer(elem, order);
4349
- // reorder layers
4490
+
4491
+ // Update related UI
4350
4492
  this.layersReorder();
4351
- // show/hide info widget
4352
4493
  this.checkInfoWidget();
4353
- // update
4354
- this.setState({});
4494
+ this.toggleCustomLegendItem(this.layers[key]);
4495
+ hasChanges = true;
4355
4496
  }
4356
4497
  }
4357
4498
  }
4499
+
4500
+ // Only update state once if there were changes
4501
+ if (hasChanges) {
4502
+ this.setState({});
4503
+ }
4358
4504
  }
4359
4505
 
4360
4506
  /**
@@ -4393,6 +4539,8 @@ class MenuWidget extends React.Component {
4393
4539
  */
4394
4540
  saveCheckedLayer(layer) {
4395
4541
  if (this.props.download) return;
4542
+
4543
+ // Update sessionStorage as before
4396
4544
  let checkedLayers = JSON.parse(sessionStorage.getItem('checkedLayers'));
4397
4545
  if (checkedLayers === null) {
4398
4546
  checkedLayers = [layer];
@@ -4404,6 +4552,31 @@ class MenuWidget extends React.Component {
4404
4552
  sessionStorage.setItem('checkedLayers', JSON.stringify(checkedLayers));
4405
4553
  }
4406
4554
  window.dispatchEvent(new Event('storage'));
4555
+
4556
+ // Also update localStorage for user service layers
4557
+ const savedServices = JSON.parse(
4558
+ localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4559
+ );
4560
+
4561
+ if (savedServices && Array.isArray(savedServices)) {
4562
+ let servicesUpdated = false;
4563
+
4564
+ // Update checked state for matching layer in user services
4565
+ savedServices.forEach((service) => {
4566
+ if (service.LayerId === layer) {
4567
+ service.checked = true;
4568
+ servicesUpdated = true;
4569
+ }
4570
+ });
4571
+
4572
+ // Only save if we made changes
4573
+ if (servicesUpdated) {
4574
+ localStorage.setItem(
4575
+ USER_SERVICES_KEY + '_' + this.userID,
4576
+ JSON.stringify(savedServices),
4577
+ );
4578
+ }
4579
+ }
4407
4580
  }
4408
4581
 
4409
4582
  /**
@@ -4442,6 +4615,31 @@ class MenuWidget extends React.Component {
4442
4615
  sessionStorage.setItem('visibleLayers', JSON.stringify(visibleLayers));
4443
4616
  }
4444
4617
  }
4618
+
4619
+ // Also update localStorage for user service layers
4620
+ const savedServices = JSON.parse(
4621
+ localStorage.getItem(USER_SERVICES_KEY + '_' + this.userID),
4622
+ );
4623
+
4624
+ if (savedServices && Array.isArray(savedServices)) {
4625
+ let servicesUpdated = false;
4626
+
4627
+ // Update checked state for matching layer in user services
4628
+ savedServices.forEach((service) => {
4629
+ if (service.LayerId === layer) {
4630
+ service.checked = false;
4631
+ servicesUpdated = true;
4632
+ }
4633
+ });
4634
+
4635
+ // Only save if we made changes
4636
+ if (servicesUpdated) {
4637
+ localStorage.setItem(
4638
+ USER_SERVICES_KEY + '_' + this.userID,
4639
+ JSON.stringify(savedServices),
4640
+ );
4641
+ }
4642
+ }
4445
4643
  }
4446
4644
 
4447
4645
  deleteFilteredLayer(layer) {
@@ -128,20 +128,37 @@ class UploadWidget extends React.Component {
128
128
  this.setState({ wmsServiceUrl: event.target.value });
129
129
  };
130
130
 
131
- handleUploadService = () => {
131
+ handleUploadService = async () => {
132
132
  const { wmsServiceUrl } = this.state;
133
+ try {
134
+ // Use a CORS proxy or add mode: 'no-cors' if you just need to check if service exists
135
+ let urlResult = await fetch(wmsServiceUrl, {
136
+ method: 'GET',
137
+ mode: 'cors', // You might need to change this to 'no-cors' if proxy isn't available
138
+ });
133
139
 
140
+ // Check if service is valid and properly responds
141
+ if (!urlResult || !urlResult.ok) {
142
+ this.errorPopup();
143
+ this.setState({ wmsServiceUrl: '' });
144
+ return;
145
+ }
146
+ } catch (error) {
147
+ this.errorPopup();
148
+ this.setState({ wmsServiceUrl: '' });
149
+ return;
150
+ }
151
+ // If service is valid and is a WMS service
134
152
  if (
135
153
  wmsServiceUrl &&
136
154
  wmsServiceUrl.trim() !== '' &&
137
155
  wmsServiceUrl.toLowerCase().includes('wms')
138
156
  ) {
139
157
  this.uploadUrlServiceHandler(wmsServiceUrl);
140
- this.setState({
141
- wmsServiceUrl: '',
142
- });
158
+ this.setState({ wmsServiceUrl: '' });
143
159
  } else {
144
160
  this.errorPopup();
161
+ this.setState({ wmsServiceUrl: '' });
145
162
  }
146
163
  };
147
164