Select to view content in your preferred language

Show/hide a custom view on Map Javascript

240
0
03-14-2024 10:47 PM
DivyaArora
New Contributor III

I am trying to add a custom view on the map in react application which will handle the visibility of some of the layers. This view needs to be removed or hide at some condition and then needs to be  added again.

I have used the code like below :

// code to add the custom view 
displayLayerTypeSwitcher() {
        const checkBoxElement = document.getElementById('FieldCheckboxDetails');
        if (checkBoxElement) {
            if (this.mapView?.ui.find('FieldCheckboxDetails')) {
                this.mapView?.ui.remove('FieldCheckboxDetails');
            }
            this.mapView?.ui.add(checkBoxElement, "top-right");
        }
    }
 
// code to remove the custom view 
    removeLayerTypeSwitcherView() {
        const checkBoxElement = document.getElementById('FieldCheckboxDetails');
        if (checkBoxElement) {
            if (this.mapView?.ui.find('FieldCheckboxDetails')) {
                this.mapView?.ui.remove(checkBoxElement);
            }
        }
    }
 
but once i invoke the "removeLayerTypeSwitcherView" method, the custom view is not avaialble anymore to be readded . It seems like it is removed from the DOM permanently.
Could anybody suggest how can i acheieve  the functionality to show/hide a custom view on a map.
0 Replies