L.GeoCSV=L.GeoJSON.extend({options:{titles:["lat","lng","popup"],latitudeTitle:"lat",longitudeTitle:"lng",fieldSeparator:",",lineSeparator:"\n",decimalSeparator:".",lineCommentSeparator:"#",firstLineTitles:false,activeWKT:false,WKTTitle:"wkt",debug:false},_propertiesNames:[],_re:{spaces:/\s+/g,notFloats:/[^0-9., -]/g,notWord:/[^\w]/g},_debug:function(msg,data){if(this.options.debug){if(msg)console.log(msg);if(data)console.log(data)}return data},_checkOptions:function(opts){if(this.options.activeWKT&&!opts.WKTTitle&&!this.options.firstLineTitles)this._debug("WARN: WKTTitle not defined",false);if(this.options.activeWKT&&this.options.decimalSeparator!=".")this._debug("WARN: In WKT mode decimalSeparator need to be a dot",false);if(this.options.firstLineTitles&&opts.titles)this._debug("WARN: With firstLineTitles titles array not apply",false);if(this.options.fieldSeparator.length!=1)this._debug("WARN: fieldSeparator need to be a single character",false);if(this.options.lineSeparator.length!=1)this._debug("WARN: lineSeparator need to be a single character",false)},initialize:function(csv,options){this._propertiesNames=[];L.Util.setOptions(this,options);this._checkOptions(options);L.GeoJSON.prototype.initialize.call(this,csv,options)},addData:function(data){if(typeof data==="string"){data=this._csv2array(data);if(this.options.firstLineTitles){this.options.titles=data[0];data.splice(0,1)}for(var i=0;i=0)prop=this._propertiesNames[pos];return prop},getPropertyTitle:function(prop){var pos=this._propertiesNames.indexOf(prop),title="";if(pos>=0)title=this.options.titles[pos];return title},_csv2array:function(str){var arr=[];var quote=false;var comment=false;for(var row=col=c=0;c90||lat<-90)return feature;if(isNaN(lng)||lng>180||lng<-180)return feature;if(groups.length==1){coordinates[i]=[lng,lat]}else if(geotype=="MULTIPOINT"){coordinates[g]=[lng,lat]}else{coordinates[g][i]=[lng,lat]}}}switch(geotype){case"POINT":feature["geometry"]["type"]="Point";feature["geometry"]["coordinates"]=coordinates[0];break;case"LINESTRING":feature["geometry"]["type"]="LineString";feature["geometry"]["coordinates"]=coordinates;break;case"POLYGON":feature["geometry"]["type"]="Polygon";feature["geometry"]["coordinates"]=[coordinates];break;case"MULTIPOINT":feature["geometry"]["type"]="MultiPoint";feature["geometry"]["coordinates"]=coordinates;break;case"MULTILINESTRING":feature["geometry"]["type"]="MultiLineString";feature["geometry"]["coordinates"]=coordinates;break;case"MULTIPOLYGON":feature["geometry"]["type"]="MultiPolygon";feature["geometry"]["coordinates"]=[coordinates];break;default:this._debug("ERR: "+geotype+" not supported",false)}return feature},_featureBlank:function(){return{type:"Feature",geometry:{},properties:{}}},_csv2json:function(csv){var titulos=this.options.titles,json={type:"FeatureCollection",features:[]},incr=this.options.firstLineTitles?2:1;for(var num_linea=0;num_linea-180&&lat<90&&lat>-90){feature["geometry"]["type"]="Point";feature["geometry"]["coordinates"]=[lng,lat]}else{this._debug("ERR: Invalid LatLon pair at line "+(num_linea+incr),false)}}if(feature.geometry&&feature.geometry.type){for(var i=0;i