<commit_before>/**
 * @class 
 * @description The superclass for all maps 
 * @param frameworkMap The frameworkspecific layer
 * Map object interface class
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 **/
Ext.define("viewer.viewercontroller.controller.Map",{
    extend: "Ext.util.Observable",
    events: [],
    layers: new Array(),
  //  
    config :{
        id: "id" ,
        mapComponent: new Object()
        //maxExtent : new Object()
    },
    /**
     * @constructor
     */
    constructor: function(config){
        this.initConfig(config);
        this.frameworkMap = this.mapComponent.viewerObject;
        
        this.addEvents(
            viewer.viewercontroller.controller.Event.ON_ALL_LAYERS_LOADING_COMPLETE,
            viewer.viewercontroller.controller.Event.ON_CHANGE_EXTENT,
            viewer.viewercontroller.controller.Event.ON_GET_FEATURE_INFO,
            viewer.viewercontroller.controller.Event.ON_GET_FEATURE_INFO_DATA,
            viewer.viewercontroller.controller.Event.ON_FINISHED_CHANGE_EXTENT,
            viewer.viewercontroller.controller.Event.ON_LAYER_VISIBILITY_CHANGED);
            
        return this;
    },
    
    registerEvent : function (event,handler,scope){
        this.addListener(event,handler,scope);
    },

    fire : function (event,options){
        this.fireEvent (event,this,options);
    },

    /**
     * @returns the framework map object.
     */
    getFrameworkMap: function(){
        return this.frameworkMap;
    },
    
    /**
     *Add a Array of layers(services) to the map
     *@param layers a array of layers
     **/    
    addLayers : function(layers){
        for (var i=0; i < layers.length; i++){
            this.addLayer(layers[i]);
        }
    },
    /**
     *Returns all the layers added to this maps.
     */
    getLayers : function(){
        if (this.layers==undefined){
            this.layers=new Array();
        }
        return this.layers;
    },

    /**
     *Get the layer by id
     *@param id the id of the layer you want.
     *@return the layer with the given id or null if the layer does not exists.
     */
    getLayer : function (id){
        for (var i=0; i < this.layers.length; i++){
            if (id==this.layers[i].getId()){
                return this.layers[i];
            }
        }
        return null;
    },

    /**
     *Removes a layer by the given id. Throws a exception when layer with id doesn't exists
     *@param layerId the id of the layer that needs to be removed.
     *Must be implemented by subclass
     */
    removeLayerById : function (layerId){
        this.removeLayer(this.getLayer(layerId));
    },
    /**
     *Remove all the layers
     */
    removeAllLayers:function(){
        for (var i=0; i < this.layers().length; i++){
            removeLayer(this.layers[i]);
        }
    },
    /**
     * Returns the index of the layer.
     * @param layer a Layer
     * @return the index of the layer or -1 if the layer is not found.
     */
    getLayerIndex : function(layer){
        for (var i=0; i < this.getLayers().length; i++){
            if (this.getLayers()[i]==layer){
                return i;
            }
        }<commit_msg>fix for updating array while looping over it in removeAllLayers()<commit_after>/**
 * @class 
 * @description The superclass for all maps 
 * @param frameworkMap The frameworkspecific layer
 * Map object interface class
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 **/
Ext.define("viewer.viewercontroller.controller.Map",{
    extend: "Ext.util.Observable",
    events: [],
    layers: new Array(),
  //  
    config :{
        id: "id" ,
        mapComponent: new Object()
        //maxExtent : new Object()
    },
    /**
     * @constructor
     */
    constructor: function(config){
        this.initConfig(config);
        this.frameworkMap = this.mapComponent.viewerObject;
        
        this.addEvents(
            viewer.viewercontroller.controller.Event.ON_ALL_LAYERS_LOADING_COMPLETE,
            viewer.viewercontroller.controller.Event.ON_CHANGE_EXTENT,
            viewer.viewercontroller.controller.Event.ON_GET_FEATURE_INFO,
            viewer.viewercontroller.controller.Event.ON_GET_FEATURE_INFO_DATA,
            viewer.viewercontroller.controller.Event.ON_FINISHED_CHANGE_EXTENT,
            viewer.viewercontroller.controller.Event.ON_LAYER_VISIBILITY_CHANGED);
            
        return this;
    },
    
    registerEvent : function (event,handler,scope){
        this.addListener(event,handler,scope);
    },

    fire : function (event,options){
        this.fireEvent (event,this,options);
    },

    /**
     * @returns the framework map object.
     */
    getFrameworkMap: function(){
        return this.frameworkMap;
    },
    
    /**
     *Add a Array of layers(services) to the map
     *@param layers a array of layers
     **/    
    addLayers : function(layers){
        for (var i=0; i < layers.length; i++){
            this.addLayer(layers[i]);
        }
    },
    /**
     *Returns all the layers added to this maps.
     */
    getLayers : function(){
        if (this.layers==undefined){
            this.layers=new Array();
        }
        return this.layers;
    },

    /**
     *Get the layer by id
     *@param id the id of the layer you want.
     *@return the layer with the given id or null if the layer does not exists.
     */
    getLayer : function (id){
        for (var i=0; i < this.layers.length; i++){
            if (id==this.layers[i].getId()){
                return this.layers[i];
            }
        }
        return null;
    },

    /**
     *Removes a layer by the given id. Throws a exception when layer with id doesn't exists
     *@param layerId the id of the layer that needs to be removed.
     *Must be implemented by subclass
     */
    removeLayerById : function (layerId){
        this.removeLayer(this.getLayer(layerId));
    },
    /**
     *Remove all the layers
     */
    removeAllLayers:function(){
        // loop backwards because this.layers is updated in loop
        for (var i=this.layers.length-1; i > 0; i--){
            console.log("remove layer " + this.layers[i].id, this.layers[i]);
            this.removeLayer(this.layers[i]);
        }
    },
    /**
     * Returns the index of the layer.
     * @param layer a Layer
     * @return the index of the layer or -1 if the layer is not found.
     */
    getLayerIndex : function(layer){
        for (var i=0; i < this.getLayers().length; i++){
            if (this.getLayers()[i]==layer){
                return i;
            }
        }
{'fraction_non_alphanumeric': 0.12063302478351746, 'fraction_numerical': 0.0016422812779934308, 'mean_word_length': 2.084254143646409, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1998781', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1961, 'n_words': 501}