wmbeers / cmv-app

CMV - The Configurable Map Viewer - A community supported open source mapping framework built with the Esri JavaScript API and the Dojo Toolkit
https://demo.cmv.io/
MIT License
1 stars 2 forks source link

Removing map services containing folders breaks layer control #82

Closed wmbeers closed 2 years ago

wmbeers commented 3 years ago

Originally reported during initial testing of #67.

Steps to reproduce:

  1. Add a map service to the map containing folders, e.g. a project map service (if on the #67 branch), or a resource service like Waste.
  2. Remove the map service by selecting Remove Layer from the hamburger menu.

Expected result: Map service is removed, controls for other map services in the map remain operational

Actual result: Map service is removed, controls for other map services stop working. The root-level checkbox is the only control that works, subfolders do not.

wmbeers commented 3 years ago

Traced it back to the scope of the "_handlers" arrays created in the declarations of _DynamicSublayer and _DynamicFolder. These are assigned in a way that makes them work like a static class-level array, and each creation of a new instance of a widget based on these is creating new handlers, but assigning them to this class-level array. If two handlers are created when the first folder or sublayer is created, _handlers.size is 2, but on the second creation of another folder or layer, two new handlers are created, and added to the same shared array. Both widgets will have the same array of four handlers.

https://github.com/wmbeers/cmv-app/blob/fd901cd555182ab26b13e164fcfe7353ab5d88aa/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js#L30-L37

Then when the destroy method is called, this array is iterated over, and all handlers removed, from all folders and dynamic sublayers: https://github.com/wmbeers/cmv-app/blob/fd901cd555182ab26b13e164fcfe7353ab5d88aa/viewer/js/gis/dijit/LayerControl/controls/_DynamicFolder.js#L277-L281

wmbeers commented 3 years ago

Reopening for merge to public site

wmbeers commented 3 years ago

Merged and deployed to public site. Closing issue.

wmbeers commented 2 years ago

This should not have been re-opened in October. It's been merged to public site.