{"size": 1512, "ext": "js", "max_stars_repo_path": "src/map/LayerSwitcherBuilder.js", "max_stars_repo_name": "geowe/openCrogis", "max_stars_repo_stars_event_min_datetime": "2021-03-30T07:31:40.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-27T16:37:33.000Z", "max_issues_repo_path": "src/map/LayerSwitcherBuilder.js", "max_issues_repo_name": "geowe/openCrogis", "max_issues_repo_issues_event_min_datetime": "2021-03-30T07:55:43.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-21T08:38:28.000Z", "max_forks_repo_path": "src/map/LayerSwitcherBuilder.js", "max_forks_repo_name": "geowe/openCrogis", "max_forks_repo_forks_event_min_datetime": "2021-03-30T06:28:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-29T09:51:32.000Z"}
{"max_stars_count": 4, "max_issues_count": 1, "max_forks_count": 3, "avg_line_length": 34.3636363636, "max_line_length": 111, "alphanum_fraction": 0.6891534392}
import layerSwitcherTools from '../ui/html/layerSwitcherTools.html';
import LayerSwitcher from 'ol-ext/control/LayerSwitcher';
import configuration from '../Configuration';

const DEFAULT_ZOOM = 15;
/**
 * Constructor gestor de capas
 *
 * @export
 * @class export default class LayerSwitcherBuilder
 * @param mapContext
 */
export default class LayerSwitcherBuilder {
    constructor(mapContext) {
        this.mapContext = mapContext;
    }
   
    build(){
        let switcher = new LayerSwitcher();
        switcher.setHeader(layerSwitcherTools);
        this.mapContext.getMap().addControl(switcher);
        
        this.registerZoomToCroquisButtonListener();
        this.registerCleanCroquisButtonListener();

        return switcher;
    }

    registerZoomToCroquisButtonListener(){
        let elemento = document.getElementById('zoomToCroquisButton');
        elemento.onclick = ()=>{this.mapContext.zoomToCroquis(configuration.getDefaultZoom() || DEFAULT_ZOOM);}
    }

    registerCleanCroquisButtonListener(){
        let elemento = document.getElementById('CleanCroquisButton');
        elemento.onclick = ()=>{
            this.mapContext.getLayerBuilder().getAuxElementLayer().getSource().clear();
            this.mapContext.getLayerBuilder().getCroquisObjectLayer().getSource().clear();
            this.mapContext.getLayerBuilder().getReferencePointLayer().getSource().clear();
            this.mapContext.getLayerBuilder().getMeasureLayer().getSource().clear();        
        }
    }

}