<commit_before>import React, { PropTypes, Component } from 'react';
import classNames from 'classnames';
import withStyles from '../../decorators/withStyles';
import styles from './Map.less';
import TextBox from '../TextBox';
import AntykaGeometry from './AntykaGeometry';
import { canUseDOM } from 'react/lib/ExecutionEnvironment';

@withStyles(styles)
class Map extends Component {

  static propTypes = {
    position: PropTypes.instanceOf(Object).isRequired,
    drawMode: PropTypes.bool.isRequired
  };

  static defaultProps = {
    
  };

  constructor() {
    super();
    this.existingPolygons = this.loadExistingPolygons();
    this.state = {
      //address: '',
      error: false,
      xx: true,
      neighborhood: null,
      map:null
    };
  }

  loadExistingNeighborhoods(map) {
    console.debug('Loading Existing Neighborhoods...');
    //-------test polygon
    // Define the LatLng coordinates for the polygon's path.
    
    /*var triangleCoords = [
    {lat: 25.774, lng: -80.190},
    {lat: 18.466, lng: -66.118},
    {lat: 32.321, lng: -64.757},
    {lat: 25.774, lng: -80.190}
  ];*/

    // Construct the polygon.
    
    //let map = this.state.map;
    this.existingPolygons.setMap(map);
    //---------------------------------
  }

  loadExistingPolygons() {
    let triangleCoords = [
      {lat: 22.572646, lng: 88.36389500000001},
      {lat: 22.582647, lng: 88.373896},
      {lat: 22.592649, lng: 88.363897},
      {lat: 22.582546, lng: 88.383895}
    ];

    let test = new google.maps.Polygon({
      paths: triangleCoords,
      strokeColor: '#008888',
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: '#FF0000',
      fillOpacity: 0.35,
      zIndex: 2
    });

    return test;
  }

  componentDidMount(rootNode) {
    console.log('Map.componentDidMount()| position:', this.props.position);
    let mapOptions = {
          center: {lat: -34.397, lng: 150.644},
          zoom: 15
        };
    let map = new google.maps.Map(React.findDOMNode(this), mapOptions);
    let infoWindow = new google.maps.InfoWindow({map: map});

    this.drawingManager = new google.maps.drawing.DrawingManager({
      drawingControl: false,
      polygonOptions: {
          fillColor: '#FFFF00',
          fillOpacity: 0.2,
          strokeWeight: 1,
          strokeColor:'#DD2200',
          clickable: true,
          editable: true,
          zIndex: 2
        },
      drawingControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER,
        drawingModes: [
          //google.maps.drawing.OverlayType.POLYGON
        ]
      }
    });
    this.drawingManager.setMap(map);


    let _this = this;
    google.maps.event.addListener(this.drawingManager, "overlaycomplete", function(event) {
      //console.log('Overlay complete:', event);
      console.debug('Overlay complete:', event.overlay.getPath().getArray());
      let newShape = event.overlay;
      _this.drawingManager.setDrawingMode(null);
      //console.log('Overlay complete:', event.overlay.getPaths().getAt(0).getArray(), event.overlay.getPaths().getAt(0).getArray());
      if(event.overlay.getPath().getArray().length <= 2) {
        _this.handleMapError('This is not a neighborhood. Remove this and try again...', event.overlay.getPath().getAt(0));
        return;
      }
      

      if(!_this.findSelfIntersectsAndShowError(newShape)) {
        _this.findIntersectsAndShowError(newShape);
      }

      

      _this.setState({neighborhood: newShape});

      console.debug('Overlay complete polygon:', newShape);
      

      google.maps.event.addListener(newShape, 'click', function(event) {
         console.log('overlay click:', event);
      });
      google.maps.event.addListener(newShape.getPath(), 'set_at', function(event) {
          console.debug("overlay edit set_at:", event, newShape.getPath().getArray());
          _this.findSelfIntersectsAndShowError(newShape);
      });

      google.maps.event.addListener(newShape.getPath(), 'insert_at', function(event) {
          console.log("overlay edit insert_at:", event);
          _this.findSelfIntersectsAndShowError(newShape);
      });

      google.maps.event.addListener(newShape.getPath(), 'remove_at', function(event) {
          console.log("overlay edit remove_at:", event);
      });
     // setSelection(newShape);
    //});
    });
    
    this.setState({map: map, infoWindow: infoWindow});
    this.loadExistingNeighborhoods(map);<commit_msg>added polygon validation in polygon change<commit_after>import React, { PropTypes, Component } from 'react';
import classNames from 'classnames';
import withStyles from '../../decorators/withStyles';
import styles from './Map.less';
import TextBox from '../TextBox';
import AntykaGeometry from './AntykaGeometry';
import { canUseDOM } from 'react/lib/ExecutionEnvironment';

@withStyles(styles)
class Map extends Component {

  static propTypes = {
    position: PropTypes.instanceOf(Object).isRequired,
    drawMode: PropTypes.bool.isRequired
  };

  static defaultProps = {
    
  };

  constructor() {
    super();
    this.existingPolygons = this.loadExistingPolygons();
    this.state = {
      //address: '',
      error: false,
      xx: true,
      neighborhood: null,
      map:null
    };
  }

  loadExistingNeighborhoods(map) {
    console.debug('Loading Existing Neighborhoods...');
    //-------test polygon
    // Define the LatLng coordinates for the polygon's path.
    
    /*var triangleCoords = [
    {lat: 25.774, lng: -80.190},
    {lat: 18.466, lng: -66.118},
    {lat: 32.321, lng: -64.757},
    {lat: 25.774, lng: -80.190}
  ];*/

    // Construct the polygon.
    
    //let map = this.state.map;
    this.existingPolygons.setMap(map);
    //---------------------------------
  }

  loadExistingPolygons() {
    let triangleCoords = [
      {lat: 22.572646, lng: 88.36389500000001},
      {lat: 22.582647, lng: 88.373896},
      {lat: 22.592649, lng: 88.363897},
      {lat: 22.582546, lng: 88.383895}
    ];

    let test = new google.maps.Polygon({
      paths: triangleCoords,
      strokeColor: '#008888',
      strokeOpacity: 0.8,
      strokeWeight: 2,
      fillColor: '#FF0000',
      fillOpacity: 0.35,
      zIndex: 2
    });

    return test;
  }

  componentDidMount(rootNode) {
    console.log('Map.componentDidMount()| position:', this.props.position);
    let mapOptions = {
          center: {lat: -34.397, lng: 150.644},
          zoom: 15
        };
    let map = new google.maps.Map(React.findDOMNode(this), mapOptions);
    let infoWindow = new google.maps.InfoWindow({map: map});

    this.drawingManager = new google.maps.drawing.DrawingManager({
      drawingControl: false,
      polygonOptions: {
          fillColor: '#FFFF00',
          fillOpacity: 0.2,
          strokeWeight: 1,
          strokeColor:'#DD2200',
          clickable: true,
          editable: true,
          zIndex: 2
        },
      drawingControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER,
        drawingModes: [
          //google.maps.drawing.OverlayType.POLYGON
        ]
      }
    });
    this.drawingManager.setMap(map);


    let _this = this;
    google.maps.event.addListener(this.drawingManager, "overlaycomplete", function(event) {
      //console.log('Overlay complete:', event);
      console.debug('Overlay complete:', event.overlay.getPath().getArray());
      let newShape = event.overlay;
      _this.drawingManager.setDrawingMode(null);
      //console.log('Overlay complete:', event.overlay.getPaths().getAt(0).getArray(), event.overlay.getPaths().getAt(0).getArray());
      if(event.overlay.getPath().getArray().length <= 2) {
        _this.handleMapError('This is not a neighborhood. Remove this and try again...', event.overlay.getPath().getAt(0));
        return;
      }
      

      if(!_this.findSelfIntersectsAndShowError(newShape)) {
        _this.findIntersectsAndShowError(newShape);
      }

      

      _this.setState({neighborhood: newShape});

      console.debug('Overlay complete polygon:', newShape);
      

      google.maps.event.addListener(newShape, 'click', function(event) {
         console.log('overlay click:', event);
      });
      google.maps.event.addListener(newShape.getPath(), 'set_at', function(event) {
          console.debug("overlay edit set_at:", event, newShape.getPath().getArray());
          if(!_this.findSelfIntersectsAndShowError(newShape)) {
            _this.findIntersectsAndShowError(newShape);
          }
      });

      google.maps.event.addListener(newShape.getPath(), 'insert_at', function(event) {
          console.log("overlay edit insert_at:", event);
          if(!_this.findSelfIntersectsAndShowError(newShape)) {
            _this.findIntersectsAndShowError(newShape);
          }
      });

      google.maps.event.addListener(newShape.getPath(), 'remove_at', function(event) {
          console.log("overlay edit remove_at:", event);
      });
     // setSelection(newShape);
    //});
    });
    
    this.setState({map: map, infoWindow: infoWindow});
    this.loadExistingNeighborhoods(map);
{'fraction_non_alphanumeric': 0.1492799824117841, 'fraction_numerical': 0.03429702099593272, 'mean_word_length': 2.6218152866242037, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5598389', 'n_tokens_mistral': 3050, 'n_tokens_neox': 2811, 'n_words': 526}