<commit_before>/*
 * L.Control.Legend is a control to show legend of active layers
 */

L.Control.Legend = L.Control.extend({
	options: {
		collapsed: false,
		position: 'bottomright',
		autoZIndex: true
	},

	initialize: function (overlays, options) {
		L.setOptions(this, options);

		this._layers = {};
		this._lastZIndex = 0;
		this._handlingClick = false;

		for (i in overlays) {
			this._addLayer(overlays[i], i, true);
		}
		
		this._container = L.DomUtil.create('div', 'leaflet-control-layers legend');
	},

	onAdd: function () {
		
	    this._update();
	    return this._container;
	},

	addOverlay: function (layer, name) {
		this._addLayer(layer, name, true);
	},
	
	_addLayer: function (layer, name, overlay) {

		var id = L.stamp(layer);
		
		this._layers[id] = {
			layer: layer,
			name: name,
			overlay: overlay,
			//url: L.Util.getParamString(params, url, true),
			visible: false
		};
		
	},

	_update: function () {
		if (!this._container) { return; }
		
		this._container.innerHTML = '';

		//var overlaysPresent, i, obj;

		for (i in this._layers) {
			/*obj = this._layers[i];
			this._addItem(obj);
			overlaysPresent = overlaysPresent || obj.overlay;*/
			if(this._layers[i].visible) this._container.innerHTML += this._layers[i].name + '<br><img src="http://maps.bgeo.es/geoserver/urbanisme/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&STRICT=false&style=urb_sect" alt="legend"><br/>';
		}

		return this;
	},

	_onLayerChange: function (e) {

		var id = L.stamp(e.layer);
		
		// necesitamos un parametro 'visible' de la capa que se pueda activar o desactivar
		if(e.type == 'overlayadd') this._layers[id].visible = true;
		if(e.type == 'overlayremove') this._layers[id].visible = false;
		
		this._update();
	},

	_addItem: function (obj) {
		var image = L.DomUtil.create('img', 'leaflet-buttons-control-img');
		//image.setAttribute('src',obj.legendUrl);
		image.setAttribute('src','http://maps.bgeo.es/geoserver/urbanisme/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&STRICT=false&style=urb_sect');
		
		this._container.appendChild(image);

		return image;
	}
});

L.control.legend = function (overlays, options) {
	return new L.Control.Legend(overlays, options);
};<commit_msg>createWMSLegendUrl<commit_after>/*
 * L.Control.Legend is a control to show legend of active layers
 */

L.Control.Legend = L.Control.extend({
	options: {
		collapsed: false,
		position: 'bottomright',
		autoZIndex: true
	},

	initialize: function (overlays, options) {
		L.setOptions(this, options);

		this._layers = {};

		for (i in overlays) {
			this._addLayer(overlays[i], i, true);
		}
		
		this._container = L.DomUtil.create('div', 'leaflet-control-layers legend');
	},

	onAdd: function () {
		
	    this._update();
	    return this._container;
	},

	addOverlay: function (layer, name) {
		this._addLayer(layer, name, true);
	},
	
	_addLayer: function (layer, name, overlay) {

		var id = L.stamp(layer);
		
		this._layers[id] = {
			layer: layer,
			name: name,
			overlay: overlay,
			legendUrl: this._createWMSLegendUrl(layer),
			visible: false
		};
		
	},

	_update: function () {
		if (!this._container) { return; }
		
		this._container.innerHTML = '';

		//var overlaysPresent, i, obj;

		for (i in this._layers) {
			obj = this._layers[i];
			if(obj.visible) this._addItem(obj);
		}

		return this;
	},

	_onLayerChange: function (e) {

		var id = L.stamp(e.layer);
		
		// necesitamos un parametro 'visible' de la capa que se pueda activar o desactivar
		if(e.type == 'overlayadd') this._layers[id].visible = true;
		if(e.type == 'overlayremove') this._layers[id].visible = false;
		
		this._update();
	},

	_addItem: function (obj) {
		
		//if(!obj.legendUrl) return;
		var div = L.DomUtil.create("div", "legend-text"); 
		//obj.legendUrl = 'http://maps.bgeo.es/geoserver/urbanisme/wms?REQUEST=GetLegendGraphic&VERSION=1.0.0&FORMAT=image/png&WIDTH=20&HEIGHT=20&STRICT=false&style=urb_sect';

		var image = L.DomUtil.create('img', 'leaflet-buttons-control-img');
		image.setAttribute('src', obj.legendUrl);
		div.innerHTML = '<br>' + obj.name;
		
		this._container.appendChild(div);
		this._container.appendChild(image);

		return this._container;
	}, 
	
	_createWMSLegendUrl: function (layer) {
		
		var params = {
		          request: 'GetLegendGraphic',
		          //style: "urb_sect",
		          layer: layer.wmsParams.layers,
		          version: "1.1.1", // Force 1.1.1, don't use 1.3.0
		          format: "image/png",
		          height: 20,
		          width: 20
		        };		
		
		return layer._url + L.Util.getParamString(params);
	}
});

L.control.legend = function (overlays, options) {
	return new L.Control.Legend(overlays, options);
};
{'fraction_non_alphanumeric': 0.16048862679022746, 'fraction_numerical': 0.007371524852569503, 'mean_word_length': 3.4717514124293785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4481312', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1652, 'n_words': 327}