<commit_before>dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("GeoMOOSE.Tab");
dojo.require("extensions.VisibleLayers.mapsource");
dojo.require("extensions.VisibleLayers.layer");

dojo.provide("extensions.VisibleLayers.tab");
dojo.declare('extensions.VisibleLayers.tab', [GeoMOOSE.Tab, dijit._Widget, dijit._Templated], {
	title: 'Active Layers', /* GeoMOOSE.Tab */

	templateString: dojo.cache("extensions.VisibleLayers", "templates/tab.html"),
	widgetsInTemplate: true,

	layers: null,

	startup: function() {
		this.inherited(arguments);
		this.layers = {};

		if(CONFIGURATION['extensions.VisibleLayers.tab_name'])
			this.set('title', CONFIGURATION['extensions.VisibleLayers.tab_name']);
		
		GeoMOOSE.register('onMapbookLoaded', this, this.setupEvents);
		dojo.connect(Application, 'configureMapSources', dojo.hitch(this, this.renderTab));
	},

	setupEvents: function() {
		dojo.connect(Application, 'onLayersChange', dojo.hitch(this, this.onLayerChange));
		dojo.connect(Application, 'configureMapSource', dojo.hitch(this, this.onLayerAdd));
		dojo.connect(Map, 'setLayerIndex', dojo.hitch(this, this._place_layers));
	},

	onLayerAdd: function(xml, options) {
		this.renderTab();
	},

	onLayerChange: function(layer_id, vis) {
		console.log("Layer " + layer_id + " changed.");
		if(this.layers[layer_id]) {
			this.layers[layer_id].onLayerChange(vis);
		}
		this.renderTab();
	},

	renderTab: function(evt) {
		var layerList = GeoMOOSE.getVisibleLayers();
		for(var i in layerList) {
			var path = layerList[i];
			if(this.layers[path]) {
				; // update status
			} else {
				if(path.indexOf("/") > -1) { /* This is a layer */
					var group = path.split("/")[0];
					if(GeoMOOSE.isDefined(this.layers[group])) {
						var l = new extensions.VisibleLayers.layer(
										{
											title: path,
											path: path,
											map_source: this.layers[group]
										});
						this.layers[path] = l;
						dojo.place(l.domNode, this.layers[group].layersNode, "last");
					}
				} else if(Application.getMapSource(path).displayInLayerSwitcher) {
					var g = new extensions.VisibleLayers.mapsource(
									{
										title: path,
										path: path,
										tab: this
									});
					this.layers[path] = g;
					//dojo.connect(g, 'upLayer', dojo.hitch(this, this._place_layers));
					//dojo.connect(g, 'downLayer', dojo.hitch(this, this._place_layers));
					//dojo.place(g.domNode, this.layersNode, "last");
				}
			}
		}
		this._place_layers();
	},

	remove: function(path) {
		path = path.split("/")[0];
		/* Check if path is valid map-source */	
		if(GeoMOOSE.isDefined(this.layers[path])) {
			/* Delete layers in the map-source */		
			for(var p in this.layers) {
				if(p.indexOf(path+"/") == 0) {
					dojo.destroy(this.layers[p].domNode);
					delete this.layers[p];
				}
			}
			/* Delete the map-source */
			dojo.destroy(this.layers[path].domNode);
			delete this.layers[path];
	
			/* Update the list - do we need to do this?*/
			this.renderTab();
		}
	},

	_place_layers: function() {
		var map_sources = [ ];
		for(var i in this.layers) {
			if(i.indexOf("/") < 0) {
				map_sources.push(i);
			}	
		}	
		map_sources = map_sources.sort( dojo.hitch(this,
			function(a,b) {
				var al = this.layers[a];
				var bl = this.layers[b];
				return (bl.getLayerIndex() - al.getLayerIndex());
			}));

		for(var i in map_sources) {
			dojo.place(this.layers[map_sources[i]].domNode, this.layersNode, "last");
		}
	}

});<commit_msg>Modified VisibleLayers Tab to use new GeoMOOSE.Layer class and GeoMOOSE.Tab._Catalog, refs: geomoose/geomoose#44<commit_after>dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("GeoMOOSE.Tab");
dojo.require("extensions.VisibleLayers.mapsource");
dojo.require("extensions.VisibleLayers.layer");

dojo.provide("extensions.VisibleLayers.tab");
dojo.declare('extensions.VisibleLayers.tab', [GeoMOOSE.Tab, dijit._Widget, dijit._Templated], {
	title: 'Active Layers', /* GeoMOOSE.Tab */

	templateString: dojo.cache("extensions.VisibleLayers", "templates/tab.html"),
	widgetsInTemplate: true,

	layers: null,

	startup: function() {
		this.inherited(arguments);
		this.layers = {};

		if(CONFIGURATION['extensions.VisibleLayers.tab_name'])
			this.set('title', CONFIGURATION['extensions.VisibleLayers.tab_name']);
		
		GeoMOOSE.register('onMapbookLoaded', this, this.setupEvents);
		dojo.connect(Application, 'configureMapSources', dojo.hitch(this, this.renderTab));
	},

	postCreate: function() {
		this.inherited(arguments);
		this.parentId = GeoMOOSE.id();
		dojo.attr(this.layersNode, 'id', this.parentId);
	},

	setupEvents: function() {
		dojo.connect(Application, 'onLayersChange', dojo.hitch(this, this.onLayerChange));
		dojo.connect(Application, 'configureMapSource', dojo.hitch(this, this.onLayerAdd));
		dojo.connect(Map, 'setLayerIndex', dojo.hitch(this, this._place_layers));
	},

	onLayerAdd: function(xml, options) {
		this.renderTab(xml);
	},

	onLayerChange: function(layer_id, vis) {
		if(this.layers[layer_id]) {
			this.layers[layer_id].onLayerChange(vis);
		}
		this.renderTab();
	},

	renderTab: function(xml) {
		var layerList = GeoMOOSE.getVisibleLayers();
		for(var i in layerList) {
			var path = layerList[i];
			if(this.layers[path]) {
				; // update status
			} else {
				if(path.indexOf("/") > -1) { /* This is a layer */
					var group = path.split("/")[0];
					if(GeoMOOSE.isDefined(this.layers[group])) {
						var l = new extensions.VisibleLayers.layer(
										{
											title: path,
											path: path,
											map_source: this.layers[group]
										});
						this.layers[path] = l;
						dojo.place(l.domNode, this.layers[group].layersNode, "last");
					}
				} else if(Application.getMapSource(path).displayInLayerSwitcher) {
					this.layers[group] = new GeoMOOSE.Tab._CatalogLayer(this.parentId,
								Application.getMapSource(path).asLayer(),
								false, '');

					this.layers[group].getLayerIndex = function() {
						var mapSource = Application.getMapSource(this.layer.src);
						var ol_layer = mapSource._ol_layer;
						return(Map.getLayerIndex(ol_layer));
					};

					/*
					var g = new extensions.VisibleLayers.mapsource(
									{
										title: path,
										path: path,
										tab: this
									});
					this.layers[path] = g;
					*/

					// parent_id, layer_xml, multiple, group_name
					/*
					this.layers[group] = new GeoMOOSE.Tab._CatalogLayer(this.parentId, 
								xml,
								false,
								'');
					*/
					//dojo.connect(g, 'upLayer', dojo.hitch(this, this._place_layers));
					//dojo.connect(g, 'downLayer', dojo.hitch(this, this._place_layers));
					//dojo.place(g.domNode, this.layersNode, "last");
				}
			}
		}
		this._place_layers();
	},

	remove: function(path) {
		path = path.split("/")[0];
		/* Check if path is valid map-source */	
		if(GeoMOOSE.isDefined(this.layers[path])) {
			/* Delete layers in the map-source */		
			for(var p in this.layers) {
				if(p.indexOf(path+"/") == 0) {
					dojo.destroy(this.layers[p].domNode);
					delete this.layers[p];
				}
			}
			/* Delete the map-source */
			dojo.destroy(this.layers[path].domNode);
			delete this.layers[path];
	
			/* Update the list - do we need to do this?*/
			this.renderTab();
		}
	},

	_place_layers: function() {
		var map_sources = [ ];
		for(var i in this.layers) {
			if(i.indexOf("/") < 0) {
				map_sources.push(i);
			}	
		}	
		map_sources = map_sources.sort( dojo.hitch(this,
			function(a,b) {
				var al = this.layers[a];
				var bl = this.layers[b];
				return (bl.getLayerIndex() - al.getLayerIndex());
			}));

		for(var i in map_sources) {
			//dojo.place(this.layers[map_sources[i]].domNode, this.layersNode, "last");
			dojo.place(this.layers[map_sources[i]].div, this.layersNode, "last");
		}
	}

});
{'fraction_non_alphanumeric': 0.16562300319488818, 'fraction_numerical': 0.0015335463258785943, 'mean_word_length': 3.381858902575588, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '7035083', 'n_tokens_mistral': 3404, 'n_tokens_neox': 2764, 'n_words': 444}