<commit_before>// @require: OpenLayers/Layer/Markers.js
/**
* @class
*/
OpenLayers.Layer.Text = Class.create();
OpenLayers.Layer.Text.prototype = 
  Object.extend( new OpenLayers.Layer.Markers(), {

    /** store url of text file
    * @type str */
    location:null,
    /**
    * @constructor
    *
    * @param {String} name
    */
    initialize: function(name, location) {
        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
        this.location = location;
        new Ajax.Request(location, 
          { method: 'get', onComplete:this.parseData.bind(this) } );
    },
    parseData: function(ajaxRequest) {
      var text = ajaxRequest.responseText;
      var lines = text.split('\n');
      var columns;
      // length - 1 to allow for trailing new line
      for (var lcv = 0; lcv < (lines.length - 1); lcv++) {
          var currLine = lines[lcv].replace(/^\s*/,'').replace(/\s*$/,'');
      
          if (currLine.charAt(0) != '#') { /* not a comment */
          
              if (!columns) {
                  //First line is columns
                  columns = currLine.split('\t');
              } else {
                  var vals = currLine.split('\t');
                  var location = new OpenLayers.LonLat(0,0);
                  var title = ""; var description = "";
                  var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png',new OpenLayers.Size(10,17));
                  var set = false;
                  for (var valIndex = 0; valIndex < vals.length; valIndex++) {
                      if (vals[valIndex]) {
                          if (columns[valIndex] == 'point') {
                              var coords = vals[valIndex].split(',');
                              location.lat = parseFloat(coords[0]);
                              location.lon = parseFloat(coords[1]);
                              set = true;
                          } else if (columns[valIndex] == 'lat') {
                              location.lat = parseFloat(vals[valIndex]);
                              set = true;
                          } else if (columns[valIndex] == 'lon') {
                              location.lon = parseFloat(vals[valIndex]);
                              set = true;
                          } else if (columns[valIndex] == 'title')
                              title = vals[valIndex];
                          else if (columns[valIndex] == 'image')
                              icon.url = vals[valIndex];
                          else if (columns[valIndex] == 'title')
                              title = vals[valIndex];
                          else if (columns[valIndex] == 'description') {
                              description = vals[valIndex];
                          }
                      }
                  }
                  if (set) {
                    var marker = new OpenLayers.Marker(location, icon);
                    var popup = new OpenLayers.Popup(null, location, null, '<h2>'+title+'</h2><p>'+description+'</p>');
                    marker.events.register('click', this, function(evt) { this.map.addPopup(popup); Event.stop(evt); } ); //this.map.addPopup(popup); });
                    this.addMarker(marker);
                  }
              }
          }
        }
    },
    testFunction: function() {
        alert('tesT');
    }
});
     
    <commit_msg>Working text layer with popups! woohoo! parseText suffered a reindentation, so not as much changed here as it looks like. <commit_after>// @require: OpenLayers/Layer/Markers.js
/**
* @class
*/
OpenLayers.Layer.Text = Class.create();
OpenLayers.Layer.Text.prototype = 
  Object.extend( new OpenLayers.Layer.Markers(), {

    /** store url of text file
    * @type str */
    location:null,
    /**
    * @constructor
    *
    * @param {String} name
    */
    initialize: function(name, location) {
        OpenLayers.Layer.Markers.prototype.initialize.apply(this, [name]);
        this.location = location;
        new Ajax.Request(location, 
          { method: 'get', onComplete:this.parseData.bind(this) } );
    },
    parseData: function(ajaxRequest) {
        var text = ajaxRequest.responseText;
        var lines = text.split('\n');
        var columns;
        // length - 1 to allow for trailing new line
        for (var lcv = 0; lcv < (lines.length - 1); lcv++) {
            var currLine = lines[lcv].replace(/^\s*/,'').replace(/\s*$/,'');
        
            if (currLine.charAt(0) != '#') { /* not a comment */
            
                if (!columns) {
                    //First line is columns
                    columns = currLine.split('\t');
                } else {
                    var vals = currLine.split('\t');
                    var location = new OpenLayers.LonLat(0,0);
                    var title; var url;
                    var icon, iconSize, iconOffset;
                    var set = false;
                    for (var valIndex = 0; valIndex < vals.length; valIndex++) {
                        if (vals[valIndex]) {
                            if (columns[valIndex] == 'point') {
                                var coords = vals[valIndex].split(',');
                                location.lat = parseFloat(coords[0]);
                                location.lon = parseFloat(coords[1]);
                                set = true;
                            } else if (columns[valIndex] == 'lat') {
                                location.lat = parseFloat(vals[valIndex]);
                                set = true;
                            } else if (columns[valIndex] == 'lon') {
                                location.lon = parseFloat(vals[valIndex]);
                                set = true;
                            } else if (columns[valIndex] == 'title')
                                title = vals[valIndex];
                            else if (columns[valIndex] == 'image' ||
                                     columns[valIndex] == 'icon')
                                url = vals[valIndex];
                            else if (columns[valIndex] == 'iconSize') {
                                var size = vals[valIndex].split(',');
                                iconSize = new OpenLayers.Size(parseFloat(size[0]),
                                                           parseFloat(size[1]));
                            } else if (columns[valIndex] == 'iconOffset') {
                                var offset = vals[valIndex].split(',');
                                iconOffset = new OpenLayers.Pixel(parseFloat(offset[0]),
                                                           parseFloat(offset[1]));
                            } else if (columns[valIndex] == 'title') {
                                title = vals[valIndex];
                            } else if (columns[valIndex] == 'description') {
                                description = vals[valIndex];
                            }
                        }
                    }
                    if (set) {
                      var data = {};
                      data['iconURL'] = url;
                      data['iconSize'] = iconSize;
                      data['iconOffset'] = iconOffset;
                      data['popupContentHTML'] = '<h2>'+title+'</h2><p>'+description+'</p>';
                      var feature = new OpenLayers.Feature(this, location, data);
                      var marker = feature.createMarker();
                      marker.events.register('click', feature, this.markerClick);
                      this.addMarker(marker);
                    }
                }
            }
        }
    },
    markerClick: function(evt) {
        for(var i=0; i < this.layer.map.popups.length; i++) {
            this.layer.map.removePopup(this.layer.map.popups[i]);
        }
        this.layer.map.addPopup(this.createPopup()); 
        Event.stop(evt);
    }
});
     
    
{'fraction_non_alphanumeric': 0.12745958140117808, 'fraction_numerical': 0.003885198646446923, 'mean_word_length': 1.1905023332418336, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 17, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1754891', 'n_tokens_mistral': 2091, 'n_tokens_neox': 2014, 'n_words': 416}