<commit_before>var React = require('react');
var RouteHandler = require('react-router').RouteHandler;
var CurrentLocation = require('./CurrentLocation');
var SearchBox = require('./SearchBox');
var RouteWindow = require('./Route');

require('leafletCss');
require('ratchet');
require('./css/main.css');


var RouteButton = React.createClass({
  route : function(){
    this.props.setMapMode("route");
  },
  render : function(){
    return(
      <div className="sideBtn" onClick = {this.route}>
        <div className="route-icon"></div>
      </div>
    );
  }
});

var Main = React.createClass({

  getInitialState: function(){
    return{
      // markerLyaer is being mutated, not the way react recommends
      currentPoint : {
        //hard coded! what will be the best?
        name : "Current location",
        lat: 0,
        lon: 0
      },
      startPoint : {
        name : "Choose start location.",
        lat :  40.7410605,
        lon : -73.9896986
      },
      destMarker : {
        name : "Choose destination.",
        lat :  40.7410605,
        lon : -73.9896986
      },
      poiMarkers:[],
      currentLayer : L.layerGroup(),
      markerLayer : L.layerGroup([L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.')]),
      routeLayer : L.layerGroup(),
      mode : "search"
    }

  },
  setStartPoint: function(mrkr){
    this.setState({startPoint:mrkr},function(){
    });
  },

  setCurrentPoint: function(pos){
    
    var newCurrentLocation = {
      name : "Current location",
      lat: pos.coords.latitude,
      lon: pos.coords.longitude
    }

    this.setState({
      currentPoint : newCurrentLocation,
      startPoint : newCurrentLocation
    },function(){
      var center = L.latLng(pos.coords.latitude,pos.coords.longitude);
      this.state.currentLayer.clearLayers();
      this.state.currentLayer.addLayer(L.circleMarker(center), 3, {
        color: '#00f',
        opacity:1,
        fillColor: '#00f',
        fillOpacity: 0.8,

      });
      this.map.setView(center,14);
    });

  },

  addMarker: function(mrkr){

    this.state.markerLayer.clearLayers();
    var marker = L.marker([mrkr.lat,mrkr.lon]);
    //replace not to mutate state directly
    this.state.markerLayer.addLayer(marker);
    
    this.map.setView(marker.getLatLng(),14);
    this.setState({
      destMarker: mrkr
    });
  },
  addPOIMarkers: function(mrkrs){
    this.state.markerLayer.clearLayers();
    
    var i;
    var minLat = mrkrs[0].lat;
    var minLon = mrkrs[0].lon;
    var maxLat = mrkrs[0].lat;
    var maxLon = mrkrs[0].lat;

    var self = this;

    for(i =0; i<mrkrs.length; i++){
      var marker = new L.marker([mrkrs[i].lat,mrkrs[i].lon]);
      marker.name = mrkrs[i].name;
      marker.bindPopup(mrkrs[i].name);
      marker.on('click', function (e) {
        self.setState({
          destMarker:{
            name : this.name,
            lat : this.getLatLng().lat,
            lon : this.getLatLng().lng
          }
        });
      });

      if(mrkrs[i].lat < minLat) minLat = mrkrs[i].lat;
      else maxLat = mrkrs[i].lat;
      
      if(mrkrs[i].lon < minLon) minLon = mrkrs[i].lon;
      else maxLon = mrkrs[i].lon;
      this.state.markerLayer.addLayer(marker);
    }
    this.map.fitBounds([[minLat,minLon],[maxLat,maxLon]]);
  },
  clearMap : function(){
    this.state.markerLayer.clearLayers();
    this.state.currentLayer.clearLayers();
    this.state.routeLayer.clearLayers();
    this.setState({
      startPoint:{},
      destPoint:{}<commit_msg>correct function to find boundbox for poi markers<commit_after>var React = require('react');
var RouteHandler = require('react-router').RouteHandler;
var CurrentLocation = require('./CurrentLocation');
var SearchBox = require('./SearchBox');
var RouteWindow = require('./Route');

require('leafletCss');
require('ratchet');
require('./css/main.css');


var RouteButton = React.createClass({
  route : function(){
    this.props.setMapMode("route");
  },
  render : function(){
    return(
      <div className="sideBtn" onClick = {this.route}>
        <div className="route-icon"></div>
      </div>
    );
  }
});

var Main = React.createClass({

  getInitialState: function(){
    return{
      // markerLyaer is being mutated, not the way react recommends
      currentPoint : {
        //hard coded! what will be the best?
        name : "Current location",
        lat: 0,
        lon: 0
      },
      startPoint : {
        name : "Choose start location.",
        lat :  40.7410605,
        lon : -73.9896986
      },
      destMarker : {
        name : "Choose destination.",
        lat :  40.7410605,
        lon : -73.9896986
      },
      poiMarkers:[],
      currentLayer : L.layerGroup(),
      markerLayer : L.layerGroup([L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.')]),
      routeLayer : L.layerGroup(),
      mode : "search"
    }

  },
  setStartPoint: function(mrkr){
    this.setState({startPoint:mrkr},function(){
    });
  },

  setCurrentPoint: function(pos){
    
    var newCurrentLocation = {
      name : "Current location",
      lat: pos.coords.latitude,
      lon: pos.coords.longitude
    }

    this.setState({
      currentPoint : newCurrentLocation,
      startPoint : newCurrentLocation
    },function(){
      var center = L.latLng(pos.coords.latitude,pos.coords.longitude);
      this.state.currentLayer.clearLayers();
      this.state.currentLayer.addLayer(L.circleMarker(center), 3, {
        color: '#00f',
        opacity:1,
        fillColor: '#00f',
        fillOpacity: 0.8,

      });
      this.map.setView(center,14);
    });

  },

  addMarker: function(mrkr){

    this.state.markerLayer.clearLayers();
    var marker = L.marker([mrkr.lat,mrkr.lon]);
    //replace not to mutate state directly
    this.state.markerLayer.addLayer(marker);
    
    this.map.setView(marker.getLatLng(),14);
    this.setState({
      destMarker: mrkr
    });
  },
  addPOIMarkers: function(mrkrs){
    this.state.markerLayer.clearLayers();
    
    var i;
    var minLat = mrkrs[0].lat;
    var minLon = mrkrs[0].lon;
    var maxLat = mrkrs[0].lat;
    var maxLon = mrkrs[0].lon;

    var self = this;

    for(i =0; i<mrkrs.length; i++){
      var marker = new L.marker([mrkrs[i].lat,mrkrs[i].lon]);
      marker.name = mrkrs[i].name;
      marker.bindPopup(mrkrs[i].name);
      marker.on('click', function (e) {
        self.setState({
          destMarker:{
            name : this.name,
            lat : this.getLatLng().lat,
            lon : this.getLatLng().lng
          }
        });
      });

      if(mrkrs[i].lat < minLat) minLat = mrkrs[i].lat;
      if(mrkrs[i].lat > maxLat) maxLat = mrkrs[i].lat;
      if(mrkrs[i].lon < minLon) minLon = mrkrs[i].lon;
      if(mrkrs[i].lon > maxLon) maxLon = mrkrs[i].lon;

      this.state.markerLayer.addLayer(marker);
    }
    this.map.fitBounds([[minLat,minLon],[maxLat,maxLon]]);
  },
  clearMap : function(){
    this.state.markerLayer.clearLayers();
    this.state.currentLayer.clearLayers();
    this.state.routeLayer.clearLayers();
    this.setState({
      startPoint:{},
      destPoint:{}
{'fraction_non_alphanumeric': 0.15526905829596413, 'fraction_numerical': 0.017937219730941704, 'mean_word_length': 2.4814634146341463, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, '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': '6501394', 'n_tokens_mistral': 2496, 'n_tokens_neox': 2378, 'n_words': 430}